本文整理汇总了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)));
}
}
示例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));
}
示例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;
}