本文整理汇总了Java中org.apache.http.client.protocol.RequestAcceptEncoding类的典型用法代码示例。如果您正苦于以下问题:Java RequestAcceptEncoding类的具体用法?Java RequestAcceptEncoding怎么用?Java RequestAcceptEncoding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestAcceptEncoding类属于org.apache.http.client.protocol包,在下文中一共展示了RequestAcceptEncoding类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHttpClientBuilder
import org.apache.http.client.protocol.RequestAcceptEncoding; //导入依赖的package包/类
public static HttpClientBuilder getHttpClientBuilder() {
// Common CacheConfig for both the JarCacheStorage and the underlying
// BasicHttpCacheStorage
final CacheConfig cacheConfig = CacheConfig.custom().setMaxCacheEntries(1000).setMaxObjectSize(1024 * 128)
.build();
RequestConfig config = RequestConfig.custom().setConnectTimeout(DEFAULT_TIMEOUT)
.setConnectionRequestTimeout(DEFAULT_TIMEOUT).setSocketTimeout(DEFAULT_TIMEOUT).build();
HttpClientBuilder clientBuilder = CachingHttpClientBuilder.create()
// allow caching
.setCacheConfig(cacheConfig)
// Wrap the local JarCacheStorage around a BasicHttpCacheStorage
.setHttpCacheStorage(new JarCacheStorage(null, cacheConfig, new BasicHttpCacheStorage(cacheConfig)))
// Support compressed data
// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/httpagent.html#d5e1238
.addInterceptorFirst(new RequestAcceptEncoding()).addInterceptorFirst(new ResponseContentEncoding())
// use system defaults for proxy etc.
.useSystemProperties().setDefaultRequestConfig(config);
return clientBuilder;
}
示例2: createHttpProcessor
import org.apache.http.client.protocol.RequestAcceptEncoding; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected BasicHttpProcessor createHttpProcessor() {
BasicHttpProcessor result = super.createHttpProcessor();
result.addRequestInterceptor(new RequestAcceptEncoding());
result.addResponseInterceptor(new ResponseContentEncoding());
return result;
}
示例3: createHttpProcessor
import org.apache.http.client.protocol.RequestAcceptEncoding; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected BasicHttpProcessor createHttpProcessor() {
final BasicHttpProcessor result = super.createHttpProcessor();
result.addRequestInterceptor(new RequestAcceptEncoding());
result.addResponseInterceptor(new ResponseContentEncoding());
return result;
}
示例4: createInstance
import org.apache.http.client.protocol.RequestAcceptEncoding; //导入依赖的package包/类
/**
* Creates an instance of <tt>DefaultHttpClient</tt> with a <tt>ThreadSafeClientConnManager</tt>.
* @return an implementation of the <tt>HttpClient</tt> interface.
*/
public HttpClient createInstance() {
LOGGER.debug("Creating a new instance of DefaultHttpClient with configuration -> {}", toString());
// Create the connection manager which will be default create the necessary schema registry stuff...
final PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
connectionManager.setMaxTotal(maxTotalConnections);
connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute);
// Set the HTTP connection parameters (These are in the HttpCore JavaDocs, NOT the HttpClient ones)...
final HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
HttpConnectionParams.setLinger(params, linger);
HttpConnectionParams.setSocketBufferSize(params, socketBufferSize);
HttpConnectionParams.setSoKeepalive(params, soKeepAlive);
HttpConnectionParams.setSoReuseaddr(params, soReuseAddr);
HttpConnectionParams.setSoTimeout(params, soTimeout);
HttpConnectionParams.setStaleCheckingEnabled(params, staleCheckingEnabled);
HttpConnectionParams.setTcpNoDelay(params, tcpNoDelay);
// Create the HttpClient and configure the compression interceptors if required...
final DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, params);
if (useCompression) {
httpClient.addRequestInterceptor(new RequestAcceptEncoding());
httpClient.addResponseInterceptor(new DeflateContentEncoding());
}
return httpClient;
}
示例5: prepareHttpClient
import org.apache.http.client.protocol.RequestAcceptEncoding; //导入依赖的package包/类
private void prepareHttpClient(AbstractHttpClient client)
{
client.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, true);
client.addRequestInterceptor(new RequestAcceptEncoding());
client.addResponseInterceptor(new ResponseContentEncoding());
client.setRedirectStrategy(new BasicRedirectStrategy());
}
示例6: connect
import org.apache.http.client.protocol.RequestAcceptEncoding; //导入依赖的package包/类
@Override
public void connect() throws IOException {
if (m_client != null) {
return;
}
final HttpParams httpParams = new BasicHttpParams();
if (m_request != null) {
int timeout = m_request.getParameterAsInt("timeout");
if (timeout > 0) {
HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
HttpConnectionParams.setSoTimeout(httpParams, timeout);
}
}
m_client = new DefaultHttpClient(httpParams);
m_client.addRequestInterceptor(new RequestAcceptEncoding());
m_client.addResponseInterceptor(new ResponseContentEncoding());
if (m_request != null) {
int retries = m_request.getParameterAsInt("retries");
if (retries > 0) {
m_client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler() {
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
if (executionCount <= getRetryCount() && (exception instanceof SocketTimeoutException || exception instanceof ConnectTimeoutException)) {
return true;
}
return super.retryRequest(exception, executionCount, context);
}
});
}
String disableSslVerification = m_request.getParameter("disable-ssl-verification");
if (Boolean.parseBoolean(disableSslVerification)) {
final SchemeRegistry registry = m_client.getConnectionManager().getSchemeRegistry();
final Scheme https = registry.getScheme("https");
try {
SSLSocketFactory factory = new SSLSocketFactory(SSLContext.getInstance(EmptyKeyRelaxedTrustSSLContext.ALGORITHM), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
final Scheme lenient = new Scheme(https.getName(), https.getDefaultPort(), factory);
registry.register(lenient);
} catch (NoSuchAlgorithmException e) {
log().warn(e.getMessage());
}
}
}
}
示例7: DecompressingHttpClient
import org.apache.http.client.protocol.RequestAcceptEncoding; //导入依赖的package包/类
/**
* Constructs a decorator to ask for and handle compressed
* entities on the fly.
* @param backend the {@link HttpClient} to use for actually
* issuing requests
*/
public DecompressingHttpClient(HttpClient backend) {
this(backend, new RequestAcceptEncoding(), new ResponseContentEncoding());
}
示例8: DecompressingHttpClient
import org.apache.http.client.protocol.RequestAcceptEncoding; //导入依赖的package包/类
/**
* Constructs a decorator to ask for and handle compressed
* entities on the fly.
* @param backend the {@link HttpClient} to use for actually
* issuing requests
*/
public DecompressingHttpClient(final HttpClient backend) {
this(backend, new RequestAcceptEncoding(), new ResponseContentEncoding());
}