Java Code Examples for org.apache.http.client.methods.HttpUriRequest#containsHeader()
The following examples show how to use
org.apache.http.client.methods.HttpUriRequest#containsHeader() .
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: SecurityClientRequestFactory.java From dolphin-platform with Apache License 2.0 | 6 votes |
@Override protected void postProcessHttpRequest(HttpUriRequest request) { final String token = securityTokenSupplier.get(); if(token != null && !token.isEmpty() && !request.containsHeader(AUTHORIZATION_HEADER)) { LOG.debug("adding auth header"); request.setHeader(AUTHORIZATION_HEADER, BEARER + token); } final String realm = realmSupplier.get(); if(realm != null && !realm.isEmpty() && !request.containsHeader(REALM_NAME_HEADER)) { LOG.debug("adding realm header"); request.setHeader(REALM_NAME_HEADER, realm); } final String appName = appNameSupplier.get(); if(appName != null && !appName.isEmpty() && !request.containsHeader(APPLICATION_NAME_HEADER)) { LOG.debug("adding app name header"); request.setHeader(APPLICATION_NAME_HEADER, appName); } }
Example 2
Source File: AuthHttpClient.java From docker-java-api with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public HttpResponse execute(final HttpUriRequest request) throws IOException { if (!request.containsHeader(this.authentication.headerName())) { request.setHeader( this.authentication.headerName(), this.authentication.encoded() ); } return this.origin.execute(request); }
Example 3
Source File: AbstractGatewayDispatch.java From knox with Apache License 2.0 | 5 votes |
public void copyRequestHeaderFields(HttpUriRequest outboundRequest, HttpServletRequest inboundRequest) { Enumeration<String> headerNames = inboundRequest.getHeaderNames(); while( headerNames.hasMoreElements() ) { String name = headerNames.nextElement(); if ( !outboundRequest.containsHeader( name ) && !getOutboundRequestExcludeHeaders().contains( name ) ) { String value = inboundRequest.getHeader( name ); outboundRequest.addHeader( name, value ); } } }
Example 4
Source File: AsyncHttpClient.java From AndroidWear-OpenWear with MIT License | 4 votes |
/** * Puts a new request in queue as a new thread in pool to be executed * * @param client HttpClient to be used for request, can differ in single * requests * @param contentType MIME body type, for POST and PUT requests, may be null * @param context Context of Android application, to hold the reference of * request * @param httpContext HttpContext in which the request will be executed * @param responseHandler ResponseHandler or its subclass to put the response into * @param uriRequest instance of HttpUriRequest, which means it must be of * HttpDelete, HttpPost, HttpGet, HttpPut, etc. * @return RequestHandle of future request process */ protected RequestHandle sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) { if (uriRequest == null) { throw new IllegalArgumentException("HttpUriRequest must not be null"); } if (responseHandler == null) { throw new IllegalArgumentException("ResponseHandler must not be null"); } if (responseHandler.getUseSynchronousMode() && !responseHandler.getUsePoolThread()) { throw new IllegalArgumentException( "Synchronous ResponseHandler used in AsyncHttpClient. You should create your response handler in a looper thread or use SyncHttpClient instead."); } if (contentType != null) { if (uriRequest instanceof HttpEntityEnclosingRequestBase && ((HttpEntityEnclosingRequestBase) uriRequest).getEntity() != null && uriRequest.containsHeader(HEADER_CONTENT_TYPE)) { } else { uriRequest.setHeader(HEADER_CONTENT_TYPE, contentType); } } responseHandler.setRequestHeaders(uriRequest.getAllHeaders()); responseHandler.setRequestURI(uriRequest.getURI()); AsyncHttpRequest request = newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context); threadPool.submit(request); RequestHandle requestHandle = new RequestHandle(request); if (context != null) { List<RequestHandle> requestList; // Add request to request map synchronized (requestMap) { requestList = requestMap.get(context); if (requestList == null) { requestList = Collections.synchronizedList(new LinkedList<RequestHandle>()); requestMap.put(context, requestList); } } requestList.add(requestHandle); Iterator<RequestHandle> iterator = requestList.iterator(); while (iterator.hasNext()) { if (iterator.next().shouldBeGarbageCollected()) { iterator.remove(); } } } return requestHandle; }