Java Code Examples for com.ning.http.client.AsyncHttpClient.BoundRequestBuilder#addHeader()
The following examples show how to use
com.ning.http.client.AsyncHttpClient.BoundRequestBuilder#addHeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractLeaderAwareResource.java From Singularity with Apache License 2.0 | 6 votes |
private void copyHeadersAndParams( BoundRequestBuilder requestBuilder, HttpServletRequest request ) { Enumeration<String> headerNames = request.getHeaderNames(); if (headerNames != null) { while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); requestBuilder.addHeader(headerName, request.getHeader(headerName)); LOG.trace("Copied header {}:{}", headerName, request.getHeader(headerName)); } } Enumeration<String> parameterNames = request.getParameterNames(); if (parameterNames != null) { while (parameterNames.hasMoreElements()) { String parameterName = parameterNames.nextElement(); requestBuilder.addQueryParam(parameterName, request.getParameter(parameterName)); LOG.trace( "Copied query param {}={}", parameterName, request.getParameter(parameterName) ); } } }
Example 2
Source File: PcHttpUtils.java From parallec with Apache License 2.0 | 5 votes |
/** * Adds the headers. * * @param builder * the builder * @param headerMap * the header map */ public static void addHeaders(BoundRequestBuilder builder, Map<String, String> headerMap) { for (Entry<String, String> entry : headerMap.entrySet()) { String name = entry.getKey(); String value = entry.getValue(); builder.addHeader(name, value); } }
Example 3
Source File: WSAsync.java From restcommander with Apache License 2.0 | 5 votes |
private BoundRequestBuilder prepare(BoundRequestBuilder builder) { if (this.username != null && this.password != null && this.scheme != null) { AuthScheme authScheme; switch (this.scheme) { case DIGEST: authScheme = AuthScheme.DIGEST; break; case NTLM: authScheme = AuthScheme.NTLM; break; case KERBEROS: authScheme = AuthScheme.KERBEROS; break; case SPNEGO: authScheme = AuthScheme.SPNEGO; break; case BASIC: authScheme = AuthScheme.BASIC; break; default: throw new RuntimeException("Scheme " + this.scheme + " not supported by the UrlFetch WS backend."); } builder.setRealm( (new RealmBuilder()) .setScheme(authScheme) .setPrincipal(this.username) .setPassword(this.password) .setUsePreemptiveAuth(true) .build() ); } for (String key: this.headers.keySet()) { builder.addHeader(key, headers.get(key)); } builder.setFollowRedirects(this.followRedirects); PerRequestConfig perRequestConfig = new PerRequestConfig(); perRequestConfig.setRequestTimeoutInMs(this.timeout * 1000); builder.setPerRequestConfig(perRequestConfig); return builder; }
Example 4
Source File: MyHttpUtils.java From restcommander with Apache License 2.0 | 5 votes |
public static void addHeaders(BoundRequestBuilder builder, Map<String, String> headerMap) { for (Entry<String, String> entry : headerMap.entrySet()) { String name = entry.getKey(); String value = entry.getValue(); builder.addHeader(name, value); } }
Example 5
Source File: AgentManager.java From Baragon with Apache License 2.0 | 5 votes |
private AsyncHttpClient.BoundRequestBuilder buildAgentBatchRequest(String url, List<BaragonRequestBatchItem> batch) throws JsonProcessingException { final BoundRequestBuilder builder = asyncHttpClient.preparePost(url); if (baragonAuthKey.isPresent()) { builder.addQueryParam("authkey", baragonAuthKey.get()); } builder.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); builder.setBody(objectMapper.writeValueAsBytes(batch)); return builder; }
Example 6
Source File: WSAsync.java From restcommander with Apache License 2.0 | 4 votes |
/** * If generatedContentType is present AND if Content-type header is not already present, * add generatedContentType as Content-Type to headers in requestBuilder */ private void addGeneratedContentType(BoundRequestBuilder requestBuilder) { if (!headers.containsKey("Content-Type") && generatedContentType!=null) { requestBuilder.addHeader("Content-Type", generatedContentType); } }