Search in sources :

Example 11 with SocketConfig

use of org.apache.hc.core5.http.io.SocketConfig in project httpcomponents-core by apache.

the class TestingFramework method startServer.

private void startServer() throws TestingFrameworkException {
    /*
         * Start an in-process server and handle all HTTP requests
         * with the requestHandler.
         */
    final SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(15000, TimeUnit.MILLISECONDS).build();
    final ServerBootstrap serverBootstrap = ServerBootstrap.bootstrap().setLookupRegistry(new UriPatternMatcher<>()).setSocketConfig(socketConfig).register("/*", requestHandler);
    server = serverBootstrap.create();
    try {
        server.start();
    } catch (final IOException e) {
        throw new TestingFrameworkException(e);
    }
    port = server.getLocalPort();
}
Also used : SocketConfig(org.apache.hc.core5.http.io.SocketConfig) IOException(java.io.IOException) ServerBootstrap(org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap)

Example 12 with SocketConfig

use of org.apache.hc.core5.http.io.SocketConfig in project httpcomponents-core by apache.

the class ClassicTestClient method start.

public void start(final HttpProcessor httpProcessor) {
    if (requesterRef.get() == null) {
        final HttpRequestExecutor requestExecutor = new HttpRequestExecutor(HttpRequestExecutor.DEFAULT_WAIT_FOR_CONTINUE, DefaultConnectionReuseStrategy.INSTANCE, LoggingHttp1StreamListener.INSTANCE);
        final StrictConnPool<HttpHost, HttpClientConnection> connPool = new StrictConnPool<>(20, 50, TimeValue.NEG_ONE_MILLISECOND, PoolReusePolicy.LIFO, LoggingConnPoolListener.INSTANCE);
        final HttpRequester requester = new HttpRequester(requestExecutor, httpProcessor != null ? httpProcessor : HttpProcessors.client(), connPool, socketConfig, new LoggingBHttpClientConnectionFactory(Http1Config.DEFAULT, CharCodingConfig.DEFAULT), sslContext != null ? sslContext.getSocketFactory() : null, null, null, DefaultAddressResolver.INSTANCE);
        requesterRef.compareAndSet(null, requester);
    } else {
        throw new IllegalStateException("Requester has already been started");
    }
}
Also used : HttpRequestExecutor(org.apache.hc.core5.http.impl.io.HttpRequestExecutor) StrictConnPool(org.apache.hc.core5.pool.StrictConnPool) HttpHost(org.apache.hc.core5.http.HttpHost) HttpClientConnection(org.apache.hc.core5.http.io.HttpClientConnection) HttpRequester(org.apache.hc.core5.http.impl.bootstrap.HttpRequester)

Aggregations

SocketConfig (org.apache.hc.core5.http.io.SocketConfig)8 HttpServer (org.apache.hc.core5.http.impl.bootstrap.HttpServer)6 IOException (java.io.IOException)4 HttpException (org.apache.hc.core5.http.HttpException)3 HttpHost (org.apache.hc.core5.http.HttpHost)3 SocketTimeoutException (java.net.SocketTimeoutException)2 SSLContext (javax.net.ssl.SSLContext)2 SSLConnectionSocketFactory (org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory)2 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)2 ConnectionClosedException (org.apache.hc.core5.http.ConnectionClosedException)2 ExceptionListener (org.apache.hc.core5.http.ExceptionListener)2 HttpConnection (org.apache.hc.core5.http.HttpConnection)2 ServerBootstrap (org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap)2 InetAddress (java.net.InetAddress)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 TimeUnit (java.util.concurrent.TimeUnit)1 DnsResolver (org.apache.hc.client5.http.DnsResolver)1 HttpRoute (org.apache.hc.client5.http.HttpRoute)1 SystemDefaultDnsResolver (org.apache.hc.client5.http.SystemDefaultDnsResolver)1