當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientBuilder.addInterceptorFirst方法代碼示例

本文整理匯總了Java中org.apache.http.impl.client.HttpClientBuilder.addInterceptorFirst方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientBuilder.addInterceptorFirst方法的具體用法?Java HttpClientBuilder.addInterceptorFirst怎麽用?Java HttpClientBuilder.addInterceptorFirst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.impl.client.HttpClientBuilder的用法示例。


在下文中一共展示了HttpClientBuilder.addInterceptorFirst方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: configureCredentials

import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
private void configureCredentials(HttpClientBuilder builder, CredentialsProvider credentialsProvider, Collection<Authentication> authentications) {
    if(authentications.size() > 0) {
        useCredentials(credentialsProvider, AuthScope.ANY_HOST, AuthScope.ANY_PORT, authentications);

        // Use preemptive authorisation if no other authorisation has been established
        builder.addInterceptorFirst(new PreemptiveAuth(new BasicScheme(), isPreemptiveEnabled(authentications)));
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:9,代碼來源:HttpClientConfigurer.java

示例2: onBuild

import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
@Override
public void onBuild(HttpClientBuilder builder) {
	ClientRequestInterceptor clientRequestInterceptor = brave.clientRequestInterceptor();
	ClientResponseInterceptor clientResponseInterceptor = brave.clientResponseInterceptor();
	builder.addInterceptorFirst(new BraveHttpRequestInterceptor(clientRequestInterceptor, spanNameProvider));
	builder.addInterceptorFirst(new BraveHttpResponseInterceptor(clientResponseInterceptor));
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:8,代碼來源:HttpClientBraveIntegration.java

示例3: usingHttpComponents

import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
static ClientHttpRequestFactory usingHttpComponents(ClientOptions options,
                                                    SslConfiguration sslConfiguration) throws GeneralSecurityException,
        IOException {

    HttpClientBuilder httpClientBuilder = HttpClients.custom();

    httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(
            DefaultSchemePortResolver.INSTANCE, ProxySelector.getDefault()));

    if (hasSslConfiguration(sslConfiguration)) {

        SSLContext sslContext = getSSLContext(sslConfiguration);
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
                sslContext);
        httpClientBuilder.setSSLSocketFactory(sslSocketFactory);
        httpClientBuilder.setSslcontext(sslContext);
    }

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(options.getConnectionTimeout())
            .setSocketTimeout(options.getReadTimeout())
            .setAuthenticationEnabled(true)
            .build();

    httpClientBuilder.setDefaultRequestConfig(requestConfig);

    // Support redirects
    httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy());

    // Fix weird problem `ProtocolException: Content-Length header already present` from `org.apache.http.protocol.RequestContent`
    httpClientBuilder.addInterceptorFirst(new HttpRequestInterceptor() {
        @Override
        public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
            if (request instanceof HttpEntityEnclosingRequest) {
                request.removeHeaders(HTTP.TRANSFER_ENCODING);
                request.removeHeaders(HTTP.CONTENT_LEN);
            }
        }
    });

    return new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
}
 
開發者ID:JetBrains,項目名稱:teamcity-hashicorp-vault-plugin,代碼行數:43,代碼來源:ClientHttpRequestFactoryFactory.java

示例4: create

import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
@Override
public ConnectionManagerAwareHttpClient create(HttpClientSettings settings) {
    final HttpClientBuilder builder = HttpClients.custom();
    // Note that it is important we register the original connection manager with the
    // IdleConnectionReaper as it's required for the successful deregistration of managers
    // from the reaper. See https://github.com/aws/aws-sdk-java/issues/722.
    final HttpClientConnectionManager cm = cmFactory.create(settings);

    builder.setRequestExecutor(new SdkHttpRequestExecutor())
            .setKeepAliveStrategy(buildKeepAliveStrategy(settings))
            .disableRedirectHandling()
            .disableAutomaticRetries()
            .setConnectionManager(ClientConnectionManagerFactory.wrap(cm));

    // By default http client enables Gzip compression. So we disable it
    // here.
    // Apache HTTP client removes Content-Length, Content-Encoding and
    // Content-MD5 headers when Gzip compression is enabled. Currently
    // this doesn't affect S3 or Glacier which exposes these headers.
    //
    if (!(settings.useGzip())) {
        builder.disableContentCompression();
    }

    HttpResponseInterceptor itcp = new CRC32ChecksumResponseInterceptor();
    if (settings.calculateCRC32FromCompressedData()) {
        builder.addInterceptorFirst(itcp);
    } else {
        builder.addInterceptorLast(itcp);
    }

    addProxyConfig(builder, settings);

    final ConnectionManagerAwareHttpClient httpClient = new SdkHttpClient(builder.build(), cm);

    if (settings.useReaper()) {
        IdleConnectionReaper.registerConnectionManager(cm, settings.getMaxIdleConnectionTime());
    }

    return httpClient;
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:42,代碼來源:ApacheHttpClientFactory.java


注:本文中的org.apache.http.impl.client.HttpClientBuilder.addInterceptorFirst方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。