Example usage for org.apache.http.impl.client HttpClientBuilder addInterceptorLast

List of usage examples for org.apache.http.impl.client HttpClientBuilder addInterceptorLast

Introduction

In this page you can find the example usage for org.apache.http.impl.client HttpClientBuilder addInterceptorLast.

Prototype

public final HttpClientBuilder addInterceptorLast(final HttpRequestInterceptor itcp) 

Source Link

Document

Adds this protocol interceptor to the tail of the protocol processing list.

Usage

From source file:com.nextdoor.bender.ipc.es.ElasticSearchTransportFactory.java

private HttpClientBuilder addSigningAuth(HttpClientBuilder cb, UrlSigningAuthConfig auth) {
    return cb.addInterceptorLast(new AWSSigningRequestInterceptor(auth.getAWSSigner()));
}

From source file:ch.cyberduck.core.hubic.HubicSession.java

@Override
public Client connect(final HostKeyCallback key) throws BackgroundException {
    final HttpClientBuilder configuration = builder.build(this);
    configuration.addInterceptorLast(authorizationService);
    configuration.setServiceUnavailableRetryStrategy(retryHandler);
    return new Client(configuration.build());
}

From source file:com.google.reviewit.app.Gerrit.java

private GerritApi connect(ServerConfig serverCfg) {
    return new GerritRestApiFactory().create(
            new GerritAuthData.Basic(serverCfg.url, serverCfg.user, serverCfg.password),
            new HttpClientBuilderExtension() {
                @Override/*  w ww .  j ava  2  s  .  co m*/
                public HttpClientBuilder extend(HttpClientBuilder httpClientBuilder, GerritAuthData authData) {
                    httpClientBuilder.addInterceptorLast(new HttpRequestInterceptor() {
                        public void process(HttpRequest request, HttpContext context)
                                throws HttpException, IOException {
                            Header existingUserAgent = request.getFirstHeader(HttpHeaders.USER_AGENT);
                            String userAgent = String.format("%s/%s", getApplicationName(), getVersion());
                            userAgent += " using " + existingUserAgent.getValue();
                            request.setHeader(HttpHeaders.USER_AGENT, userAgent);
                        }
                    });
                    return super.extend(httpClientBuilder, authData);
                }
            });
}

From source file:com.urswolfer.intellij.plugin.gerrit.rest.UserAgentClientBuilderExtension.java

@Override
public HttpClientBuilder extend(HttpClientBuilder httpClientBuilder, GerritAuthData authData) {
    HttpClientBuilder builder = super.extend(httpClientBuilder, authData);
    httpClientBuilder.addInterceptorLast(new UserAgentHttpRequestInterceptor());
    return builder;
}

From source file:ch.cyberduck.core.googledrive.DriveSession.java

@Override
protected Drive connect(final HostKeyCallback callback) throws BackgroundException {
    final HttpClientBuilder configuration = builder.build(this);
    configuration.addInterceptorLast(authorizationService);
    configuration.setServiceUnavailableRetryStrategy(retryHandler);
    this.transport = new ApacheHttpTransport(configuration.build());
    return new Drive.Builder(transport, json, new HttpRequestInitializer() {
        @Override//w  w  w  . j  a  v  a2 s . c o  m
        public void initialize(HttpRequest request) throws IOException {
            request.setSuppressUserAgentSuffix(true);
            // OAuth Bearer added in interceptor
        }
    }).setApplicationName(useragent.get()).build();
}

From source file:ch.cyberduck.core.b2.B2Session.java

@Override
public B2ApiClient connect(final HostKeyCallback key) throws BackgroundException {
    final HttpClientBuilder configuration = builder.build(this);
    configuration.setServiceUnavailableRetryStrategy(retryHandler);
    configuration.addInterceptorLast(retryHandler);
    return new B2ApiClient(configuration.build());
}

From source file:ch.cyberduck.core.onedrive.OneDriveSession.java

