/** * Adds the specified request header, NOT overwriting any previous value. * Note that header-name matching is case insensitive. * * @param headerName the header's name * @param headerValue the header's value */ public void addRequestHeader(String headerName, String headerValue) { addRequestHeader(new Header(headerName, headerValue)); }
/** * Generates <tt>Proxy-Connection: Keep-Alive</tt> request header when * communicating via a proxy server. * * @param state the {@link HttpState state} information associated with this method * @param conn the {@link HttpConnection connection} used to execute * this HTTP method * * @throws IOException if an I/O (transport) error occurs. Some transport exceptions * can be recovered from. * @throws HttpException if a protocol exception occurs. Usually protocol exceptions * cannot be recovered from. */ protected void addProxyConnectionHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { LOG.trace("enter HttpMethodBase.addProxyConnectionHeader(" + "HttpState, HttpConnection)"); if (!conn.isTransparent()) { if (getRequestHeader("Proxy-Connection") == null) { addRequestHeader("Proxy-Connection", "Keep-Alive"); } } }
private void addPostHeaders(HttpMethodBase method) { method.addRequestHeader("Accept", "application/json, text/plain, */*"); method.addRequestHeader("Content-Type", "application/json"); method.addRequestHeader("Authorization", "Basic " + conn.getBasicAuthHeader()); }
@Override public void addHeader(String name, String value) { method.addRequestHeader(name, value); }
/** * Adds the specified request header, NOT overwriting any previous value. * Note that header-name matching is case insensitive. * * @param headerName the header's name * @param headerValue the header's value */ @Override public void addRequestHeader(String headerName, String headerValue) { addRequestHeader(new Header(headerName, headerValue)); }
/** * Adds the specified request header, NOT overwriting any previous value. * Note that header-name matching is case insensitive. * * @param headerName the header's name * @param headerValue the header's value */ public void addRequestHeader(String headerName, String headerValue) { addRequestHeader(new Header(headerName, headerValue)); }
/** * Adds the specified request header, NOT overwriting any previous value. * Note that header-name matching is case insensitive. * * @param headerName the header's name * @param headerValue the header's value */ public void addRequestHeader(String headerName, String headerValue) { addRequestHeader(new Header(headerName, headerValue)); }
private void configureRequestForJson(HttpMethodBase request) { request.addRequestHeader("Accept", "application/json"); if ( request instanceof PutMethod ) request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); }
private void addHeader(HttpMethodBase method, Map<String, String> header) { if (header != null) { for (String key : header.keySet()) { Header h = new Header(key, header.get(key)); method.addRequestHeader(h); } } }
/** * Adds the specified request header, NOT overwriting any previous value. * Note that header-name matching is case insensitive. * * @param headerName the header's name * @param headerValue the header's value */ public void addRequestHeader(String headerName, String headerValue) { addRequestHeader(new Header(headerName, headerValue)); }
/** * Adds the specified request header, NOT overwriting any previous value. * Note that header-name matching is case insensitive. * * @param headerName the header's name * @param headerValue the header's value */ public void addRequestHeader(String headerName, String headerValue) { addRequestHeader(new Header(headerName, headerValue)); }
private HttpMethodBase setHeader(HttpMethodBase method) { Map<String, List<String>> value = getNameValuePairs(header, "header"); if (value != null) { for (Map.Entry<String, List<String>> entry : value.entrySet()) { for (String v : entry.getValue()) { method.addRequestHeader(entry.getKey(), v); } } } else if (header != null) { throw new PaxmlRuntimeException("Header should be key-value pairs but got: " + header); } return method; }
private HttpMethodBase setHeader(HttpMethodBase method) { Map<String, List<String>> value = getNameValuePairs(header, "header"); if (value != null) { for (Map.Entry<String, List<String>> entry : value.entrySet()) { for (String v : entry.getValue()) { method.addRequestHeader(entry.getKey(), v); } } } else if (header != null) { throw new PaxmlRuntimeException("Header should be key-value pairs but got: " + header); } return method; }
/** * Add the headers to the method, and the auth token (which must be set * @param method method to update * @param requestHeaders the list of headers * @throws SwiftInternalStateException not yet authenticated */ private void setHeaders(HttpMethodBase method, Header[] requestHeaders) throws SwiftInternalStateException { for (Header header : requestHeaders) { method.addRequestHeader(header); } setAuthToken(method, getToken()); }
private void overrideHeaders(HttpMethodBase httpMethod, String url, String method) { String headers = getRequestHeaders(); String[] header = headers.split(System.getProperty("line.separator")); for (String kvp : header) { int pos = kvp.indexOf(':'); if (pos < 0) { pos = kvp.indexOf('='); } if (pos > 0) { String k = kvp.substring(0, pos).trim(); String v = ""; if (kvp.length() > pos + 1) { v = kvp.substring(pos + 1).trim(); } httpMethod.addRequestHeader(k, v); } } String authorization = OAuthGenerator.getInstance(getConsumerKey(), getConsumerSecret()).getAuthorization(url, method); httpMethod.addRequestHeader("Authorization", authorization); }
private void overrideHeaders(HttpMethodBase httpMethod, String url, String method) { String headers = getRequestHeaders(); String[] header = headers.split(System.getProperty("line.separator")); for (String kvp : header) { int pos = kvp.indexOf(':'); if (pos < 0) { pos = kvp.indexOf('='); } if (pos > 0) { String k = kvp.substring(0, pos).trim(); String v = ""; if (kvp.length() > pos + 1) { v = kvp.substring(pos + 1).trim(); } httpMethod.addRequestHeader(k, v); } } String authorization = OAuthGenerator.getInstance(getConsumerKey(), getConsumerSecret()).getAuthorization(url, method); httpMethod.addRequestHeader("Authorization", authorization); }
/** * Generates <tt>Proxy-Connection: Keep-Alive</tt> request header when * communicating via a proxy server. * * @param state the {@link HttpState state} information associated with this method * @param conn the {@link HttpConnection connection} used to execute * this HTTP method * * @throws IOException if an I/O (transport) error occurs. Some transport exceptions * can be recovered from. * @throws HttpException if a protocol exception occurs. Usually protocol exceptions * cannot be recovered from. */ protected void addProxyConnectionHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { LOG.trace("enter HttpMethodBase.addProxyConnectionHeader(" + "HttpState, HttpConnection)"); if (!conn.isTransparent()) { if (getRequestHeader("Proxy-Connection") == null) { addRequestHeader("Proxy-Connection", "Keep-Alive"); } } }
/** * Generates <tt>Proxy-Connection: Keep-Alive</tt> request header when * communicating via a proxy server. * * @param state the {@link HttpState state} information associated with this method * @param conn the {@link HttpConnection connection} used to execute * this HTTP method * * @throws IOException if an I/O (transport) error occurs. Some transport exceptions * can be recovered from. * @throws HttpException if a protocol exception occurs. Usually protocol exceptions * cannot be recovered from. */ protected void addProxyConnectionHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { LOG.trace("enter HttpMethodBase.addProxyConnectionHeader(" + "HttpState, HttpConnection)"); if (!conn.isTransparent()) { if (getRequestHeader("Proxy-Connection") == null) { addRequestHeader("Proxy-Connection", "Keep-Alive"); } } }
@Override public ClientHttpResponse executeInternal(HttpHeaders headers, byte[] output) throws IOException { for (Map.Entry<String, List<String>> entry : headers.entrySet()) { String headerName = entry.getKey(); for (String headerValue : entry.getValue()) { httpMethod.addRequestHeader(headerName, headerValue); } } if (this.httpMethod instanceof EntityEnclosingMethod) { EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) this.httpMethod; RequestEntity requestEntity = new ByteArrayRequestEntity(output); entityEnclosingMethod.setRequestEntity(requestEntity); } this.httpClient.executeMethod(this.httpMethod); return new CommonsClientHttpResponse(this.httpMethod); }
@Override public void execute() throws IOException { populateHostConfiguration(); // add compression headers if needed if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) { method.addRequestHeader(HTTPConstants.HEADER_ACCEPT_ENCODING, HTTPConstants.COMPRESSION_GZIP); } if (msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS) != null) { HttpMethodParams params = (HttpMethodParams) msgContext .getProperty(HTTPConstants.HTTP_METHOD_PARAMS); method.setParams(params); } String cookiePolicy = (String) msgContext.getProperty(HTTPConstants.COOKIE_POLICY); if (cookiePolicy != null) { method.getParams().setCookiePolicy(cookiePolicy); } HttpState httpState = (HttpState) msgContext.getProperty(HTTPConstants.CACHED_HTTP_STATE); httpClient.executeMethod(config, method, httpState); }