本文整理汇总了Java中org.apache.http.impl.client.HttpClientBuilder.addInterceptorLast方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientBuilder.addInterceptorLast方法的具体用法?Java HttpClientBuilder.addInterceptorLast怎么用?Java HttpClientBuilder.addInterceptorLast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.impl.client.HttpClientBuilder
的用法示例。
在下文中一共展示了HttpClientBuilder.addInterceptorLast方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
@Override
protected Drive connect(final HostKeyCallback callback, final LoginCallback prompt) {
authorizationService = new OAuth2RequestInterceptor(builder.build(this, prompt).build(), host.getProtocol())
.withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
final HttpClientBuilder configuration = builder.build(this, prompt);
configuration.addInterceptorLast(authorizationService);
configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService));
this.transport = new ApacheHttpTransport(configuration.build());
return new Drive.Builder(transport, json, new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
request.setSuppressUserAgentSuffix(true);
// OAuth Bearer added in interceptor
}
})
.setApplicationName(useragent.get())
.build();
}
示例2: connect
import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
@Override
protected DbxRawClientV2 connect(final HostKeyCallback callback, final LoginCallback prompt) {
authorizationService = new OAuth2RequestInterceptor(builder.build(this, prompt).build(), host.getProtocol())
.withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
final HttpClientBuilder configuration = builder.build(this, prompt);
configuration.addInterceptorLast(authorizationService);
configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService));
final CloseableHttpClient client = configuration.build();
return new DbxRawClientV2(DbxRequestConfig.newBuilder(useragent.get())
.withAutoRetryDisabled()
.withHttpRequestor(new DropboxCommonsHttpRequestExecutor(client)).build(), DbxHost.DEFAULT) {
@Override
protected void addAuthHeaders(final List<HttpRequestor.Header> headers) {
// OAuth Bearer added in interceptor
}
};
}
示例3: connect
import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
@Override
public B2ApiClient connect(final HostKeyCallback key, final LoginCallback prompt) throws BackgroundException {
final HttpClientBuilder configuration = builder.build(this, prompt);
configuration.setServiceUnavailableRetryStrategy(retryHandler = new B2ErrorResponseInterceptor(
this));
configuration.addInterceptorLast(retryHandler);
return new B2ApiClient(configuration.build());
}
示例4: connect
import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
@Override
public RequestEntityRestStorageService connect(final HostKeyCallback key, final LoginCallback prompt) {
authorizationService = new OAuth2RequestInterceptor(builder.build(this, prompt).build(), host.getProtocol())
.withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
final HttpClientBuilder configuration = builder.build(this, prompt);
configuration.addInterceptorLast(authorizationService);
configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService));
return new OAuth2RequestEntityRestStorageService(this, this.configure(), configuration);
}
示例5: connect
import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
@Override
public Client connect(final HostKeyCallback key, final LoginCallback prompt) {
authorizationService = new OAuth2RequestInterceptor(builder.build(this, prompt).build(), host.getProtocol())
.withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
final HttpClientBuilder configuration = builder.build(this, prompt);
configuration.addInterceptorLast(authorizationService);
configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService));
return new Client(configuration.build());
}
示例6: initialzeInternalClient
import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
protected void initialzeInternalClient() {
if (!needsInternalClientInialization) {
// internal client is already initialized
return;
}
// release any resources if this client was already used
close();
// rebuild the client
HttpClientBuilder httpClientBuilder = HttpClients.custom();
// Add this interceptor to get the values of all HTTP headers in the request.
// Some of them are provided by the user while others are generated by Apache HTTP Components.
httpClientBuilder.addInterceptorLast(new HttpRequestInterceptor() {
@Override
public void process( HttpRequest request, HttpContext context ) throws HttpException,
IOException {
Header[] requestHeaders = request.getAllHeaders();
actualRequestHeaders = new ArrayList<HttpHeader>();
for (Header header : requestHeaders) {
addHeaderToList(actualRequestHeaders, header.getName(), header.getValue());
}
if (debugLevel != HttpDebugLevel.NONE) {
logHTTPRequest(requestHeaders, request);
}
}
});
// connect and read timeouts
httpClientBuilder.setDefaultRequestConfig(RequestConfig.custom()
.setConnectTimeout(connectTimeoutSeconds
* 1000)
.setSocketTimeout(readTimeoutSeconds
* 1000)
.build());
// socket buffer size
if (this.socketBufferSize > 0) {
httpClientBuilder.setDefaultSocketConfig(SocketConfig.custom()
.setRcvBufSize(this.socketBufferSize)
.setSndBufSize(this.socketBufferSize)
.build());
}
// SSL
if (isOverSsl) {
setupSSL(httpClientBuilder);
}
// setup authentication
if (!StringUtils.isNullOrEmpty(username)) {
setupAuthentication(httpClientBuilder);
}
// set proxy
if (AtsSystemProperties.SYSTEM_HTTP_PROXY_HOST != null
&& AtsSystemProperties.SYSTEM_HTTP_PROXY_PORT != null) {
HttpHost proxy = new HttpHost(AtsSystemProperties.SYSTEM_HTTP_PROXY_HOST,
Integer.parseInt(AtsSystemProperties.SYSTEM_HTTP_PROXY_PORT));
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
httpClientBuilder.setRoutePlanner(routePlanner);
}
// now build the client after we have already set everything needed on the client builder
httpClient = httpClientBuilder.build();
// do not come here again until not needed
needsInternalClientInialization = false;
}
示例7: connect
import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
@Override
protected OneDriveAPI connect(final HostKeyCallback key, final LoginCallback prompt) {
authorizationService = new OAuth2RequestInterceptor(builder.build(this, prompt).build(), host.getProtocol()) {
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
if(request.containsHeader(HttpHeaders.AUTHORIZATION)) {
super.process(request, context);
}
}
}.withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
final HttpClientBuilder configuration = builder.build(this, prompt);
configuration.addInterceptorLast(authorizationService);
configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService));
final RequestExecutor executor = new OneDriveCommonsHttpRequestExecutor(configuration.build()) {
@Override
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;
}
};
}
示例8: 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;
}