Example usage for org.apache.http.impl.nio.client HttpAsyncClientBuilder setRedirectStrategy

List of usage examples for org.apache.http.impl.nio.client HttpAsyncClientBuilder setRedirectStrategy

Introduction

In this page you can find the example usage for org.apache.http.impl.nio.client HttpAsyncClientBuilder setRedirectStrategy.

Prototype

public final HttpAsyncClientBuilder setRedirectStrategy(final RedirectStrategy redirectStrategy) 

Source Link

Document

Assigns RedirectStrategy instance.

Usage

From source file:org.apache.zeppelin.notebook.repo.zeppelinhub.rest.HttpProxyClient.java

private HttpAsyncClientBuilder setRedirects(HttpAsyncClientBuilder clientBuilder) {
    clientBuilder.setRedirectStrategy(new DefaultRedirectStrategy() {
        /** Redirectable methods. */
        private String[] REDIRECT_METHODS = new String[] { HttpGet.METHOD_NAME, HttpPost.METHOD_NAME,
                HttpPut.METHOD_NAME, HttpDelete.METHOD_NAME, HttpHead.METHOD_NAME };

        @Override//from w  w w  .j  a  v  a2 s  .c  o  m
        protected boolean isRedirectable(String method) {
            for (String m : REDIRECT_METHODS) {
                if (m.equalsIgnoreCase(method)) {
                    return true;
                }
            }
            return false;
        }
    });
    return clientBuilder;
}

From source file:org.rapidoid.http.HttpClient.java

private static CloseableHttpAsyncClient asyncClient(boolean enableCookies, boolean enableRedirects) {
    ConnectionReuseStrategy reuseStrategy = new NoConnectionReuseStrategy();

    HttpAsyncClientBuilder builder = HttpAsyncClients.custom()
            .setThreadFactory(new RapidoidThreadFactory("http-client"));

    if (!enableCookies) {
        builder = builder.disableCookieManagement().disableConnectionState().disableAuthCaching()
                .setConnectionReuseStrategy(reuseStrategy);
    }//ww w  .ja  v  a 2  s. co m

    if (!enableRedirects) {
        builder = builder.setRedirectStrategy(NO_REDIRECTS);
    }

    return builder.build();
}