List of usage examples for org.springframework.http HttpHeaders putAll
@Override public void putAll(Map<? extends String, ? extends List<String>> map)
From source file:org.cloudfoundry.example.Controller.java
private static RequestEntity<?> getOutgoingRequest(RequestEntity<?> incoming) { HttpHeaders headers = new HttpHeaders(); headers.putAll(incoming.getHeaders()); URI uri = headers.remove(FORWARDED_URL).stream().findFirst().map(URI::create) .orElseThrow(() -> new IllegalStateException(String.format("No %s header present", FORWARDED_URL))); return new RequestEntity<>(incoming.getBody(), headers, incoming.getMethod(), uri); }
From source file:io.pivotalservices.wiretaprouteservice.CatchAllController.java
private static RequestEntity<?> getOutgoingRequest(RequestEntity<?> incoming) { HttpHeaders headers = new HttpHeaders(); headers.putAll(incoming.getHeaders()); URI uri = headers.remove(FORWARDED_URL).stream().findFirst().map(URI::create) .orElseThrow(() -> new IllegalStateException(String.format("No %s header present", FORWARDED_URL))); return new RequestEntity<>(incoming.getBody(), headers, incoming.getMethod(), uri); }
From source file:org.zalando.riptide.Actions.java
/** * Normalizes the {@code Location} and {@code Content-Location} headers of any given response by resolving them * against the given {@code uri}.//from w w w . ja v a2 s . c o m * * @param uri the base uri to resolve against * @return a function that normalizes responses */ public static ThrowingFunction<ClientHttpResponse, ClientHttpResponse, IOException> normalize(final URI uri) { return response -> { final HttpHeaders headers = new HttpHeaders(); headers.putAll(response.getHeaders()); Optional.ofNullable(headers.getLocation()).map(uri::resolve).ifPresent(headers::setLocation); Optional.ofNullable(headers.getFirst(CONTENT_LOCATION)).map(uri::resolve) .ifPresent(location -> headers.set(CONTENT_LOCATION, location.toASCIIString())); return new ForwardingClientHttpResponse() { @Override protected ClientHttpResponse delegate() { return response; } @Override public HttpHeaders getHeaders() { return headers; } }; }; }
From source file:com.kolich.spring.controllers.KolichControllerClosure.java
public static final ResponseEntity<byte[]> getResponseEntity(final KolichCommonEntity entity, final HttpHeaders headers, final MediaType contentType, final HttpStatus status) { final HttpHeaders merged = new HttpHeaders(); if (headers != null) { merged.putAll(headers); }//from ww w .java 2 s . c o m merged.setContentType(contentType); return getResponseEntity(entity, merged, status); }
From source file:com.codeabovelab.dm.gateway.filestorage.GetResponseExtractor.java
@Override public Object extractData(ClientHttpResponse response) throws IOException { HttpHeaders headers = new HttpHeaders(); headers.putAll(response.getHeaders()); for (Map.Entry<String, List<String>> e : headers.entrySet()) { List<String> values = e.getValue(); for (int i = 0; i < values.size(); i++) { final String key = e.getKey(); if (FORBIDDEN_HEADERS.contains(key)) { continue; }/*from www . j a va2 s .c o m*/ servletResponse.setHeader(key, values.get(i)); } } try (InputStream is = response.getBody(); ServletOutputStream os = servletResponse.getOutputStream()) { IOUtils.copy(is, os); servletResponse.flushBuffer(); } return null; }
From source file:io.pivotal.spring.cloud.service.eureka.SurgicalRoutingRequestTransformer.java
@Override public HttpRequest transformRequest(HttpRequest request, ServiceInstance instance) { Map<String, String> metadata = instance.getMetadata(); if (metadata.containsKey(CF_APP_GUID) && metadata.containsKey(CF_INSTANCE_INDEX)) { final String headerValue = String.format("%s:%s", metadata.get(CF_APP_GUID), metadata.get(CF_INSTANCE_INDEX)); // request.getHeaders might be immutable, so return a wrapper return new HttpRequestWrapper(request) { @Override/*from w w w .ja v a 2 s. c om*/ public HttpHeaders getHeaders() { HttpHeaders headers = new HttpHeaders(); headers.putAll(super.getHeaders()); headers.add(SURGICAL_ROUTING_HEADER, headerValue); return headers; } }; } return request; }
From source file:org.agatom.springatom.web.controller.SVDefaultController.java
protected <T> ResponseEntity<T> response(final HttpHeaders headers, final T body, final HttpStatus status) { final HttpHeaders httpHeaders = new HttpHeaders(); if (null != headers) { httpHeaders.putAll(headers); }/*from ww w .j a v a2 s .c om*/ httpHeaders.put("sa-error", Collections.singletonList(Boolean.TRUE.toString())); return new ResponseEntity<>(body, httpHeaders, status); }
From source file:org.devefx.httpmapper.http.HttpEntity.java
/** * Create a new {@code HttpEntity} with the given body and headers. * @param body the entity body/*w w w. j a v a 2 s.co m*/ * @param headers the entity headers */ public HttpEntity(T body, MultiValueMap<String, String> headers) { this.body = body; HttpHeaders tempHeaders = new HttpHeaders(); if (headers != null) { tempHeaders.putAll(headers); } this.headers = tempHeaders; }
From source file:be.solidx.hot.rest.RestController.java
protected ResponseEntity<byte[]> buildJSONResponse(Object response, HttpHeaders headers, HttpStatus httpStatus) {// ww w .java 2s .c om HttpHeaders jsonHeaders = jsonResponseHeaders(); jsonHeaders.putAll(headers); try { return new ResponseEntity<byte[]>(objectMapper.writeValueAsBytes(response), jsonHeaders, httpStatus); } catch (Exception e) { return new ResponseEntity<byte[]>(e.getMessage().getBytes(), HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:net.paslavsky.springrest.SpringRestClientMethodInterceptor.java
@Override public Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); RestMethodMetadata metadata = annotationPreprocessor.parse(method.getDeclaringClass(), method); Object[] arguments = invocation.getArguments(); URI uri = new UriBuilder(baseUrl, arguments).build(metadata); Object body = getRequestBody(metadata, arguments); HttpHeaders headers = helper.getHttpHeaders(metadata.getRequestHeaderParameters(), arguments); if (authenticationManager != null) { headers.putAll(authenticationManager.getAuthenticationHeaders()); }/*from ww w . j a va 2s .c o m*/ HttpEntity<?> httpEntity = new HttpEntity<Object>(body, headers); ResponseEntity<?> responseEntity = restTemplate.exchange(uri, metadata.getHttpMethod(), httpEntity, metadata.getResponseClass()); if (metadata.getMethodReturnType() == ResponseEntity.class) { return responseEntity; } else { return responseEntity.getBody(); } }