Search in sources :

Example 1 with RedirectStrategy

use of org.apache.http.client.RedirectStrategy in project dropwizard by dropwizard.

the class HttpClientBuilderTest method usesACustomRedirectStrategy.

@Test
public void usesACustomRedirectStrategy() throws Exception {
    RedirectStrategy neverFollowRedirectStrategy = new RedirectStrategy() {

        @Override
        public boolean isRedirected(HttpRequest httpRequest, HttpResponse httpResponse, HttpContext httpContext) throws ProtocolException {
            return false;
        }

        @Override
        public HttpUriRequest getRedirect(HttpRequest httpRequest, HttpResponse httpResponse, HttpContext httpContext) throws ProtocolException {
            return null;
        }
    };
    ConfiguredCloseableHttpClient client = builder.using(neverFollowRedirectStrategy).createClient(apacheBuilder, connectionManager, "test");
    assertThat(client).isNotNull();
    assertThat(spyHttpClientBuilderField("redirectStrategy", apacheBuilder)).isSameAs(neverFollowRedirectStrategy);
}
Also used : HttpRequest(org.apache.http.HttpRequest) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) RedirectStrategy(org.apache.http.client.RedirectStrategy) Test(org.junit.Test)

Aggregations

HttpRequest (org.apache.http.HttpRequest)1 HttpResponse (org.apache.http.HttpResponse)1 RedirectStrategy (org.apache.http.client.RedirectStrategy)1 BasicHttpContext (org.apache.http.protocol.BasicHttpContext)1 HttpContext (org.apache.http.protocol.HttpContext)1 Test (org.junit.Test)1