Java 类org.apache.http.impl.io.DefaultHttpRequestWriterFactory 实例源码

项目:purecloud-iot    文件:ManagedHttpClientConnectionFactory.java   
/**
 * @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;
}
项目:remote-files-sync    文件:ManagedHttpClientConnectionFactory.java   
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;
}
项目:Visit    文件:ManagedHttpClientConnectionFactory.java   
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;
}
项目:ZTLib    文件:ManagedHttpClientConnectionFactory.java   
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;
}
项目:java-restclient    文件:HTTPCBuilder.java   
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);
}
项目:java-restclient    文件:HTTPCBuilder.java   
@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);
}
项目:remote-files-sync    文件:DefaultBHttpClientConnection.java   
/**
 * 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);
}
项目:Visit    文件:DefaultBHttpClientConnection.java   
/**
 * 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);
}
项目:ZTLib    文件:DefaultBHttpClientConnection.java   
/**
 * 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);
}