本文整理汇总了Java中org.apache.http.impl.io.DefaultHttpRequestWriterFactory类的典型用法代码示例。如果您正苦于以下问题:Java DefaultHttpRequestWriterFactory类的具体用法?Java DefaultHttpRequestWriterFactory怎么用?Java DefaultHttpRequestWriterFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultHttpRequestWriterFactory类属于org.apache.http.impl.io包,在下文中一共展示了DefaultHttpRequestWriterFactory类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ManagedHttpClientConnectionFactory
import org.apache.http.impl.io.DefaultHttpRequestWriterFactory; //导入依赖的package包/类
/**
* @since 4.4
*/
public ManagedHttpClientConnectionFactory(
final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
final HttpMessageParserFactory<HttpResponse> responseParserFactory,
final ContentLengthStrategy incomingContentStrategy,
final ContentLengthStrategy outgoingContentStrategy) {
super();
this.requestWriterFactory = requestWriterFactory != null ? requestWriterFactory :
DefaultHttpRequestWriterFactory.INSTANCE;
this.responseParserFactory = responseParserFactory != null ? responseParserFactory :
DefaultHttpResponseParserFactory.INSTANCE;
this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
LaxContentLengthStrategy.INSTANCE;
this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
StrictContentLengthStrategy.INSTANCE;
}
示例2: buildClient
import org.apache.http.impl.io.DefaultHttpRequestWriterFactory; //导入依赖的package包/类
@Override
protected ExecREST buildClient(RESTPool pool) throws IOException {
SSLContext sslContext;
try {
sslContext = SSLContext.getDefault();
} catch (NoSuchAlgorithmException e) {
throw new IOException(e);
}
Registry<ConnectionSocketFactory> socketRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE))
.build();
//TODO buffers size
SocketConfig socketConfig = SocketConfig.custom()
.setSoTimeout(new Long(pool.getSocketTimeout()).intValue())
.setTcpNoDelay(true)
.setSoKeepAlive(true)
.setSoReuseAddress(true)
.build();
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setCharset(StandardCharsets.UTF_8)
.setMalformedInputAction(CodingErrorAction.IGNORE)
.setUnmappableInputAction(CodingErrorAction.IGNORE)
.build();
HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory = new ManagedHttpClientConnectionFactory(
new DefaultHttpRequestWriterFactory(),
new DefaultHttpResponseParserFactory()
);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(new Long(pool.getMaxPoolWait()).intValue())
.setConnectTimeout(new Long(pool.getConnectionTimeout()).intValue())
.setExpectContinueEnabled(pool.expectContinue())
.build();
PoolingHttpClientConnectionManager ccm = new PoolingHttpClientConnectionManager(socketRegistry, connFactory);
ccm.setMaxTotal(pool.getMaxTotal());
ccm.setDefaultMaxPerRoute(pool.getMaxPerRoute());
ccm.setDefaultSocketConfig(socketConfig);
ccm.setDefaultConnectionConfig(connectionConfig);
ccm.setValidateAfterInactivity(pool.getValidationOnInactivity());
HttpClientBuilder builder = HttpClients.custom()
.setConnectionManager(ccm)
.setDefaultRequestConfig(requestConfig)
.disableAutomaticRetries()
.setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE)
.disableCookieManagement()
.disableContentCompression();
addProxy(pool, builder);
handleRedirects(pool, builder);
CloseableHttpClient servClient = builder.build();
IdleConnectionEvictor evictor = new IdleConnectionEvictor(ccm, pool.getEvictorSleep(), TimeUnit.MILLISECONDS, pool.getMaxIdleTime(), TimeUnit.MILLISECONDS);
HTTPCClientMonitor monitor = pool.hasConnectionMetrics() ? new HTTPCSyncClientMonitor(pool.getName(), ccm) : null;
return new HTTPCClient(servClient, evictor, monitor);
}
示例3: ManagedHttpClientConnectionFactory
import org.apache.http.impl.io.DefaultHttpRequestWriterFactory; //导入依赖的package包/类
public ManagedHttpClientConnectionFactory(
final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
super();
this.requestWriterFactory = requestWriterFactory != null ? requestWriterFactory :
DefaultHttpRequestWriterFactory.INSTANCE;
this.responseParserFactory = responseParserFactory != null ? responseParserFactory :
DefaultHttpResponseParserFactory.INSTANCE;
}
示例4: buildAsyncClient
import org.apache.http.impl.io.DefaultHttpRequestWriterFactory; //导入依赖的package包/类
protected ExecCallbackAsyncREST<HttpResponse> buildAsyncClient(RESTPool pool) throws IOException {
SSLContext sslContext;
try {
sslContext = SSLContext.getDefault();
} catch (NoSuchAlgorithmException e) {
throw new IOException(e);
}
Registry<SchemeIOSessionStrategy> socketRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create()
.register("http", NoopIOSessionStrategy.INSTANCE)
.register("https", new SSLIOSessionStrategy(sslContext, NoopHostnameVerifier.INSTANCE))
.build();
IOReactorConfig socketConfig = IOReactorConfig.custom()
.setIoThreadCount(pool.getReactorThreadCount())
.setSoTimeout(new Long(pool.getSocketTimeout()).intValue())
.setTcpNoDelay(true)
.setSoKeepAlive(true)
.setSelectInterval(REACTOR_SELECT_INTERVAL)
.build();
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setCharset(StandardCharsets.UTF_8)
.setMalformedInputAction(CodingErrorAction.IGNORE)
.setUnmappableInputAction(CodingErrorAction.IGNORE)
.build();
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(new Long(pool.getMaxPoolWait()).intValue())
.setConnectTimeout(new Long(pool.getConnectionTimeout()).intValue())
.setExpectContinueEnabled(pool.expectContinue())
.setRedirectsEnabled(false)
.setStaleConnectionCheckEnabled(pool.getValidationOnInactivity() >= 0)
.build();
NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory = new ManagedNHttpClientConnectionFactory(
new org.apache.http.impl.nio.codecs.DefaultHttpRequestWriterFactory(),
new org.apache.http.impl.nio.codecs.DefaultHttpResponseParserFactory(),
HeapByteBufferAllocator.INSTANCE
);
//TODO set validateAfterInactivity when supported
PoolingNHttpClientConnectionManager ccm = new PoolingNHttpClientConnectionManager(
new DefaultConnectingIOReactor(socketConfig),
connFactory,
socketRegistry,
new SystemDefaultDnsResolver()
);
ccm.setMaxTotal(pool.getMaxTotal());
ccm.setDefaultMaxPerRoute(pool.getMaxPerRoute());
ccm.setDefaultConnectionConfig(connectionConfig);
HttpAsyncClientBuilder builder = HttpAsyncClients.custom()
.setConnectionManager(ccm)
.setDefaultRequestConfig(requestConfig)
.setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE)
.disableCookieManagement();
IdleAsyncConnectionEvictor evictor = new IdleAsyncConnectionEvictor(ccm, pool.getEvictorSleep(), TimeUnit.MILLISECONDS, pool.getMaxIdleTime(), TimeUnit.MILLISECONDS);
addProxy(pool, builder);
handleRedirects(pool, builder);
CloseableHttpAsyncClient servClient = builder.build();
servClient.start();
HTTPCClientMonitor monitor = pool.hasConnectionMetrics() ? new HTTPCAsyncClientMonitor(pool.getName(), ccm) : null;
return new HTTPCAsyncClient(servClient, evictor, monitor);
}
示例5: DefaultBHttpClientConnection
import org.apache.http.impl.io.DefaultHttpRequestWriterFactory; //导入依赖的package包/类
/**
* Creates new instance of DefaultBHttpClientConnection.
*
* @param buffersize buffer size. Must be a positive number.
* @param fragmentSizeHint fragment size hint.
* @param chardecoder decoder to be used for decoding HTTP protocol elements.
* If <code>null</code> simple type cast will be used for byte to char conversion.
* @param charencoder encoder to be used for encoding HTTP protocol elements.
* If <code>null</code> simple type cast will be used for char to byte conversion.
* @param constraints Message constraints. If <code>null</code>
* {@link MessageConstraints#DEFAULT} will be used.
* @param incomingContentStrategy incoming content length strategy. If <code>null</code>
* {@link org.apache.http.impl.entity.LaxContentLengthStrategyHC4#INSTANCE} will be used.
* @param outgoingContentStrategy outgoing content length strategy. If <code>null</code>
* {@link org.apache.http.impl.entity.StrictContentLengthStrategyHC4#INSTANCE} will be used.
* @param requestWriterFactory request writer factory. If <code>null</code>
* {@link DefaultHttpRequestWriterFactory#INSTANCE} will be used.
* @param responseParserFactory response parser factory. If <code>null</code>
* {@link DefaultHttpResponseParserFactory#INSTANCE} will be used.
*/
public DefaultBHttpClientConnection(
final int buffersize,
final int fragmentSizeHint,
final CharsetDecoder chardecoder,
final CharsetEncoder charencoder,
final MessageConstraints constraints,
final ContentLengthStrategy incomingContentStrategy,
final ContentLengthStrategy outgoingContentStrategy,
final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
super(buffersize, fragmentSizeHint, chardecoder, charencoder,
constraints, incomingContentStrategy, outgoingContentStrategy);
this.requestWriter = (requestWriterFactory != null ? requestWriterFactory :
DefaultHttpRequestWriterFactory.INSTANCE).create(getSessionOutputBuffer());
this.responseParser = (responseParserFactory != null ? responseParserFactory :
DefaultHttpResponseParserFactory.INSTANCE).create(getSessionInputBuffer(), constraints);
}