List of usage examples for org.apache.http.client.methods HttpRequestBase setHeader
public void setHeader(String str, String str2)
From source file:eu.prestoprime.p4gui.connection.WorkflowConnection.java
public static String executeWorkflow(P4Service service, P4Workflow workflow, Map<String, String> dParamsString, Map<String, File> dParamsFile) throws WorkflowRequestException { if (dParamsString == null) dParamsString = new HashMap<>(); if (dParamsFile == null) dParamsFile = new HashMap<>(); dParamsString.put("wfID", workflow.toString()); try {//from www. ja va2 s .c o m MultipartEntity part = new MultipartEntity(); for (String key : dParamsString.keySet()) { String value = dParamsString.get(key); part.addPart(key, new StringBody(value)); } for (String key : dParamsFile.keySet()) { File value = dParamsFile.get(key); part.addPart(key, new FileBody(value)); } String path = service.getURL() + "/wf/execute/" + workflow; logger.debug("Calling " + path); P4HttpClient client = new P4HttpClient(service.getUserID()); HttpRequestBase request = new HttpPost(path); request.setHeader("content-data", "multipart/form-data"); ((HttpPost) request).setEntity(part); HttpResponse response = client.executeRequest(request); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); if (entity != null) { BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); String line; if ((line = reader.readLine()) != null) { logger.debug("Requested new job: " + line); return line; } } } else { logger.debug(response.getStatusLine().toString()); throw new WorkflowRequestException("Unable to request execution of workflow " + workflow + "..."); } } catch (IOException e) { e.printStackTrace(); } throw new WorkflowRequestException( "Something wrong in WorkflowConnection requesting a workflow: no wfID returned..."); }
From source file:com.aliyun.android.oss.http.OSSHttpTool.java
/** * httpHeader/*from www.j a v a 2 s .c om*/ */ public static void addHttpRequestHeader(HttpRequestBase request, String key, String value) { if (!Helper.isEmptyString(key) && !Helper.isEmptyString(value)) { request.setHeader(key, value); } }
From source file:com.graphaware.test.util.TestUtils.java
private static void setHeaders(HttpRequestBase method, Map<String, String> headers) { for (Map.Entry<String, String> headerEntry : headers.entrySet()) { method.setHeader(headerEntry.getKey(), headerEntry.getValue()); }/*from w w w . ja v a 2 s.c o m*/ }
From source file:com.daskiworks.ghwatch.backend.RemoteSystemClient.java
protected static void setHeaders(HttpRequestBase httpRequest, Map<String, String> headers) { httpRequest.setHeader("User-Agent", "GH::watch"); if (headers != null) { for (Entry<String, String> he : headers.entrySet()) { Log.d(TAG, "Set request header " + he.getKey() + ":" + he.getValue()); httpRequest.setHeader(he.getKey(), he.getValue()); }/*w w w.j a va2 s.c o m*/ } }
From source file:com.github.segator.scaleway.api.Utils.java
public static HttpRequestBase buildRequest(String type, String requestPath, String accessToken) { HttpRequestBase request = null; switch (type) { case "POST": request = new HttpPost(requestPath); break;/*from w w w.j a v a2 s.co m*/ case "GET": request = new HttpGet(requestPath); break; case "DELETE": request = new HttpDelete(requestPath); break; case "PATCH": request = new HttpPatch(requestPath); break; } request.setHeader(ScalewayConstants.HEADER_AUTH_TOKEN, accessToken); request.setHeader(HttpHeaders.CONTENT_TYPE, ScalewayConstants.JSON_APPLICATION); return request; }
From source file:org.jboss.pnc.auth.keycloakutil.util.HttpUtil.java
private static void addHeaders(HttpRequestBase request, Headers headers) { for (Header header : headers) { request.setHeader(header.getName(), header.getValue()); }/* ww w. j ava 2 s . com*/ }
From source file:org.jboss.pnc.auth.keycloakutil.util.HttpUtil.java
private static void addAuth(HttpRequestBase request, String authorization) { if (authorization != null) { request.setHeader(HttpHeaders.AUTHORIZATION, authorization); }/*from w w w . j a v a2 s .co m*/ }
From source file:org.wso2.cdm.agent.proxy.ServerApiAccess.java
public static HttpRequestBase buildHeaders(HttpRequestBase httpRequestBase, Map<String, String> headers, String httpMethod) {/*w ww. j a va 2 s .c om*/ Iterator<Entry<String, String>> iterator = headers.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, String> header = iterator.next(); httpRequestBase.setHeader(header.getKey(), header.getValue()); } return httpRequestBase; }
From source file:org.openmhealth.shim.OAuth1Utils.java
/** * Signs an HTTP post request for cases where OAuth 1.0 posts are * required instead of GET.//from w w w . j ava 2 s . c om * * @param unsignedUrl - The unsigned URL * @param clientId - The external provider assigned client id * @param clientSecret - The external provider assigned client secret * @param token - The access token * @param tokenSecret - The 'secret' parameter to be used (Note: token secret != client secret) * @param oAuthParameters - Any additional parameters * @return The request to be signed and sent to external data provider. */ public static HttpRequestBase getSignedRequest(HttpMethod method, String unsignedUrl, String clientId, String clientSecret, String token, String tokenSecret, Map<String, String> oAuthParameters) throws ShimException { URL requestUrl = buildSignedUrl(unsignedUrl, clientId, clientSecret, token, tokenSecret, oAuthParameters); String[] signedParams = requestUrl.toString().split("\\?")[1].split("&"); HttpRequestBase postRequest = method == HttpMethod.GET ? new HttpGet(unsignedUrl) : new HttpPost(unsignedUrl); String oauthHeader = ""; for (String signedParam : signedParams) { String[] parts = signedParam.split("="); oauthHeader += parts[0] + "=\"" + parts[1] + "\","; } oauthHeader = "OAuth " + oauthHeader.substring(0, oauthHeader.length() - 1); postRequest.setHeader("Authorization", oauthHeader); CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(clientId, clientSecret); consumer.setSendEmptyTokens(false); if (token != null) { consumer.setTokenWithSecret(token, tokenSecret); } try { consumer.sign(postRequest); return postRequest; } catch (OAuthMessageSignerException | OAuthExpectationFailedException | OAuthCommunicationException e) { e.printStackTrace(); throw new ShimException("Could not sign POST request, cannot continue"); } }
From source file:org.wso2.mdm.agent.proxy.utils.ServerUtilities.java
public static HttpRequestBase buildHeaders(HttpRequestBase httpRequestBase, Map<String, String> headers, HTTP_METHODS httpMethod) {//from ww w. j a v a 2 s. com Iterator<Entry<String, String>> iterator = headers.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, String> header = iterator.next(); httpRequestBase.setHeader(header.getKey(), header.getValue()); } return httpRequestBase; }