@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { HttpRequestWrapper wrapper = new HttpRequestWrapper(request); if(name != null && value != null) { wrapper.getHeaders().set(name, value); } return execution.execute(wrapper, body); }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { HttpRequestWrapper requestWrapper = new HttpRequestWrapper(request); requestWrapper.getHeaders().setAccept(Collections.singletonList(mediaType)); return execution.execute(requestWrapper, body); }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { HttpRequestWrapper requestWrapper = new HttpRequestWrapper(request); HttpHeaders headers = requestWrapper.getHeaders(); headers.setAccept(singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); return execution.execute(requestWrapper, body); }
@Override public ClientHttpResponse intercept(final HttpRequest request, final byte[] body, final ClientHttpRequestExecution execution) throws IOException { final HttpRequest wrapper = new HttpRequestWrapper(request); wrapper.getHeaders().set(headerName, headerValue); return execution.execute(wrapper, body); }
@Test public void validateRequestWhenUriStartsWithRootUriShouldReplaceUri() throws Exception { ClientHttpRequest request = mock(ClientHttpRequest.class); given(request.getURI()).willReturn(new URI(this.uri + "/hello")); this.manager.validateRequest(request); verify(this.delegate).validateRequest(this.requestCaptor.capture()); HttpRequestWrapper actual = (HttpRequestWrapper) this.requestCaptor.getValue(); assertThat(actual.getRequest()).isSameAs(request); assertThat(actual.getURI()).isEqualTo(new URI("/hello")); }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { HttpRequestWrapper wrapped = new HttpRequestWrapper(request); wrapped.getHeaders().put("Content-Type", asList(MediaTypes.HAL_JSON_VALUE)); wrapped.getHeaders().put("Accept", asList(MediaTypes.HAL_JSON_VALUE)); return execution.execute(wrapped, body); }
private static List<ClientHttpRequestInterceptor> createAcceptBrotliEncodingInterceptor() { return singletonList((ClientHttpRequestInterceptor) new ClientHttpRequestInterceptor() { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { HttpRequest wrapper = new HttpRequestWrapper(request); wrapper.getHeaders().set("Accept-Encoding", BROTLI_HTTP_CONTENT_CODING); return execution.execute(wrapper, body); } }); }
@Override public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { HttpRequestWrapper requestWrapper = new HttpRequestWrapper(httpRequest); requestWrapper.getHeaders().set(headerKey, headerValue); return clientHttpRequestExecution.execute(requestWrapper, bytes); }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { HttpRequestWrapper requestWrapper = new HttpRequestWrapper(request); requestWrapper.getHeaders().add("ctoken", ctoken); requestWrapper.getHeaders().add("DeviceId", "f8280cf34708c7b5a8bd2ed93dcd3c8148d00000"); return execution.execute(requestWrapper, body); }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { HttpRequestWrapper requestWrapper = new HttpRequestWrapper(request); requestWrapper.getHeaders().add("ctoken", ctoken); requestWrapper.getHeaders().add("utoken", utoken); requestWrapper.getHeaders().add("DeviceId", "f8280cf34708c7b5a8bd2ed93dcd3c8148d00000"); return execution.execute(requestWrapper, body); }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] bytes, ClientHttpRequestExecution execution) throws IOException { HttpRequest wrapper = new HttpRequestWrapper(request); wrapper.getHeaders().set(JWT_TOKEN_HEADER_PARAM, "Bearer " + token); return execution.execute(wrapper, bytes); }
/** * Intercept the given request, set headers passed to constructor, and return a response. * The given {@link org.springframework.http.client.ClientHttpRequestExecution} allows the interceptor * to pass on the request and response to the next entity in the chain. * * @param request the request, containing method, URI, and headers * @param body the body of the request * @param execution the request execution * @return the response * @throws IOException in case of I/O errors */ @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { final HttpRequestWrapper requestWrapper = new HttpRequestWrapper(request); for (final Map.Entry<String, String> header : headers.entrySet()) { requestWrapper.getHeaders().set(header.getKey(), header.getValue()); } return execution.execute(requestWrapper, body); }