public ClientRequest cookie(Cookie cookie) { return header(HttpHeaders.COOKIE, cookie); }
public ClientRequestConfigurer header(final String name, final String value) { clientRequest.header(name, value); return this; }
public ClientRequestConfigurer header(final String name, final String value) { clientRequest.header(name, value); return this; }
public ClientRequest cookie(Cookie cookie) { return header(HttpHeaders.COOKIE, cookie); }
public ClientRequest accept(MediaType accepts) { return header(ACCEPT, accepts.toString()); }
public ClientRequest accept(MediaType accepts) { return header(ACCEPT, accepts.toString()); }
@Override public ClientResponse execute(ClientRequest request) throws Exception { for (Map.Entry<String, String> entry : headers.entrySet()) { request.header(entry.getKey(), entry.getValue()); } return super.execute(request); } });
private void setRequestHeaders(Object headers, ClientRequest clientExecutor) { Map<String, Object> headersMap = HelperJsonUtils.readObjectAsMap(headers); for (Object key : headersMap.keySet()) { clientExecutor.header((String) key, headersMap.get(key)); } }
@Override public ClientResponse execute(ClientRequest request) throws Exception { for (Map.Entry<String, String> entry : headers.entrySet()) { request.header(entry.getKey(), entry.getValue()); } return super.execute(request); } });
@Override public ClientResponse execute(ClientExecutionContext ctx) throws Exception { for (Map.Entry<String, String> entry : headers.entrySet()) { ctx.getRequest().header(entry.getKey(), entry.getValue()); } return ctx.proceed(); } }
@Override public ClientResponse execute(ClientExecutionContext ctx) throws Exception { for (Map.Entry<String, String> entry : headers.entrySet()) { ctx.getRequest().header(entry.getKey(), entry.getValue()); } return ctx.proceed(); } }
/** * {@inheritDoc} */ @Override public ClientResponse execute(ClientRequest request) throws Exception { request.header("Authorization", "Basic " + encodeCredentials()); return super.execute(request); } }
protected ClientRequest createRequest(Object[] args) { ClientRequest request = new ClientRequest(uri, executor, providerFactory); request.getAttributes().putAll(attributes); if (accepts != null) request.header(HttpHeaders.ACCEPT, accepts.toString()); this.copyClientInterceptorsTo(request); boolean isClientResponseResult = ClientResponse.class.isAssignableFrom(method.getReturnType()); request.followRedirects(!isClientResponseResult || this.followRedirects); for (int i = 0; i < marshallers.length; i++) { marshallers[i].build(request, args[i]); } return request; }
protected ClientRequest createRequest(Object[] args) { ClientRequest request = new ClientRequest(uri, executor, providerFactory); request.getAttributes().putAll(attributes); if (accepts != null) request.header(HttpHeaders.ACCEPT, accepts.toString()); this.copyClientInterceptorsTo(request); boolean isClientResponseResult = ClientResponse.class.isAssignableFrom(method.getReturnType()); request.followRedirects(!isClientResponseResult || this.followRedirects); for (int i = 0; i < marshallers.length; i++) { marshallers[i].build(request, args[i]); } return request; }
protected void initClientRequest() { if (this.executor == null) { this.clientRequest = new ClientRequest(getUrl()); } else { this.clientRequest = new ClientRequest(getUrl(), this.executor); } for (Cookie cookie : cookies) { clientRequest.cookie(cookie); } for (Map.Entry<String, String> headerEntry : headers.entrySet()) { clientRequest.header(headerEntry.getKey(), headerEntry.getValue()); } }
@Override public ClientResponse execute(ClientExecutionContext ctx) throws Exception { String token = tokenManager.getAccessTokenString(); if (null != token) { ctx.getRequest().header(HttpHeaders.AUTHORIZATION, "Bearer " + token); } return ctx.proceed(); }
@Override public ClientResponse execute(ClientExecutionContext ctx) throws Exception { String token = tokenManager.getAccessTokenString(); if (null != token) { ctx.getRequest().header(HttpHeaders.AUTHORIZATION, "Bearer " + token); } return ctx.proceed(); }
@Test public void testExecute() throws Exception { ClientExecutionContext ctx = mock(ClientExecutionContext.class); ClientRequest request = mock(ClientRequest.class); ClientResponse response = mock(ClientResponse.class); when(ctx.getRequest()).thenReturn(request); when(ctx.proceed()).thenReturn(response); ClientResponse response1 = this.interceptor.execute(ctx); verify(request, times(1)).header(eq(HttpHeaders.AUTHORIZATION), eq("Bearer token1")); Assert.assertEquals(response, response1); } }
@Test public void testExecute() throws Exception { ClientExecutionContext ctx = mock(ClientExecutionContext.class); ClientRequest request = mock(ClientRequest.class); ClientResponse response = mock(ClientResponse.class); when(ctx.getRequest()).thenReturn(request); when(ctx.proceed()).thenReturn(response); ClientResponse response1 = this.interceptor.execute(ctx); verify(request, times(1)).header(eq(HttpHeaders.AUTHORIZATION), eq("Bearer token1")); Assert.assertEquals(response, response1); } }
@Override public ClientResponse execute(final ClientExecutionContext ctx) throws Exception { final ClientRequest request = ctx.getRequest(); // ETags can only be used on GET requests, so if it's anything else proceed normally if (!request.getHttpMethod().equals(HttpMethod.GET)) { return ctx.proceed(); } // Load the etag for the request from the cache final String etag = getETag(request); if (etag != null) { request.header(HttpHeaders.IF_NONE_MATCH, etag); } // Get the response and save the etag value final ClientResponse response = ctx.proceed(); cacheIfPossible(request, response); return response; }