List of usage examples for org.apache.http.client.methods HttpRequestBase addHeader
public void addHeader(String str, String str2)
From source file:com.ibm.streamsx.topology.internal.context.AnalyticsServiceStreamsContext.java
private JSONObject getJsonResponse(CloseableHttpClient httpClient, HttpRequestBase request) throws IOException, ClientProtocolException { request.addHeader("accept", ContentType.APPLICATION_JSON.getMimeType()); CloseableHttpResponse response = httpClient.execute(request); JSONObject jsonResponse;// w w w .j a va2 s. c om try { HttpEntity entity = response.getEntity(); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { final String errorInfo; if (entity != null) errorInfo = " -- " + EntityUtils.toString(entity); else errorInfo = ""; throw new IllegalStateException( "Unexpected HTTP resource from service:" + response.getStatusLine().getStatusCode() + ":" + response.getStatusLine().getReasonPhrase() + errorInfo); } if (entity == null) throw new IllegalStateException("No HTTP resource from service"); jsonResponse = JSONObject.parse(new BufferedInputStream(entity.getContent())); EntityUtils.consume(entity); } finally { response.close(); } return jsonResponse; }
From source file:org.apache.manifoldcf.authorities.authorities.jira.JiraSession.java
private void getRest(String rightside, JiraJSONResponse response) throws IOException, ResponseException { // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local // auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(host, basicAuth);// w ww .j a v a2 s . co m // Add AuthCache to the execution context HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); final HttpRequestBase method = new HttpGet(host.toURI() + path + rightside); method.addHeader("Accept", "application/json"); try { HttpResponse httpResponse = httpClient.execute(method, localContext); int resultCode = httpResponse.getStatusLine().getStatusCode(); if (resultCode != 200) throw new ResponseException( "Unexpected result code " + resultCode + ": " + convertToString(httpResponse)); Object jo = convertToJSON(httpResponse); response.acceptJSONObject(jo); } finally { method.abort(); } }
From source file:com.ibm.sbt.services.endpoints.ConnectionsEndpointAdapter.java
private void updateNonceHeader(HttpRequestBase method, String nonce) { Header header = findHeader(method, X_UPDATE_NONCE); if (header != null) { method.removeHeader(header);/* ww w.j av a 2s.c o m*/ } method.addHeader(X_UPDATE_NONCE, nonce); }
From source file:fi.iki.mtr.jot.Neo4jDao.java
private void sign(HttpRequestBase req) { try {/*ww w .ja v a 2 s .c om*/ String credentials = username + ":" + password; req.addHeader("Authorization", "Basic " + Base64.encodeBase64String(credentials.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new AssertionError(e); } }
From source file:com.puppetlabs.geppetto.forge.client.ForgeHttpClient.java
protected void configureRequest(final HttpRequestBase request) { if (credentials != null) request.addHeader(HttpHeaders.AUTHORIZATION, credentials); else//from w w w .j ava 2s .c o m request.addHeader(HttpHeaders.USER_AGENT, userAgent); }
From source file:org.openrepose.commons.utils.http.ServiceClient.java
private void setHeaders(HttpRequestBase base, Map<String, String> headers) { final Set<Map.Entry<String, String>> entries = headers.entrySet(); for (Map.Entry<String, String> entry : entries) { base.addHeader(entry.getKey(), entry.getValue()); }/*ww w .j av a2 s . c o m*/ }
From source file:com.puppetlabs.puppetdb.javaclient.impl.HttpComponentsConnector.java
protected void configureRequest(final HttpRequestBase request) { request.addHeader(HttpHeaders.ACCEPT, CONTENT_TYPE_JSON); request.addHeader(HttpHeaders.USER_AGENT, USER_AGENT); }
From source file:com.google.code.jerseyclients.httpclientfour.ApacheHttpClientFourHandler.java
private void writeOutBoundHeaders(MultivaluedMap<String, Object> metadata, HttpRequestBase method) { for (Map.Entry<String, List<Object>> e : metadata.entrySet()) { List<Object> vs = e.getValue(); if (vs.size() == 1) { method.addHeader(e.getKey(), headerValueToString(vs.get(0))); } else {//from w w w.j av a2 s . c om StringBuilder b = new StringBuilder(); for (Object v : e.getValue()) { if (b.length() > 0) { b.append(','); } b.append(headerValueToString(v)); } method.addHeader(e.getKey(), b.toString()); } } }
From source file:com.aliyun.oss.common.comm.HttpRequestFactory.java
private void configureRequestHeaders(ServiceClient.Request request, ExecutionContext context, HttpRequestBase httpRequest) { for (Entry<String, String> entry : request.getHeaders().entrySet()) { if (entry.getKey().equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH) || entry.getKey().equalsIgnoreCase(HttpHeaders.HOST)) { continue; }/*from w ww. j av a2 s . co m*/ httpRequest.addHeader(entry.getKey(), entry.getValue()); } if (!request.isUseUrlSignature() && (httpRequest.getHeaders(HttpHeaders.CONTENT_TYPE) == null || httpRequest.getHeaders(HttpHeaders.CONTENT_TYPE).length == 0)) { httpRequest.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded; " + "charset=" + context.getCharset().toLowerCase()); } }
From source file:com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade.java
private void appendAccessTokenToHeader(HttpRequestBase request, OAuthBearerClientRequest oAuthClientRequest) throws OAuthSystemException { Map<String, String> oAuthHeaders = oAuthClientRequest.buildHeaderMessage().getHeaders(); request.removeHeaders(OAuth.HeaderType.AUTHORIZATION); request.addHeader(OAuth.HeaderType.AUTHORIZATION, oAuthHeaders.get(OAuth.HeaderType.AUTHORIZATION)); }