List of usage examples for org.apache.http.client.methods HttpRequestBase setHeader
public void setHeader(String str, String str2)
From source file:no.digipost.api.useragreements.client.ApiService.java
private <T> T executeHttpRequest(final HttpRequestBase request, final ResponseHandler<T> handler) { try {/* w w w.j av a 2s .c om*/ request.setHeader(X_Digipost_UserId, brokerId.serialize()); return httpClient.execute(request, handler); } catch (IOException e) { throw RuntimeIOException.from(e); } }
From source file:com.gistlabs.mechanize.requestor.RequestBuilder.java
private void buildHeaders(final HttpRequestBase request) { for (Header header : this.setHeaders) for (String value : header) request.setHeader(header.getName(), value); for (Header header : this.addHeaders) for (String value : header) request.addHeader(header.getName(), value); }
From source file:au.com.borner.salesforce.client.rest.ConnectionManager.java
private <T extends AbstractJSONObject> T doExecute(HttpRequestBase request, Class<T> responseClass) { HttpResponse response;//from w ww . ja v a 2 s. c om try { request.setHeader(AUTHORIZATION, BEARER + token); response = httpClient.execute(request); } catch (Exception e) { throw new ConnectionException( String.format("Unable to execute request for %s", request.getURI().toString()), e); } String responseString = null; if (response.getEntity() != null) { try { responseString = EntityUtils.toString(response.getEntity()); } catch (IOException e) { throw new ConnectionException("Unable to parse response entity!", e); } } checkResponseForError(response.getStatusLine().getStatusCode(), responseString); Constructor<T> constructor; try { constructor = responseClass.getConstructor(String.class); return constructor.newInstance(responseString); } catch (Exception e) { throw new ConnectionException("Unable to instantiate response class", e); } }
From source file:uk.co.visalia.brightpearl.apiclient.http.httpclient4.HttpClient4Client.java
private HttpRequestBase buildRequest(Request request) { Method method = request.getMethod(); String url = request.getUrl(); String body = request.getBody(); if (request.getParameters() != null) { try {/* w w w .j a v a 2s. c o m*/ URIBuilder builder = new URIBuilder(url); for (Map.Entry<String, String> param : request.getParameters().entrySet()) { builder.setParameter(param.getKey(), param.getValue()); } url = builder.build().toString(); } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid URL: \"" + request.getUrl() + "\""); } } HttpRequestBase clientRequest = createBaseRequest(method, url, body); if (request.getHeaders() != null) { for (Map.Entry<String, String> header : request.getHeaders().entrySet()) { clientRequest.setHeader(header.getKey(), header.getValue()); } } return clientRequest; }
From source file:org.hawk.http.HTTPManager.java
protected void decorateCurrentRevisionRequest(final HttpRequestBase request) { if (lastETag != null) { request.setHeader(HEADER_ETAG, lastETag); request.setHeader(HEADER_NONE_MATCH, "*"); }// w w w . jav a 2 s . c o m }
From source file:com.thoughtworks.go.util.HttpService.java
public CloseableHttpResponse execute(HttpRequestBase httpMethod) throws IOException { GoAgentServerHttpClient client = httpClientFactory.httpClient(); if (httpMethod.getURI().getScheme().equals("http") || !useMutualTLS) { httpMethod.setHeader("X-Agent-GUID", agentRegistry.uuid()); httpMethod.setHeader("Authorization", agentRegistry.token()); }/* w ww. j a v a 2 s .c o m*/ CloseableHttpResponse response = client.execute(httpMethod); LOGGER.info("Got back {} from server", response.getStatusLine().getStatusCode()); return response; }
From source file:mx.openpay.client.core.impl.DefaultHttpServiceClient.java
protected void addAuthentication(final HttpRequestBase request) { if (this.key != null) { String authEncoding = this.getBase64Auth(); request.setHeader("Authorization", "Basic " + authEncoding); }/*from w ww . j a va 2s . co m*/ }
From source file:org.apache.stratos.metadata.client.rest.DefaultRestClient.java
private void setAuthHeader(HttpRequestBase post) { if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { return;/*from w w w. ja v a2 s .c o m*/ } String identity = username + ":" + password; String encoding = new String(Base64.encodeBase64(identity.getBytes())); post.setHeader("Authorization", "Basic " + encoding); }
From source file:com.github.tmyroadctfig.icloud4j.ICloudService.java
/** * Populates the HTTP request headers./*from w w w .j av a 2s. c o m*/ * * @param request the request to populate. */ public void populateRequestHeadersParameters(HttpRequestBase request) { request.setHeader("Origin", endPoint); request.setHeader("Referer", endPoint + "/"); request.setHeader("User-Agent", session.getUserAgent()); }
From source file:org.fcrepo.camel.FcrepoClient.java
/** * Make a GET request//ww w . j a v a 2 s. c om * @param url the URL of the resource to fetch * @param accept the requested MIMEType of the resource to be retrieved * @param prefer the value for a prefer header sent in the request * @return the repository response * @throws FcrepoOperationFailedException when the underlying HTTP request results in an error */ public FcrepoResponse get(final URI url, final String accept, final String prefer) throws FcrepoOperationFailedException { final HttpRequestBase request = HttpMethods.GET.createRequest(url); if (accept != null) { request.setHeader("Accept", accept); } if (prefer != null) { request.setHeader("Prefer", prefer); } LOGGER.debug("Fcrepo GET request headers: {}", request.getAllHeaders()); final HttpResponse response = executeRequest(request); final int status = response.getStatusLine().getStatusCode(); final String contentType = getContentTypeHeader(response); LOGGER.debug("Fcrepo GET request returned status [{}]", status); if ((status >= HttpStatus.SC_OK && status < HttpStatus.SC_BAD_REQUEST) || !this.throwExceptionOnFailure) { URI describedBy = null; final List<URI> links = getLinkHeaders(response, DESCRIBED_BY); if (links.size() == 1) { describedBy = links.get(0); } return new FcrepoResponse(url, status, contentType, describedBy, getEntityContent(response)); } else { throw new FcrepoOperationFailedException(url, status, response.getStatusLine().getReasonPhrase()); } }