List of usage examples for org.apache.http.client.methods HttpRequestBase addHeader
public void addHeader(String str, String str2)
From source file:org.wise.vle.domain.webservice.http.impl.HttpRestTransportImpl.java
private void setHeaders(final AbstractHttpRequest httpRequestData, HttpRequestBase request) { final Map<String, String> requestHeaders = httpRequestData.getRequestHeaders(); if (requestHeaders != null && !requestHeaders.isEmpty()) { Set<String> keys = requestHeaders.keySet(); for (String key : keys) { request.addHeader(key, requestHeaders.get(key)); }//from w w w .j av a 2 s . com } }
From source file:gmusic.api.comm.ApacheConnector.java
private HttpRequestBase adjustAddress(URI address, HttpRequestBase request) throws MalformedURLException, URISyntaxException { if (address.toString().startsWith(HTTPS_PLAY_GOOGLE_COM_MUSIC_SERVICES)) { address = new URI(address.toURL() + String.format(COOKIE_FORMAT, getCookieValue("xt"))); }// w w w. j a v a 2s .co m request.setURI(address); if (authorizationToken != null) { request.addHeader(GOOGLE_LOGIN_AUTH_KEY, String.format(GOOGLE_LOGIN_AUTH_VALUE, authorizationToken)); } // if((address.toString().startsWith("https://android.clients.google.com/music/mplay")) && deviceId != null) // { // request.addHeader("X-Device-ID", deviceId); // } return request; }
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:com.googlesource.gerrit.plugins.hooks.rtc.network.Transport.java
@SuppressWarnings("unchecked") private synchronized <T> T invoke(HttpRequestBase request, Object typeOrClass, String acceptType, String contentType) throws IOException, ClientProtocolException, ResourceNotFoundException { if (contentType != null) { request.addHeader("Content-Type", contentType); }//from ww w . j a va 2s . c o m if (acceptType != null) { request.addHeader("Accept", acceptType); } HttpResponse response = httpclient.execute(request); try { final int code = response.getStatusLine().getStatusCode(); if (code / 100 != 2) { if (code == 404) { log.debug("API call failed: " + response.getStatusLine()); throw new ResourceNotFoundException(request.getURI()); } else { log.debug("API call failed: " + response.getStatusLine()); throw new IOException("API call failed! " + response.getStatusLine()); } } String responseContentTypeString = getResponseContentType(response); String entityString = readEntityAsString(response); if (!assertValidContentType(acceptType, responseContentTypeString)) { log.error("Request to " + request.getURI() + " failed because of an invalid content returned:\n" + entityString); rtcClient.setLoggedIn(false); throw new InvalidContentTypeException("Wrong content type '" + responseContentTypeString + "' in HTTP response (Expected: " + acceptType + ")"); } if (typeOrClass != null && acceptType.endsWith("json") && responseContentTypeString.endsWith("json")) { Transport.etag.set(extractEtag(response)); if (typeOrClass instanceof ParameterizedType) { return gson.fromJson(entityString, (Type) typeOrClass); } else { return gson.fromJson(entityString, (Class<T>) typeOrClass); } } else if (typeOrClass != null && typeOrClass.equals(String.class)) { return (T) entityString; } else { if (log.isDebugEnabled()) log.debug(entityString); return null; } } finally { consumeHttpEntity(response.getEntity()); Transport.etag.set(null); } }
From source file:net.rcarz.jiraclient.RestClient.java
private JSON request(HttpRequestBase req) throws RestException, IOException { req.addHeader("Accept", "application/json"); if (creds != null) creds.authenticate(req);// w w w . j a v a 2 s . co m HttpResponse resp = httpClient.execute(req); HttpEntity ent = resp.getEntity(); StringBuilder result = new StringBuilder(); if (ent != null) { String encoding = null; if (ent.getContentEncoding() != null) { encoding = ent.getContentEncoding().getValue(); } if (encoding == null) { Header contentTypeHeader = resp.getFirstHeader("Content-Type"); HeaderElement[] contentTypeElements = contentTypeHeader.getElements(); for (HeaderElement he : contentTypeElements) { NameValuePair nvp = he.getParameterByName("charset"); if (nvp != null) { encoding = nvp.getValue(); } } } InputStreamReader isr = encoding != null ? new InputStreamReader(ent.getContent(), encoding) : new InputStreamReader(ent.getContent()); BufferedReader br = new BufferedReader(isr); String line = ""; while ((line = br.readLine()) != null) result.append(line); } StatusLine sl = resp.getStatusLine(); if (sl.getStatusCode() >= 300) throw new RestException(sl.getReasonPhrase(), sl.getStatusCode(), result.toString()); return result.length() > 0 ? JSONSerializer.toJSON(result.toString()) : null; }
From source file:it.larusba.neo4j.jdbc.http.driver.CypherExecutor.java
/** * Execute the http client request./*from w ww . j a v a 2 s .c om*/ * * @param request The request to make * @throws SQLException */ protected Neo4jResponse executeHttpRequest(HttpRequestBase request) throws SQLException { Neo4jResponse result = null; // Adding default headers to the request for (Header header : this.getDefaultHeaders()) { request.addHeader(header.getName(), header.getValue()); } // Make the request try (CloseableHttpResponse response = http.execute(request)) { result = new Neo4jResponse(response, this.mapper); if (result.location != null) { // Here we reconstruct the location in case of a proxy, but in this case you should redirect write queries to the master. Integer transactionId = this.getTransactionId(result.location); this.currentTransactionUrl = new StringBuffer().append(this.transactionUrl).append("/") .append(transactionId).toString(); } } catch (Exception e) { throw new SQLException(e); } return result; }
From source file:io.apicurio.hub.api.github.GitHubPullRequestCreator.java
/** * Adds security to the request./* w w w.j av a2 s.co m*/ * @param request */ protected void addSecurityTo(HttpRequestBase request) { String idpToken = this.token; request.addHeader("Authorization", "Bearer " + idpToken); }
From source file:com.ibm.watson.developer_cloud.service.Request.java
/** * Adds the headers./*w w w . j av a 2 s . c o m*/ * * @param method * the method * @param headers * the headers */ private void addHeaders(HttpRequestBase method, List<NameValuePair> headers) { for (NameValuePair header : headers) { method.addHeader(header.getName(), header.getValue()); } }
From source file:org.neo4j.jdbc.http.driver.CypherExecutor.java
/** * Execute the http client request./*from w w w.ja v a 2s . c om*/ * * @param request The request to make */ private Neo4jResponse executeHttpRequest(HttpRequestBase request) throws SQLException { Neo4jResponse result = null; // Adding default headers to the request for (Header header : this.getDefaultHeaders()) { request.addHeader(header.getName(), header.getValue()); } // Make the request try (CloseableHttpResponse response = http.execute(request)) { result = new Neo4jResponse(response, mapper); if (result.hasErrors()) { // The transaction *was* rolled back server-side. Whether a transaction existed or not before, it should // now be considered rolled back on this side as well. this.currentTransactionUrl = this.transactionUrl; } else if (result.location != null) { // Here we reconstruct the location in case of a proxy, but in this case you should redirect write queries to the master. Integer transactionId = this.getTransactionId(result.location); this.currentTransactionUrl = this.transactionUrl + "/" + transactionId; } } catch (Exception e) { throw new SQLException(e); } return result; }