@Test public void testRequestShouldNotFollowRedirects() throws IOException { final AtomicInteger requestsAttempted = new AtomicInteger(0); HttpRequestExecutor requestExecutor = new HttpRequestExecutor() { @Override public HttpResponse execute( HttpRequest request, HttpClientConnection connection, HttpContext context) throws IOException, HttpException { HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 302, null); response.addHeader("location", "https: requestsAttempted.incrementAndGet(); return response; } }; HttpClient client = HttpClients.custom().setRequestExecutor(requestExecutor).build(); ApacheHttpTransport transport = new ApacheHttpTransport(client); ApacheHttpRequest request = transport.buildRequest("GET", "https: LowLevelHttpResponse response = request.execute(); assertEquals(1, requestsAttempted.get()); assertEquals(302, response.getStatusCode()); }
@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();  }