@Override
protected OneDriveAPI connect(final HostKeyCallback key) throws BackgroundException {
    final HttpClientBuilder configuration = builder.build(this);
    configuration.addInterceptorLast(authorizationService);
    configuration.setServiceUnavailableRetryStrategy(retryHandler);
    final RequestExecutor executor = new OneDriveCommonsHttpRequestExecutor(configuration.build()) {
        @Override/*from   w  w  w. ja  v  a 2 s.  com*/
        public void addAuthorizationHeader(final Set<RequestHeader> headers) {
            // Placeholder
            headers.add(new RequestHeader(HttpHeaders.AUTHORIZATION, "Bearer"));
        }
    };
    return new OneDriveAPI() {
        @Override
        public RequestExecutor getExecutor() {
            return executor;
        }

        @Override
        public boolean isBusinessConnection() {
            return false;
        }

        @Override
        public boolean isGraphConnection() {
            return StringUtils.equals("graph.microsoft.com", host.getHostname());
        }

        @Override
        public String getBaseURL() {
            return String.format("%s://%s%s", host.getProtocol().getScheme(), host.getHostname(),
                    host.getProtocol().getContext());
        }

        @Override
        public String getEmailURL() {
            return null;
        }
    };
}

From source file:org.codelibs.solr.lib.server.SolrLibHttpSolrServer.java

public void init() {
    if (clientConnectionManager == null) {
        final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
        connectionManager.setDefaultMaxPerRoute(defaultMaxConnectionsPerHost);
        connectionManager.setMaxTotal(maxTotalConnections);
        idleConnectionMonitorThread = new IdleConnectionMonitorThread(connectionManager,
                connectionMonitorInterval, connectionIdelTimeout);
        idleConnectionMonitorThread.start();
        clientConnectionManager = connectionManager;
    }/*  w ww  .  ja  v  a2  s.c o m*/

    requestConfigBuilder.setRedirectsEnabled(followRedirects);

    final HttpClientBuilder builder = HttpClients.custom();

    if (allowCompression) {
        builder.addInterceptorLast(new UseCompressionRequestInterceptor());
        builder.addInterceptorLast(new UseCompressionResponseInterceptor());
    }

    for (final HttpRequestInterceptor iterceptor : httpRequestInterceptorList) {
        builder.addInterceptorLast(iterceptor);
    }

    init(builder.setConnectionManager(clientConnectionManager)
            .setDefaultRequestConfig(requestConfigBuilder.build()).build());

}

From source file:com.supermap.desktop.icloud.online.AuthenticatorImpl.java

/**
 * ??HttpClientLicenseServece???HttpClient
 *
 * @param token         ?/*from ww  w .j av a2 s  .c  om*/
 * @param clientBuilder HttpClient
 * @param service
 * @return
 * @throws AuthenticationException
 */
public CloseableHttpClient authenticate(UsernamePassword token, HttpClientBuilder clientBuilder, URL service)
        throws AuthenticationException {
    CloseableHttpClient client = this.ssoHttpClientBuilder.build();
    try {
        String jSessionId = login(client, token, service);
        if (null == jSessionId) {
            return null;
        }
        clientBuilder.addInterceptorLast(new SessionIdCookie(jSessionId));
        return clientBuilder.build();
    } catch (IOException e) {
        throw new AuthenticationException(e);
    } finally {
        IOUtils.closeQuietly(client);
    }
}

From source file:ch.cyberduck.core.sds.SDSSession.java

@Override
protected SDSApiClient connect(final HostKeyCallback key) throws BackgroundException {
    final HttpClientBuilder configuration = builder.build(this);
    switch (SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) {
    case oauth:/*from   w w  w .  ja  v a  2s  .  c  o m*/
        configuration
                .setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService));
        configuration.addInterceptorLast(authorizationService);
        configuration.addInterceptorLast(new HttpRequestInterceptor() {
            @Override
            public void process(final HttpRequest request, final HttpContext context)
                    throws HttpException, IOException {
                request.removeHeaders(SDSSession.SDS_AUTH_TOKEN_HEADER);
            }
        });
        break;
    default:
        configuration.setServiceUnavailableRetryStrategy(retryHandler);
        configuration.addInterceptorLast(retryHandler);
        break;
    }
    final CloseableHttpClient apache = configuration.build();
    final SDSApiClient client = new SDSApiClient(apache);
    client.setBasePath(new HostUrlProvider(false, true).get(host.getProtocol().getScheme(), host.getPort(),
            null, host.getHostname(), host.getProtocol().getContext()));
    client.setHttpClient(ClientBuilder.newClient(new ClientConfig().register(new InputStreamProvider())
            .register(MultiPartFeature.class).register(new JSON()).register(JacksonFeature.class)
            .connectorProvider(new HttpComponentsProvider(apache))));
    client.setUserAgent(new PreferencesUseragentProvider().get());
    return client;
}