@Test public void testRequestCanSetHeaders() { final AtomicBoolean interceptorCalled = new AtomicBoolean(false); HttpClient client = HttpClients.custom() .addInterceptorFirst( new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { Header header = request.getFirstHeader("foo"); assertNotNull("Should have found header", header); assertEquals("bar", header.getValue()); interceptorCalled.set(true); throw new IOException("cancelling request"); } }) .build(); ApacheHttpTransport transport = new ApacheHttpTransport(client); ApacheHttpRequest request = transport.buildRequest("GET", "https: request.addHeader("foo", "bar"); try { LowLevelHttpResponse response = request.execute(); fail("should not actually make the request"); } catch (IOException exception) { assertEquals("cancelling request", exception.getMessage()); } assertTrue("Expected to have called our test interceptor", interceptorCalled.get()); }
@Override protected ApacheHttpRequest buildRequest(String method, String url) { HttpRequestBase requestBase; if (method.equals(HttpMethods.DELETE)) { requestBase = new HttpDelete(url); } else if (method.equals(HttpMethods.GET)) { requestBase = new HttpGet(url); } else if (method.equals(HttpMethods.HEAD)) { requestBase = new HttpHead(url); } else if (method.equals(HttpMethods.PATCH)) { requestBase = new HttpPatch(url); } else if (method.equals(HttpMethods.POST)) { requestBase = new HttpPost(url); } else if (method.equals(HttpMethods.PUT)) { requestBase = new HttpPut(url); } else if (method.equals(HttpMethods.TRACE)) { requestBase = new HttpTrace(url); } else if (method.equals(HttpMethods.OPTIONS)) { requestBase = new HttpOptions(url); } else { requestBase = new HttpExtensionMethod(method, url); } return new ApacheHttpRequest(httpClient, requestBase); }
ApacheHttpTransport extends HttpTransport { @Override protected ApacheHttpRequest buildRequest(String method, String url) { HttpRequestBase requestBase; if (method.equals(HttpMethods.DELETE)) { requestBase = new HttpDelete(url); } else if (method.equals(HttpMethods.GET)) { requestBase = new HttpGet(url); } else if (method.equals(HttpMethods.HEAD)) { requestBase = new HttpHead(url); } else if (method.equals(HttpMethods.PATCH)) { requestBase = new HttpPatch(url); } else if (method.equals(HttpMethods.POST)) { requestBase = new HttpPost(url); } else if (method.equals(HttpMethods.PUT)) { requestBase = new HttpPut(url); } else if (method.equals(HttpMethods.TRACE)) { requestBase = new HttpTrace(url); } else if (method.equals(HttpMethods.OPTIONS)) { requestBase = new HttpOptions(url); } else { requestBase = new HttpExtensionMethod(method, url); } return new ApacheHttpRequest(httpClient, requestBase); } }
ApacheHttpTransport extends HttpTransport { @Override protected ApacheHttpRequest buildRequest(String method, String url) { HttpRequestBase requestBase; if (method.equals(HttpMethods.DELETE)) { requestBase = new HttpDelete(url); } else if (method.equals(HttpMethods.GET)) { requestBase = new HttpGet(url); } else if (method.equals(HttpMethods.HEAD)) { requestBase = new HttpHead(url); } else if (method.equals(HttpMethods.PATCH)) { requestBase = new HttpPatch(url); } else if (method.equals(HttpMethods.POST)) { requestBase = new HttpPost(url); } else if (method.equals(HttpMethods.PUT)) { requestBase = new HttpPut(url); } else if (method.equals(HttpMethods.TRACE)) { requestBase = new HttpTrace(url); } else if (method.equals(HttpMethods.OPTIONS)) { requestBase = new HttpOptions(url); } else { requestBase = new HttpExtensionMethod(method, url); } return new ApacheHttpRequest(httpClient, requestBase); } ApacheHttpTransport();  ApacheHttpTransport(HttpClient httpClient); }
ApacheHttpTransport extends HttpTransport { @Override protected ApacheHttpRequest buildRequest(String method, String url) { HttpRequestBase requestBase; if (method.equals(HttpMethods.DELETE)) { requestBase = new HttpDelete(url); } else if (method.equals(HttpMethods.GET)) { requestBase = new HttpGet(url); } else if (method.equals(HttpMethods.HEAD)) { requestBase = new HttpHead(url); } else if (method.equals(HttpMethods.PATCH)) { requestBase = new HttpPatch(url); } else if (method.equals(HttpMethods.POST)) { requestBase = new HttpPost(url); } else if (method.equals(HttpMethods.PUT)) { requestBase = new HttpPut(url); } else if (method.equals(HttpMethods.TRACE)) { requestBase = new HttpTrace(url); } else if (method.equals(HttpMethods.OPTIONS)) { requestBase = new HttpOptions(url); } else { requestBase = new HttpExtensionMethod(method, url); } return new ApacheHttpRequest(httpClient, requestBase); } ApacheHttpTransport();  ApacheHttpTransport(HttpClient httpClient); static HttpClient newDefaultHttpClient(); static HttpClientBuilder newDefaultHttpClientBuilder(); @Override boolean supportsMethod(String method); @Override void shutdown(); HttpClient getHttpClient(); }
ApacheHttpTransport extends HttpTransport { @Override protected ApacheHttpRequest buildRequest(String method, String url) { HttpRequestBase requestBase; if (method.equals(HttpMethods.DELETE)) { requestBase = new HttpDelete(url); } else if (method.equals(HttpMethods.GET)) { requestBase = new HttpGet(url); } else if (method.equals(HttpMethods.HEAD)) { requestBase = new HttpHead(url); } else if (method.equals(HttpMethods.PATCH)) { requestBase = new HttpPatch(url); } else if (method.equals(HttpMethods.POST)) { requestBase = new HttpPost(url); } else if (method.equals(HttpMethods.PUT)) { requestBase = new HttpPut(url); } else if (method.equals(HttpMethods.TRACE)) { requestBase = new HttpTrace(url); } else if (method.equals(HttpMethods.OPTIONS)) { requestBase = new HttpOptions(url); } else { requestBase = new HttpExtensionMethod(method, url); } return new ApacheHttpRequest(httpClient, requestBase); } ApacheHttpTransport();  ApacheHttpTransport(HttpClient httpClient); static HttpClient newDefaultHttpClient(); static HttpClientBuilder newDefaultHttpClientBuilder(); @Override boolean supportsMethod(String method); @Override void shutdown(); HttpClient getHttpClient();  }