本文整理汇总了Java中org.apache.http.impl.DefaultConnectionReuseStrategy类的典型用法代码示例。如果您正苦于以下问题:Java DefaultConnectionReuseStrategy类的具体用法?Java DefaultConnectionReuseStrategy怎么用?Java DefaultConnectionReuseStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultConnectionReuseStrategy类属于org.apache.http.impl包,在下文中一共展示了DefaultConnectionReuseStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ProxyClient
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
public ProxyClient(final HttpParams params) {
super();
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
new RequestContent(),
new RequestTargetHost(),
new RequestClientConnControl(),
new RequestUserAgent(),
new RequestProxyAuthentication()
} );
this.requestExec = new HttpRequestExecutor();
this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
this.authenticator = new HttpAuthenticator();
this.proxyAuthState = new AuthState();
this.authSchemeRegistry = new AuthSchemeRegistry();
this.authSchemeRegistry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.NTLM, new NTLMSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.KERBEROS, new KerberosSchemeFactory());
this.reuseStrategy = new DefaultConnectionReuseStrategy();
this.params = params;
}
示例2: getBuilder
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
@NotNull
static HttpClientBuilder getBuilder() {
final HttpClientBuilder builder = HttpClients.custom().setSSLContext(CertificateManager.getInstance().getSslContext()).
setMaxConnPerRoute(100000).setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);
final HttpConfigurable proxyConfigurable = HttpConfigurable.getInstance();
final List<Proxy> proxies = proxyConfigurable.getOnlyBySettingsSelector().select(URI.create(EduStepicNames.STEPIC_URL));
final InetSocketAddress address = proxies.size() > 0 ? (InetSocketAddress)proxies.get(0).address() : null;
if (address != null) {
builder.setProxy(new HttpHost(address.getHostName(), address.getPort()));
}
final ConfirmingTrustManager trustManager = CertificateManager.getInstance().getTrustManager();
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[]{trustManager}, new SecureRandom());
builder.setSSLContext(sslContext);
}
catch (NoSuchAlgorithmException | KeyManagementException e) {
LOG.error(e.getMessage());
}
return builder;
}
示例3: QSystemHtmlInstance
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
private QSystemHtmlInstance() {
this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).
setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).
setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).
setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).
setParameter(CoreProtocolPNames.ORIGIN_SERVER, "QSystemReportHttpServer/1.1");
// Set up the HTTP protocol processor
final BasicHttpProcessor httpproc = new BasicHttpProcessor();
httpproc.addInterceptor(new ResponseDate());
httpproc.addInterceptor(new ResponseServer());
httpproc.addInterceptor(new ResponseContent());
httpproc.addInterceptor(new ResponseConnControl());
// Set up request handlers
final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpQSystemReportsHandler());
// Set up the HTTP service
this.httpService = new HttpService(
httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory(), reqistry, this.params);
}
示例4: RequestListenerThread
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
public RequestListenerThread(Context context) throws IOException, BindException {
serversocket = new ServerSocket(PORT);
params = new BasicHttpParams();
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
httpProcessor.addInterceptor(new ResponseDate());
httpProcessor.addInterceptor(new ResponseServer());
httpProcessor.addInterceptor(new ResponseContent());
httpProcessor.addInterceptor(new ResponseConnControl());
// Set up the HTTP service
this.httpService = new YaaccHttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), context);
}
示例5: createCloseableHttpAsyncClient
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
private CloseableHttpAsyncClient createCloseableHttpAsyncClient() throws Exception {
HttpAsyncClientBuilder builder = HttpAsyncClientBuilder.create();
builder.useSystemProperties();
builder.setSSLContext(SSLContext.getDefault());
builder.setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);
builder.setMaxConnPerRoute(2);
builder.setMaxConnTotal(2);
builder.setDefaultRequestConfig(RequestConfig
.custom()
.setConnectionRequestTimeout(1000)
.setConnectTimeout(2000)
.setSocketTimeout(2000)
.build()
);
// builder.setHttpProcessor()
CloseableHttpAsyncClient hc = builder.build();
hc.start();
return hc;
}
示例6: ProxyClient
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
/**
* @since 4.3
*/
public ProxyClient(
final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
final ConnectionConfig connectionConfig,
final RequestConfig requestConfig) {
super();
this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
this.httpProcessor = new ImmutableHttpProcessor(
new RequestTargetHost(), new RequestClientConnControl(), new RequestUserAgent());
this.requestExec = new HttpRequestExecutor();
this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
this.authenticator = new HttpAuthenticator();
this.proxyAuthState = new AuthState();
this.authSchemeRegistry = new AuthSchemeRegistry();
this.authSchemeRegistry.register(AuthSchemes.BASIC, new BasicSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.DIGEST, new DigestSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.NTLM, new NTLMSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory());
this.reuseStrategy = new DefaultConnectionReuseStrategy();
}
示例7: RequestListenerThread
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
public RequestListenerThread(int port, final String docroot) throws IOException {
this.serversocket = new ServerSocket(port);
this.params = new SyncBasicHttpParams();
this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[]{
new ResponseDate(),
new ResponseServer(),
new ResponseContent(),
new ResponseConnControl()
});
// Set up request handlers
HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpFileHandler());
// Set up the HTTP service
this.httpService = new HttpService(
httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory(),
reqistry,
this.params);
}
示例8: HttpServerConnectionUpnpStream
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
protected HttpServerConnectionUpnpStream(ProtocolFactory protocolFactory,
HttpServerConnection connection,
final HttpParams params) {
super(protocolFactory);
this.connection = connection;
this.params = params;
// The Date header is recommended in UDA, need to document the requirement in StreamServer interface?
httpProcessor.addInterceptor(new ResponseDate());
// The Server header is only required for Control so callers have to add it to UPnPMessage
// httpProcessor.addInterceptor(new ResponseServer());
httpProcessor.addInterceptor(new ResponseContent());
httpProcessor.addInterceptor(new ResponseConnControl());
httpService =
new UpnpHttpService(
httpProcessor,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory()
);
httpService.setParams(params);
}
示例9: ListenerThread
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
public ListenerThread(InetAddress address, int port, HttpParams params,
HttpRequestHandlerRegistry handlerRegistry) throws IOException {
this.params = params;
this.serverSocket = new ServerSocket(port, 0, address);
BasicHttpProcessor httpproc = new BasicHttpProcessor();
httpproc.addInterceptor(new ResponseDate());
httpproc.addInterceptor(new ResponseServer());
httpproc.addInterceptor(new ResponseContent());
httpproc.addInterceptor(new ResponseConnControl());
this.httpService = new HttpService(httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory());
this.httpService.setParams(params);
this.httpService.setHandlerResolver(handlerRegistry);
}
示例10: initHttpClient
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
private void initHttpClient() {
_params = new SyncBasicHttpParams();
HttpProtocolParams.setVersion(_params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(_params, "UTF-8");
HttpProtocolParams.setUseExpectContinue(_params, false);
HttpProtocolParams.setHttpElementCharset(_params, "UTF-8");
_httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
// Required protocol interceptors
new BasicHttpProcessor(),
new RequestConnControl(),
new RequestContent(),
new RequestDate(),
new RequestTargetHost(),
// Recommended protocol interceptors
new RequestUserAgent(),
new RequestExpectContinue()
});
_httpexecutor = new HttpRequestExecutor();
_httpcontext = new BasicHttpContext(null);
_connection = new DefaultHttpClientConnection();
_connectionStrategy = new DefaultConnectionReuseStrategy();
}
示例11: createConnectionReuseStrategy
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
@Override
protected ConnectionReuseStrategy createConnectionReuseStrategy() {
String s = System.getProperty("http.keepAlive");
if ("true".equalsIgnoreCase(s)) {
return new DefaultConnectionReuseStrategy();
} else {
return new NoConnectionReuseStrategy();
}
}
示例12: FetchingThread
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
/** Creates a new fetching thread.
*
* @param frontier a reference to the {@link Frontier}.
* @param index the index of this thread (only for logging purposes).
*/
public FetchingThread(final Frontier frontier, final int index) throws NoSuchAlgorithmException, IllegalArgumentException, IOException {
setName(this.getClass().getSimpleName() + '-' + index);
setPriority(Thread.MIN_PRIORITY); // Low priority; there will be thousands of this guys around.
this.frontier = frontier;
final BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManagerWithAlternateDNS(frontier.rc.dnsResolver);
connManager.closeIdleConnections(0, TimeUnit.MILLISECONDS);
connManager.setConnectionConfig(ConnectionConfig.custom().setBufferSize(8 * 1024).build()); // TODO: make this configurable
cookieStore = new BasicCookieStore();
BasicHeader[] headers = {
new BasicHeader("From", frontier.rc.userAgentFrom),
new BasicHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.95,text/*;q=0.9,*/*;q=0.8")
};
httpClient = HttpClients.custom()
.setSSLContext(frontier.rc.acceptAllCertificates ? TRUST_ALL_CERTIFICATES_SSL_CONTEXT : TRUST_SELF_SIGNED_SSL_CONTEXT)
.setConnectionManager(connManager)
.setConnectionReuseStrategy(frontier.rc.keepAliveTime == 0 ? NoConnectionReuseStrategy.INSTANCE : DefaultConnectionReuseStrategy.INSTANCE)
.setUserAgent(frontier.rc.userAgent)
.setDefaultCookieStore(cookieStore)
.setDefaultHeaders(ObjectArrayList.wrap(headers))
.build();
fetchData = new FetchData(frontier.rc);
}
示例13: RequestListenerThread
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
public RequestListenerThread(int port, final String docroot) throws IOException {
this.serversocket = new ServerSocket(port);
this.params = new SyncBasicHttpParams();
this.params
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
new ResponseDate(),
new ResponseServer(),
new ResponseContent(),
new ResponseConnControl()
});
// Set up request handlers
HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpFileHandler(docroot));
// Set up the HTTP service
this.httpService = new HttpService(
httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory(),
reqistry,
this.params);
}
示例14: ProxyHandler
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
public ProxyHandler(
final HttpHost target,
final HttpProcessor httpproc,
final HttpRequestExecutor httpexecutor) {
super();
this.target = target;
this.httpproc = httpproc;
this.httpexecutor = httpexecutor;
this.connStrategy = new DefaultConnectionReuseStrategy();
}
示例15: ListenerThread
import org.apache.http.impl.DefaultConnectionReuseStrategy; //导入依赖的package包/类
public ListenerThread(final HttpRequestHandler requestHandler, final int port) {
_executor = Executors.newCachedThreadPool(new NamedThreadFactory("Cluster-Listener"));
try {
_serverSocket = new ServerSocket(port);
} catch (final IOException ioex) {
s_logger.error("error initializing cluster service servlet container", ioex);
return;
}
_params = new BasicHttpParams();
_params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
final BasicHttpProcessor httpproc = new BasicHttpProcessor();
httpproc.addInterceptor(new ResponseDate());
httpproc.addInterceptor(new ResponseServer());
httpproc.addInterceptor(new ResponseContent());
httpproc.addInterceptor(new ResponseConnControl());
// Set up request handlers
final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("/clusterservice", requestHandler);
// Set up the HTTP service
_httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
_httpService.setParams(_params);
_httpService.setHandlerResolver(reqistry);
}