List of usage examples for org.springframework.http HttpHeaders containsKey
@Override public boolean containsKey(Object key)
From source file:org.springframework.ide.eclipse.boot.wizard.github.auth.BasicAuthCredentials.java
@Override public RestTemplate apply(RestTemplate rest) { List<ClientHttpRequestInterceptor> interceptors = rest.getInterceptors(); interceptors.add(new ClientHttpRequestInterceptor() { public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { if (matchHost(request.getURI().getHost())) { HttpHeaders headers = request.getHeaders(); if (!headers.containsKey("Authorization")) { String authString = computeAuthString(); headers.add("Authorization", authString); }/* w ww . j a v a2s.c o m*/ } return execution.execute(request, body); } }); return rest; }
From source file:org.springframework.integration.http.support.DefaultHttpHeaderMapper.java
/** * Map from an HttpHeaders instance to integration MessageHeaders. * Depending on which type of adapter is using this mapper, the HttpHeaders might be * from an HTTP request (inbound adapter) or from an HTTP response (outbound adapter). *//*from ww w .ja v a 2s. c o m*/ public Map<String, Object> toHeaders(HttpHeaders source) { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("inboundHeaderNames={0}", CollectionUtils.arrayToList(inboundHeaderNames))); } Map<String, Object> target = new HashMap<String, Object>(); Set<String> headerNames = source.keySet(); for (String name : headerNames) { if (this.shouldMapInboundHeader(name)) { if (!ObjectUtils.containsElement(HTTP_REQUEST_HEADER_NAMES, name) && !ObjectUtils.containsElement(HTTP_RESPONSE_HEADER_NAMES, name)) { String prefixedName = StringUtils.startsWithIgnoreCase(name, this.userDefinedHeaderPrefix) ? name : this.userDefinedHeaderPrefix + name; Object value = source.containsKey(prefixedName) ? this.getHttpHeader(source, prefixedName) : this.getHttpHeader(source, name); if (value != null) { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value)); } this.setMessageHeader(target, name, value); } } else { Object value = this.getHttpHeader(source, name); if (value != null) { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("setting headerName=[{0}], value={1}", name, value)); } this.setMessageHeader(target, name, value); } } } } return target; }