Search in sources :

Example 6 with CharCodingConfig

use of org.apache.hc.core5.http.config.CharCodingConfig in project mercury by yellow013.

the class ClientConfiguration method main.

public static final void main(final String[] args) throws Exception {
    // Use custom message parser / writer to customize the way HTTP
    // messages are parsed from and written out to the data stream.
    final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory = new DefaultHttpResponseParserFactory() {

        @Override
        public HttpMessageParser<ClassicHttpResponse> create(final Http1Config h1Config) {
            final LineParser lineParser = new BasicLineParser() {

                @Override
                public Header parseHeader(final CharArrayBuffer buffer) {
                    try {
                        return super.parseHeader(buffer);
                    } catch (final ParseException ex) {
                        return new BasicHeader(buffer.toString(), null);
                    }
                }
            };
            return new DefaultHttpResponseParser(lineParser, DefaultClassicHttpResponseFactory.INSTANCE, h1Config);
        }
    };
    final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory = new DefaultHttpRequestWriterFactory();
    // Create HTTP/1.1 protocol configuration
    final Http1Config h1Config = Http1Config.custom().setMaxHeaderCount(200).setMaxLineLength(2000).build();
    // Create connection configuration
    final CharCodingConfig connectionConfig = CharCodingConfig.custom().setMalformedInputAction(CodingErrorAction.IGNORE).setUnmappableInputAction(CodingErrorAction.IGNORE).setCharset(StandardCharsets.UTF_8).build();
    // Use a custom connection factory to customize the process of
    // initialization of outgoing HTTP connections. Beside standard connection
    // configuration parameters HTTP connection factory can define message
    // parser / writer routines to be employed by individual connections.
    @SuppressWarnings("unused") final HttpConnectionFactory<ManagedHttpClientConnection> connFactory = new ManagedHttpClientConnectionFactory(h1Config, connectionConfig, requestWriterFactory, responseParserFactory);
    // Client HTTP connection objects when fully initialized can be bound to
    // an arbitrary network socket. The process of network socket initialization,
    // its connection to a remote address and binding to a local one is controlled
    // by a connection socket factory.
    // SSL context for secure connections can be created either based on
    // system or application specific properties.
    final SSLContext sslcontext = SSLContexts.createSystemDefault();
    // Create a registry of custom connection socket factories for supported
    // protocol schemes.
    final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", new SSLConnectionSocketFactory(sslcontext)).build();
    // Use custom DNS resolver to override the system DNS resolution.
    final DnsResolver dnsResolver = new SystemDefaultDnsResolver() {

        @Override
        public InetAddress[] resolve(final String host) throws UnknownHostException {
            if (host.equalsIgnoreCase("myhost")) {
                return new InetAddress[] { InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }) };
            } else {
                return super.resolve(host);
            }
        }
    };
    // Create a connection manager with custom configuration.
    final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry, PoolConcurrencyPolicy.STRICT, PoolReusePolicy.LIFO, TimeValue.ofMinutes(5), null, dnsResolver, null);
    // Create socket configuration
    final SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).build();
    // Configure the connection manager to use socket configuration either
    // by default or for a specific host.
    connManager.setDefaultSocketConfig(socketConfig);
    // Validate connections after 1 sec of inactivity
    connManager.setValidateAfterInactivity(TimeValue.ofSeconds(10));
    // Configure total max or per route limits for persistent connections
    // that can be kept in the pool or leased by the connection manager.
    connManager.setMaxTotal(100);
    connManager.setDefaultMaxPerRoute(10);
    connManager.setMaxPerRoute(new HttpRoute(new HttpHost("somehost", 80)), 20);
    // Use custom cookie store if necessary.
    final CookieStore cookieStore = new BasicCookieStore();
    // Use custom credentials provider if necessary.
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    // Create global request configuration
    final RequestConfig defaultRequestConfig = RequestConfig.custom().setCookieSpec(StandardCookieSpec.STRICT).setExpectContinueEnabled(true).setTargetPreferredAuthSchemes(Arrays.asList(StandardAuthScheme.NTLM, StandardAuthScheme.DIGEST)).setProxyPreferredAuthSchemes(Collections.singletonList(StandardAuthScheme.BASIC)).build();
    try (final CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(connManager).setDefaultCookieStore(cookieStore).setDefaultCredentialsProvider(credentialsProvider).setProxy(new HttpHost("myproxy", 8080)).setDefaultRequestConfig(defaultRequestConfig).build()) {
        final HttpGet httpget = new HttpGet("http://httpbin.org/get");
        // Request configuration can be overridden at the request level.
        // They will take precedence over the one set at the client level.
        final RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig).setConnectionRequestTimeout(Timeout.ofSeconds(5)).setConnectTimeout(Timeout.ofSeconds(5)).setProxy(new HttpHost("myotherproxy", 8080)).build();
        httpget.setConfig(requestConfig);
        // Execution context can be customized locally.
        final HttpClientContext context = HttpClientContext.create();
        // Contextual attributes set the local context level will take
        // precedence over those set at the client level.
        context.setCookieStore(cookieStore);
        context.setCredentialsProvider(credentialsProvider);
        System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
        try (final CloseableHttpResponse response = httpclient.execute(httpget, context)) {
            System.out.println("----------------------------------------");
            System.out.println(response.getCode() + " " + response.getReasonPhrase());
            System.out.println(EntityUtils.toString(response.getEntity()));
            // Once the request has been executed the local context can
            // be used to examine updated state and various objects affected
            // by the request execution.
            // Last executed request
            context.getRequest();
            // Execution route
            context.getHttpRoute();
            // Auth exchanges
            context.getAuthExchanges();
            // Cookie origin
            context.getCookieOrigin();
            // Cookie spec used
            context.getCookieSpec();
            // User security token
            context.getUserToken();
        }
    }
}
Also used : CharCodingConfig(org.apache.hc.core5.http.config.CharCodingConfig) BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) HttpGet(org.apache.hc.client5.http.classic.methods.HttpGet) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) SystemDefaultDnsResolver(org.apache.hc.client5.http.SystemDefaultDnsResolver) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.hc.client5.http.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.hc.client5.http.socket.PlainConnectionSocketFactory) BasicLineParser(org.apache.hc.core5.http.message.BasicLineParser) LineParser(org.apache.hc.core5.http.message.LineParser) HttpHost(org.apache.hc.core5.http.HttpHost) DefaultHttpResponseParser(org.apache.hc.core5.http.impl.io.DefaultHttpResponseParser) CloseableHttpResponse(org.apache.hc.client5.http.impl.classic.CloseableHttpResponse) ManagedHttpClientConnectionFactory(org.apache.hc.client5.http.impl.io.ManagedHttpClientConnectionFactory) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) DnsResolver(org.apache.hc.client5.http.DnsResolver) SystemDefaultDnsResolver(org.apache.hc.client5.http.SystemDefaultDnsResolver) RequestConfig(org.apache.hc.client5.http.config.RequestConfig) CloseableHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient) SocketConfig(org.apache.hc.core5.http.io.SocketConfig) HttpClientContext(org.apache.hc.client5.http.protocol.HttpClientContext) BasicLineParser(org.apache.hc.core5.http.message.BasicLineParser) SSLContext(javax.net.ssl.SSLContext) BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) CredentialsProvider(org.apache.hc.client5.http.auth.CredentialsProvider) DefaultHttpRequestWriterFactory(org.apache.hc.core5.http.impl.io.DefaultHttpRequestWriterFactory) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager) DefaultHttpResponseParserFactory(org.apache.hc.core5.http.impl.io.DefaultHttpResponseParserFactory) ManagedHttpClientConnection(org.apache.hc.client5.http.io.ManagedHttpClientConnection) HttpRoute(org.apache.hc.client5.http.HttpRoute) CookieStore(org.apache.hc.client5.http.cookie.CookieStore) BasicCookieStore(org.apache.hc.client5.http.cookie.BasicCookieStore) BasicCookieStore(org.apache.hc.client5.http.cookie.BasicCookieStore) ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) ParseException(org.apache.hc.core5.http.ParseException) InetAddress(java.net.InetAddress) Http1Config(org.apache.hc.core5.http.config.Http1Config) BasicHeader(org.apache.hc.core5.http.message.BasicHeader)

Example 7 with CharCodingConfig

use of org.apache.hc.core5.http.config.CharCodingConfig in project httpcomponents-client by apache.

the class H2AsyncClientBuilder method build.

public CloseableHttpAsyncClient build() {
    AuthenticationStrategy targetAuthStrategyCopy = this.targetAuthStrategy;
    if (targetAuthStrategyCopy == null) {
        targetAuthStrategyCopy = DefaultAuthenticationStrategy.INSTANCE;
    }
    AuthenticationStrategy proxyAuthStrategyCopy = this.proxyAuthStrategy;
    if (proxyAuthStrategyCopy == null) {
        proxyAuthStrategyCopy = DefaultAuthenticationStrategy.INSTANCE;
    }
    String userAgentCopy = this.userAgent;
    if (userAgentCopy == null) {
        if (systemProperties) {
            userAgentCopy = getProperty("http.agent", null);
        }
        if (userAgentCopy == null) {
            userAgentCopy = VersionInfo.getSoftwareInfo("Apache-HttpAsyncClient", "org.apache.hc.client5", getClass());
        }
    }
    final HttpProcessorBuilder b = HttpProcessorBuilder.create();
    if (requestInterceptors != null) {
        for (final RequestInterceptorEntry entry : requestInterceptors) {
            if (entry.position == RequestInterceptorEntry.Position.FIRST) {
                b.addFirst(entry.interceptor);
            }
        }
    }
    if (responseInterceptors != null) {
        for (final ResponseInterceptorEntry entry : responseInterceptors) {
            if (entry.position == ResponseInterceptorEntry.Position.FIRST) {
                b.addFirst(entry.interceptor);
            }
        }
    }
    b.addAll(new RequestDefaultHeaders(defaultHeaders), new RequestUserAgent(userAgentCopy), new RequestExpectContinue());
    if (!cookieManagementDisabled) {
        b.add(new RequestAddCookies());
    }
    if (!cookieManagementDisabled) {
        b.add(new ResponseProcessCookies());
    }
    if (requestInterceptors != null) {
        for (final RequestInterceptorEntry entry : requestInterceptors) {
            if (entry.position == RequestInterceptorEntry.Position.LAST) {
                b.addLast(entry.interceptor);
            }
        }
    }
    if (responseInterceptors != null) {
        for (final ResponseInterceptorEntry entry : responseInterceptors) {
            if (entry.position == ResponseInterceptorEntry.Position.LAST) {
                b.addLast(entry.interceptor);
            }
        }
    }
    final HttpProcessor httpProcessor = b.build();
    final NamedElementChain<AsyncExecChainHandler> execChainDefinition = new NamedElementChain<>();
    execChainDefinition.addLast(new H2AsyncMainClientExec(httpProcessor), ChainElement.MAIN_TRANSPORT.name());
    execChainDefinition.addFirst(new AsyncConnectExec(new DefaultHttpProcessor(new RequestTargetHost(), new RequestUserAgent(userAgentCopy)), proxyAuthStrategyCopy, schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE, authCachingDisabled), ChainElement.CONNECT.name());
    execChainDefinition.addFirst(new AsyncProtocolExec(targetAuthStrategyCopy, proxyAuthStrategyCopy, schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE, authCachingDisabled), ChainElement.PROTOCOL.name());
    // Add request retry executor, if not disabled
    if (!automaticRetriesDisabled) {
        HttpRequestRetryStrategy retryStrategyCopy = this.retryStrategy;
        if (retryStrategyCopy == null) {
            retryStrategyCopy = DefaultHttpRequestRetryStrategy.INSTANCE;
        }
        execChainDefinition.addFirst(new AsyncHttpRequestRetryExec(retryStrategyCopy), ChainElement.RETRY.name());
    }
    HttpRoutePlanner routePlannerCopy = this.routePlanner;
    if (routePlannerCopy == null) {
        SchemePortResolver schemePortResolverCopy = this.schemePortResolver;
        if (schemePortResolverCopy == null) {
            schemePortResolverCopy = DefaultSchemePortResolver.INSTANCE;
        }
        routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy);
    }
    // Add redirect executor, if not disabled
    if (!redirectHandlingDisabled) {
        RedirectStrategy redirectStrategyCopy = this.redirectStrategy;
        if (redirectStrategyCopy == null) {
            redirectStrategyCopy = DefaultRedirectStrategy.INSTANCE;
        }
        execChainDefinition.addFirst(new AsyncRedirectExec(routePlannerCopy, redirectStrategyCopy), ChainElement.REDIRECT.name());
    }
    final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
    final IOEventHandlerFactory ioEventHandlerFactory = new H2AsyncClientProtocolStarter(new DefaultHttpProcessor(new H2RequestContent(), new H2RequestTargetHost(), new H2RequestConnControl()), (request, context) -> pushConsumerRegistry.get(request), h2Config != null ? h2Config : H2Config.DEFAULT, charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT);
    final DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioEventHandlerFactory, ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT, threadFactory != null ? threadFactory : new DefaultThreadFactory("httpclient-dispatch", true), ioSessionDecorator != null ? ioSessionDecorator : LoggingIOSessionDecorator.INSTANCE, ioReactorExceptionCallback != null ? ioReactorExceptionCallback : LoggingExceptionCallback.INSTANCE, ioSessionListener, ioSession -> ioSession.enqueue(new ShutdownCommand(CloseMode.GRACEFUL), Command.Priority.IMMEDIATE));
    if (execInterceptors != null) {
        for (final ExecInterceptorEntry entry : execInterceptors) {
            switch(entry.position) {
                case AFTER:
                    execChainDefinition.addAfter(entry.existing, entry.interceptor, entry.name);
                    break;
                case BEFORE:
                    execChainDefinition.addBefore(entry.existing, entry.interceptor, entry.name);
                    break;
                case REPLACE:
                    execChainDefinition.replace(entry.existing, entry.interceptor);
                    break;
                case FIRST:
                    execChainDefinition.addFirst(entry.interceptor, entry.name);
                    break;
                case LAST:
                    // Don't add last, after H2AsyncMainClientExec, as that does not delegate to the chain
                    // Instead, add the interceptor just before it, making it effectively the last interceptor
                    execChainDefinition.addBefore(ChainElement.MAIN_TRANSPORT.name(), entry.interceptor, entry.name);
                    break;
            }
        }
    }
    customizeExecChain(execChainDefinition);
    NamedElementChain<AsyncExecChainHandler>.Node current = execChainDefinition.getLast();
    AsyncExecChainElement execChain = null;
    while (current != null) {
        execChain = new AsyncExecChainElement(current.getValue(), execChain);
        current = current.getPrevious();
    }
    Lookup<AuthSchemeFactory> authSchemeRegistryCopy = this.authSchemeRegistry;
    if (authSchemeRegistryCopy == null) {
        authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeFactory>create().register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE).register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE).register(StandardAuthScheme.NTLM, NTLMSchemeFactory.INSTANCE).register(StandardAuthScheme.SPNEGO, SPNegoSchemeFactory.DEFAULT).register(StandardAuthScheme.KERBEROS, KerberosSchemeFactory.DEFAULT).build();
    }
    Lookup<CookieSpecFactory> cookieSpecRegistryCopy = this.cookieSpecRegistry;
    if (cookieSpecRegistryCopy == null) {
        cookieSpecRegistryCopy = CookieSpecSupport.createDefault();
    }
    CookieStore cookieStoreCopy = this.cookieStore;
    if (cookieStoreCopy == null) {
        cookieStoreCopy = new BasicCookieStore();
    }
    CredentialsProvider credentialsProviderCopy = this.credentialsProvider;
    if (credentialsProviderCopy == null) {
        if (systemProperties) {
            credentialsProviderCopy = new SystemDefaultCredentialsProvider();
        } else {
            credentialsProviderCopy = new BasicCredentialsProvider();
        }
    }
    TlsStrategy tlsStrategyCopy = this.tlsStrategy;
    if (tlsStrategyCopy == null) {
        if (systemProperties) {
            tlsStrategyCopy = DefaultClientTlsStrategy.getSystemDefault();
        } else {
            tlsStrategyCopy = DefaultClientTlsStrategy.getDefault();
        }
    }
    final MultihomeConnectionInitiator connectionInitiator = new MultihomeConnectionInitiator(ioReactor, dnsResolver);
    final InternalH2ConnPool connPool = new InternalH2ConnPool(connectionInitiator, host -> null, tlsStrategyCopy);
    connPool.setConnectionConfigResolver(connectionConfigResolver);
    List<Closeable> closeablesCopy = closeables != null ? new ArrayList<>(closeables) : null;
    if (closeablesCopy == null) {
        closeablesCopy = new ArrayList<>(1);
    }
    if (evictIdleConnections) {
        final IdleConnectionEvictor connectionEvictor = new IdleConnectionEvictor(connPool, maxIdleTime != null ? maxIdleTime : TimeValue.ofSeconds(30L));
        closeablesCopy.add(connectionEvictor::shutdown);
        connectionEvictor.start();
    }
    closeablesCopy.add(connPool);
    return new InternalH2AsyncClient(ioReactor, execChain, pushConsumerRegistry, threadFactory != null ? threadFactory : new DefaultThreadFactory("httpclient-main", true), connPool, routePlannerCopy, cookieSpecRegistryCopy, authSchemeRegistryCopy, cookieStoreCopy, credentialsProviderCopy, defaultRequestConfig, closeablesCopy);
}
Also used : BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) HttpProcessor(org.apache.hc.core5.http.protocol.HttpProcessor) DefaultHttpProcessor(org.apache.hc.core5.http.protocol.DefaultHttpProcessor) RequestDefaultHeaders(org.apache.hc.client5.http.protocol.RequestDefaultHeaders) Closeable(java.io.Closeable) DefaultThreadFactory(org.apache.hc.core5.concurrent.DefaultThreadFactory) HttpRoutePlanner(org.apache.hc.client5.http.routing.HttpRoutePlanner) SystemDefaultCredentialsProvider(org.apache.hc.client5.http.impl.auth.SystemDefaultCredentialsProvider) RequestExpectContinue(org.apache.hc.client5.http.protocol.RequestExpectContinue) AsyncExecChainHandler(org.apache.hc.client5.http.async.AsyncExecChainHandler) DefaultConnectingIOReactor(org.apache.hc.core5.reactor.DefaultConnectingIOReactor) CookieStore(org.apache.hc.client5.http.cookie.CookieStore) BasicCookieStore(org.apache.hc.client5.http.cookie.BasicCookieStore) RequestTargetHost(org.apache.hc.core5.http.protocol.RequestTargetHost) H2RequestTargetHost(org.apache.hc.core5.http2.protocol.H2RequestTargetHost) BasicCookieStore(org.apache.hc.client5.http.cookie.BasicCookieStore) DefaultRoutePlanner(org.apache.hc.client5.http.impl.routing.DefaultRoutePlanner) TlsStrategy(org.apache.hc.core5.http.nio.ssl.TlsStrategy) DefaultClientTlsStrategy(org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy) AuthSchemeFactory(org.apache.hc.client5.http.auth.AuthSchemeFactory) DefaultAuthenticationStrategy(org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy) AuthenticationStrategy(org.apache.hc.client5.http.AuthenticationStrategy) H2RequestContent(org.apache.hc.core5.http2.protocol.H2RequestContent) ShutdownCommand(org.apache.hc.core5.http.nio.command.ShutdownCommand) H2RequestConnControl(org.apache.hc.core5.http2.protocol.H2RequestConnControl) DefaultSchemePortResolver(org.apache.hc.client5.http.impl.DefaultSchemePortResolver) SchemePortResolver(org.apache.hc.client5.http.SchemePortResolver) ResponseProcessCookies(org.apache.hc.client5.http.protocol.ResponseProcessCookies) RedirectStrategy(org.apache.hc.client5.http.protocol.RedirectStrategy) DefaultRedirectStrategy(org.apache.hc.client5.http.impl.DefaultRedirectStrategy) RequestAddCookies(org.apache.hc.client5.http.protocol.RequestAddCookies) RequestUserAgent(org.apache.hc.core5.http.protocol.RequestUserAgent) BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) SystemDefaultCredentialsProvider(org.apache.hc.client5.http.impl.auth.SystemDefaultCredentialsProvider) CredentialsProvider(org.apache.hc.client5.http.auth.CredentialsProvider) NamedElementChain(org.apache.hc.core5.http.config.NamedElementChain) DefaultHttpProcessor(org.apache.hc.core5.http.protocol.DefaultHttpProcessor) HttpProcessorBuilder(org.apache.hc.core5.http.protocol.HttpProcessorBuilder) DefaultHttpRequestRetryStrategy(org.apache.hc.client5.http.impl.DefaultHttpRequestRetryStrategy) HttpRequestRetryStrategy(org.apache.hc.client5.http.HttpRequestRetryStrategy) CookieSpecFactory(org.apache.hc.client5.http.cookie.CookieSpecFactory) IOEventHandlerFactory(org.apache.hc.core5.reactor.IOEventHandlerFactory) MultihomeConnectionInitiator(org.apache.hc.client5.http.impl.nio.MultihomeConnectionInitiator) H2RequestTargetHost(org.apache.hc.core5.http2.protocol.H2RequestTargetHost)

Example 8 with CharCodingConfig

use of org.apache.hc.core5.http.config.CharCodingConfig in project httpcomponents-client by apache.

the class ClientConfiguration method main.

public static final void main(final String[] args) throws Exception {
    // Use custom message parser / writer to customize the way HTTP
    // messages are parsed from and written out to the data stream.
    final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory = new DefaultHttpResponseParserFactory() {

        @Override
        public HttpMessageParser<ClassicHttpResponse> create(final Http1Config h1Config) {
            final LineParser lineParser = new BasicLineParser() {

                @Override
                public Header parseHeader(final CharArrayBuffer buffer) {
                    try {
                        return super.parseHeader(buffer);
                    } catch (final ParseException ex) {
                        return new BasicHeader(buffer.toString(), null);
                    }
                }
            };
            return new DefaultHttpResponseParser(lineParser, DefaultClassicHttpResponseFactory.INSTANCE, h1Config);
        }
    };
    final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory = new DefaultHttpRequestWriterFactory();
    // Create HTTP/1.1 protocol configuration
    final Http1Config h1Config = Http1Config.custom().setMaxHeaderCount(200).setMaxLineLength(2000).build();
    // Create connection configuration
    final CharCodingConfig connectionConfig = CharCodingConfig.custom().setMalformedInputAction(CodingErrorAction.IGNORE).setUnmappableInputAction(CodingErrorAction.IGNORE).setCharset(StandardCharsets.UTF_8).build();
    // Use a custom connection factory to customize the process of
    // initialization of outgoing HTTP connections. Beside standard connection
    // configuration parameters HTTP connection factory can define message
    // parser / writer routines to be employed by individual connections.
    final HttpConnectionFactory<ManagedHttpClientConnection> connFactory = new ManagedHttpClientConnectionFactory(h1Config, connectionConfig, requestWriterFactory, responseParserFactory);
    // Client HTTP connection objects when fully initialized can be bound to
    // an arbitrary network socket. The process of network socket initialization,
    // its connection to a remote address and binding to a local one is controlled
    // by a connection socket factory.
    // SSL context for secure connections can be created either based on
    // system or application specific properties.
    final SSLContext sslcontext = SSLContexts.createSystemDefault();
    // Create a registry of custom connection socket factories for supported
    // protocol schemes.
    final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", new SSLConnectionSocketFactory(sslcontext)).build();
    // Use custom DNS resolver to override the system DNS resolution.
    final DnsResolver dnsResolver = new SystemDefaultDnsResolver() {

        @Override
        public InetAddress[] resolve(final String host) throws UnknownHostException {
            if (host.equalsIgnoreCase("myhost")) {
                return new InetAddress[] { InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }) };
            } else {
                return super.resolve(host);
            }
        }
    };
    // Create a connection manager with custom configuration.
    final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry, PoolConcurrencyPolicy.STRICT, PoolReusePolicy.LIFO, TimeValue.ofMinutes(5), null, dnsResolver, null);
    // Configure the connection manager to use socket configuration either
    // by default or for a specific host.
    connManager.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).build());
    // Validate connections after 10 sec of inactivity
    connManager.setDefaultConnectionConfig(ConnectionConfig.custom().setConnectTimeout(Timeout.ofSeconds(30)).setSocketTimeout(Timeout.ofSeconds(30)).setValidateAfterInactivity(TimeValue.ofSeconds(10)).setTimeToLive(TimeValue.ofHours(1)).build());
    // Use TLS v1.3 only
    connManager.setDefaultTlsConfig(TlsConfig.custom().setHandshakeTimeout(Timeout.ofSeconds(30)).setSupportedProtocols(TLS.V_1_3).build());
    // Configure total max or per route limits for persistent connections
    // that can be kept in the pool or leased by the connection manager.
    connManager.setMaxTotal(100);
    connManager.setDefaultMaxPerRoute(10);
    connManager.setMaxPerRoute(new HttpRoute(new HttpHost("somehost", 80)), 20);
    // Use custom cookie store if necessary.
    final CookieStore cookieStore = new BasicCookieStore();
    // Use custom credentials provider if necessary.
    final CredentialsProvider credentialsProvider = CredentialsProviderBuilder.create().build();
    // Create global request configuration
    final RequestConfig defaultRequestConfig = RequestConfig.custom().setCookieSpec(StandardCookieSpec.STRICT).setExpectContinueEnabled(true).setTargetPreferredAuthSchemes(Arrays.asList(StandardAuthScheme.NTLM, StandardAuthScheme.DIGEST)).setProxyPreferredAuthSchemes(Collections.singletonList(StandardAuthScheme.BASIC)).build();
    try (final CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(connManager).setDefaultCookieStore(cookieStore).setDefaultCredentialsProvider(credentialsProvider).setProxy(new HttpHost("myproxy", 8080)).setDefaultRequestConfig(defaultRequestConfig).build()) {
        final HttpGet httpget = new HttpGet("http://httpbin.org/get");
        // Request configuration can be overridden at the request level.
        // They will take precedence over the one set at the client level.
        final RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig).setConnectionRequestTimeout(Timeout.ofSeconds(5)).build();
        httpget.setConfig(requestConfig);
        // Execution context can be customized locally.
        // Contextual attributes set the local context level will take
        // precedence over those set at the client level.
        final HttpClientContext context = ContextBuilder.create().useCookieStore(cookieStore).useCredentialsProvider(credentialsProvider).build();
        System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
        httpclient.execute(httpget, context, response -> {
            System.out.println("----------------------------------------");
            System.out.println(httpget + "->" + new StatusLine(response));
            EntityUtils.consume(response.getEntity());
            return null;
        });
        // Last executed request
        context.getRequest();
        // Execution route
        context.getHttpRoute();
        // Auth exchanges
        context.getAuthExchanges();
        // Cookie origin
        context.getCookieOrigin();
        // Cookie spec used
        context.getCookieSpec();
        // User security token
        context.getUserToken();
    }
}
Also used : CharCodingConfig(org.apache.hc.core5.http.config.CharCodingConfig) HttpGet(org.apache.hc.client5.http.classic.methods.HttpGet) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) SystemDefaultDnsResolver(org.apache.hc.client5.http.SystemDefaultDnsResolver) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.hc.client5.http.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.hc.client5.http.socket.PlainConnectionSocketFactory) BasicLineParser(org.apache.hc.core5.http.message.BasicLineParser) LineParser(org.apache.hc.core5.http.message.LineParser) HttpHost(org.apache.hc.core5.http.HttpHost) DefaultHttpResponseParser(org.apache.hc.core5.http.impl.io.DefaultHttpResponseParser) ManagedHttpClientConnectionFactory(org.apache.hc.client5.http.impl.io.ManagedHttpClientConnectionFactory) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) DnsResolver(org.apache.hc.client5.http.DnsResolver) SystemDefaultDnsResolver(org.apache.hc.client5.http.SystemDefaultDnsResolver) RequestConfig(org.apache.hc.client5.http.config.RequestConfig) CloseableHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient) HttpClientContext(org.apache.hc.client5.http.protocol.HttpClientContext) BasicLineParser(org.apache.hc.core5.http.message.BasicLineParser) SSLContext(javax.net.ssl.SSLContext) CredentialsProvider(org.apache.hc.client5.http.auth.CredentialsProvider) DefaultHttpRequestWriterFactory(org.apache.hc.core5.http.impl.io.DefaultHttpRequestWriterFactory) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager) StatusLine(org.apache.hc.core5.http.message.StatusLine) DefaultHttpResponseParserFactory(org.apache.hc.core5.http.impl.io.DefaultHttpResponseParserFactory) ManagedHttpClientConnection(org.apache.hc.client5.http.io.ManagedHttpClientConnection) HttpRoute(org.apache.hc.client5.http.HttpRoute) CookieStore(org.apache.hc.client5.http.cookie.CookieStore) BasicCookieStore(org.apache.hc.client5.http.cookie.BasicCookieStore) BasicCookieStore(org.apache.hc.client5.http.cookie.BasicCookieStore) ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) ParseException(org.apache.hc.core5.http.ParseException) InetAddress(java.net.InetAddress) Http1Config(org.apache.hc.core5.http.config.Http1Config) BasicHeader(org.apache.hc.core5.http.message.BasicHeader)

Example 9 with CharCodingConfig

use of org.apache.hc.core5.http.config.CharCodingConfig in project httpcomponents-client by apache.

the class H2AsyncClientProtocolStarter method createHandler.

@Override
public IOEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
    if (HEADER_LOG.isDebugEnabled() || FRAME_LOG.isDebugEnabled() || FRAME_PAYLOAD_LOG.isDebugEnabled() || FLOW_CTRL_LOG.isDebugEnabled()) {
        final String id = ioSession.getId();
        final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(httpProcessor, exchangeHandlerFactory, h2Config, charCodingConfig, new H2StreamListener() {

            final FramePrinter framePrinter = new FramePrinter();

            private void logFrameInfo(final String prefix, final RawFrame frame) {
                try {
                    final LogAppendable logAppendable = new LogAppendable(FRAME_LOG, prefix);
                    framePrinter.printFrameInfo(frame, logAppendable);
                    logAppendable.flush();
                } catch (final IOException ignore) {
                }
            }

            private void logFramePayload(final String prefix, final RawFrame frame) {
                try {
                    final LogAppendable logAppendable = new LogAppendable(FRAME_PAYLOAD_LOG, prefix);
                    framePrinter.printPayload(frame, logAppendable);
                    logAppendable.flush();
                } catch (final IOException ignore) {
                }
            }

            private void logFlowControl(final String prefix, final int streamId, final int delta, final int actualSize) {
                FLOW_CTRL_LOG.debug("{} stream {} flow control {} -> {}", prefix, streamId, delta, actualSize);
            }

            @Override
            public void onHeaderInput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
                if (HEADER_LOG.isDebugEnabled()) {
                    for (int i = 0; i < headers.size(); i++) {
                        HEADER_LOG.debug("{} << {}", id, headers.get(i));
                    }
                }
            }

            @Override
            public void onHeaderOutput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
                if (HEADER_LOG.isDebugEnabled()) {
                    for (int i = 0; i < headers.size(); i++) {
                        HEADER_LOG.debug("{} >> {}", id, headers.get(i));
                    }
                }
            }

            @Override
            public void onFrameInput(final HttpConnection connection, final int streamId, final RawFrame frame) {
                if (FRAME_LOG.isDebugEnabled()) {
                    logFrameInfo(id + " <<", frame);
                }
                if (FRAME_PAYLOAD_LOG.isDebugEnabled()) {
                    logFramePayload(id + " <<", frame);
                }
            }

            @Override
            public void onFrameOutput(final HttpConnection connection, final int streamId, final RawFrame frame) {
                if (FRAME_LOG.isDebugEnabled()) {
                    logFrameInfo(id + " >>", frame);
                }
                if (FRAME_PAYLOAD_LOG.isDebugEnabled()) {
                    logFramePayload(id + " >>", frame);
                }
            }

            @Override
            public void onInputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
                if (FLOW_CTRL_LOG.isDebugEnabled()) {
                    logFlowControl(id + " <<", streamId, delta, actualSize);
                }
            }

            @Override
            public void onOutputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
                if (FLOW_CTRL_LOG.isDebugEnabled()) {
                    logFlowControl(id + " >>", streamId, delta, actualSize);
                }
            }
        });
        return new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, false);
    }
    final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(httpProcessor, exchangeHandlerFactory, h2Config, charCodingConfig, null);
    return new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, false);
}
Also used : H2StreamListener(org.apache.hc.core5.http2.impl.nio.H2StreamListener) FramePrinter(org.apache.hc.core5.http2.frame.FramePrinter) ClientH2PrefaceHandler(org.apache.hc.core5.http2.impl.nio.ClientH2PrefaceHandler) HttpConnection(org.apache.hc.core5.http.HttpConnection) ClientH2StreamMultiplexerFactory(org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory) RawFrame(org.apache.hc.core5.http2.frame.RawFrame) IOException(java.io.IOException)

Example 10 with CharCodingConfig

use of org.apache.hc.core5.http.config.CharCodingConfig in project httpcomponents-client by apache.

the class HttpAsyncClientBuilder method build.

@SuppressWarnings("deprecated")
public CloseableHttpAsyncClient build() {
    AsyncClientConnectionManager connManagerCopy = this.connManager;
    if (connManagerCopy == null) {
        connManagerCopy = PoolingAsyncClientConnectionManagerBuilder.create().build();
    }
    ConnectionKeepAliveStrategy keepAliveStrategyCopy = this.keepAliveStrategy;
    if (keepAliveStrategyCopy == null) {
        keepAliveStrategyCopy = DefaultConnectionKeepAliveStrategy.INSTANCE;
    }
    UserTokenHandler userTokenHandlerCopy = this.userTokenHandler;
    if (userTokenHandlerCopy == null) {
        if (!connectionStateDisabled) {
            userTokenHandlerCopy = DefaultUserTokenHandler.INSTANCE;
        } else {
            userTokenHandlerCopy = NoopUserTokenHandler.INSTANCE;
        }
    }
    AuthenticationStrategy targetAuthStrategyCopy = this.targetAuthStrategy;
    if (targetAuthStrategyCopy == null) {
        targetAuthStrategyCopy = DefaultAuthenticationStrategy.INSTANCE;
    }
    AuthenticationStrategy proxyAuthStrategyCopy = this.proxyAuthStrategy;
    if (proxyAuthStrategyCopy == null) {
        proxyAuthStrategyCopy = DefaultAuthenticationStrategy.INSTANCE;
    }
    String userAgentCopy = this.userAgent;
    if (userAgentCopy == null) {
        if (systemProperties) {
            userAgentCopy = getProperty("http.agent", null);
        }
        if (userAgentCopy == null) {
            userAgentCopy = VersionInfo.getSoftwareInfo("Apache-HttpAsyncClient", "org.apache.hc.client5", getClass());
        }
    }
    final HttpProcessorBuilder b = HttpProcessorBuilder.create();
    if (requestInterceptors != null) {
        for (final RequestInterceptorEntry entry : requestInterceptors) {
            if (entry.position == RequestInterceptorEntry.Position.FIRST) {
                b.addFirst(entry.interceptor);
            }
        }
    }
    if (responseInterceptors != null) {
        for (final ResponseInterceptorEntry entry : responseInterceptors) {
            if (entry.position == ResponseInterceptorEntry.Position.FIRST) {
                b.addFirst(entry.interceptor);
            }
        }
    }
    b.addAll(new RequestDefaultHeaders(defaultHeaders), new RequestUserAgent(userAgentCopy), new RequestExpectContinue());
    if (!cookieManagementDisabled) {
        b.add(new RequestAddCookies());
    }
    if (!cookieManagementDisabled) {
        b.add(new ResponseProcessCookies());
    }
    if (requestInterceptors != null) {
        for (final RequestInterceptorEntry entry : requestInterceptors) {
            if (entry.position == RequestInterceptorEntry.Position.LAST) {
                b.addLast(entry.interceptor);
            }
        }
    }
    if (responseInterceptors != null) {
        for (final ResponseInterceptorEntry entry : responseInterceptors) {
            if (entry.position == ResponseInterceptorEntry.Position.LAST) {
                b.addLast(entry.interceptor);
            }
        }
    }
    final HttpProcessor httpProcessor = b.build();
    final NamedElementChain<AsyncExecChainHandler> execChainDefinition = new NamedElementChain<>();
    execChainDefinition.addLast(new HttpAsyncMainClientExec(httpProcessor, keepAliveStrategyCopy, userTokenHandlerCopy), ChainElement.MAIN_TRANSPORT.name());
    execChainDefinition.addFirst(new AsyncConnectExec(new DefaultHttpProcessor(new RequestTargetHost(), new RequestUserAgent(userAgentCopy)), proxyAuthStrategyCopy, schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE, authCachingDisabled), ChainElement.CONNECT.name());
    execChainDefinition.addFirst(new AsyncProtocolExec(targetAuthStrategyCopy, proxyAuthStrategyCopy, schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE, authCachingDisabled), ChainElement.PROTOCOL.name());
    // Add request retry executor, if not disabled
    if (!automaticRetriesDisabled) {
        HttpRequestRetryStrategy retryStrategyCopy = this.retryStrategy;
        if (retryStrategyCopy == null) {
            retryStrategyCopy = DefaultHttpRequestRetryStrategy.INSTANCE;
        }
        execChainDefinition.addFirst(new AsyncHttpRequestRetryExec(retryStrategyCopy), ChainElement.RETRY.name());
    }
    HttpRoutePlanner routePlannerCopy = this.routePlanner;
    if (routePlannerCopy == null) {
        SchemePortResolver schemePortResolverCopy = this.schemePortResolver;
        if (schemePortResolverCopy == null) {
            schemePortResolverCopy = DefaultSchemePortResolver.INSTANCE;
        }
        if (proxy != null) {
            routePlannerCopy = new DefaultProxyRoutePlanner(proxy, schemePortResolverCopy);
        } else if (systemProperties) {
            final ProxySelector defaultProxySelector = AccessController.doPrivileged((PrivilegedAction<ProxySelector>) ProxySelector::getDefault);
            routePlannerCopy = new SystemDefaultRoutePlanner(schemePortResolverCopy, defaultProxySelector);
        } else {
            routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy);
        }
    }
    // Add redirect executor, if not disabled
    if (!redirectHandlingDisabled) {
        RedirectStrategy redirectStrategyCopy = this.redirectStrategy;
        if (redirectStrategyCopy == null) {
            redirectStrategyCopy = DefaultRedirectStrategy.INSTANCE;
        }
        execChainDefinition.addFirst(new AsyncRedirectExec(routePlannerCopy, redirectStrategyCopy), ChainElement.REDIRECT.name());
    }
    List<Closeable> closeablesCopy = closeables != null ? new ArrayList<>(closeables) : null;
    if (!this.connManagerShared) {
        if (closeablesCopy == null) {
            closeablesCopy = new ArrayList<>(1);
        }
        if (evictExpiredConnections || evictIdleConnections) {
            if (connManagerCopy instanceof ConnPoolControl) {
                final IdleConnectionEvictor connectionEvictor = new IdleConnectionEvictor((ConnPoolControl<?>) connManagerCopy, maxIdleTime, maxIdleTime);
                closeablesCopy.add(connectionEvictor::shutdown);
                connectionEvictor.start();
            }
        }
        closeablesCopy.add(connManagerCopy);
    }
    ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy;
    if (reuseStrategyCopy == null) {
        if (systemProperties) {
            final String s = getProperty("http.keepAlive", "true");
            if ("true".equalsIgnoreCase(s)) {
                reuseStrategyCopy = DefaultClientConnectionReuseStrategy.INSTANCE;
            } else {
                reuseStrategyCopy = (request, response, context) -> false;
            }
        } else {
            reuseStrategyCopy = DefaultClientConnectionReuseStrategy.INSTANCE;
        }
    }
    final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
    final IOEventHandlerFactory ioEventHandlerFactory = new HttpAsyncClientProtocolNegotiationStarter(new DefaultHttpProcessor(new H2RequestContent(), new H2RequestTargetHost(), new H2RequestConnControl()), (request, context) -> pushConsumerRegistry.get(request), h2Config != null ? h2Config : H2Config.DEFAULT, h1Config != null ? h1Config : Http1Config.DEFAULT, charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT, reuseStrategyCopy);
    final DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioEventHandlerFactory, ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT, threadFactory != null ? threadFactory : new DefaultThreadFactory("httpclient-dispatch", true), ioSessionDecorator != null ? ioSessionDecorator : LoggingIOSessionDecorator.INSTANCE, ioReactorExceptionCallback != null ? ioReactorExceptionCallback : LoggingExceptionCallback.INSTANCE, ioSessionListener, ioSession -> ioSession.enqueue(new ShutdownCommand(CloseMode.GRACEFUL), Command.Priority.IMMEDIATE));
    if (execInterceptors != null) {
        for (final ExecInterceptorEntry entry : execInterceptors) {
            switch(entry.position) {
                case AFTER:
                    execChainDefinition.addAfter(entry.existing, entry.interceptor, entry.name);
                    break;
                case BEFORE:
                    execChainDefinition.addBefore(entry.existing, entry.interceptor, entry.name);
                    break;
                case REPLACE:
                    execChainDefinition.replace(entry.existing, entry.interceptor);
                    break;
                case FIRST:
                    execChainDefinition.addFirst(entry.interceptor, entry.name);
                    break;
                case LAST:
                    // Don't add last, after HttpAsyncMainClientExec, as that does not delegate to the chain
                    // Instead, add the interceptor just before it, making it effectively the last interceptor
                    execChainDefinition.addBefore(ChainElement.MAIN_TRANSPORT.name(), entry.interceptor, entry.name);
                    break;
            }
        }
    }
    customizeExecChain(execChainDefinition);
    NamedElementChain<AsyncExecChainHandler>.Node current = execChainDefinition.getLast();
    AsyncExecChainElement execChain = null;
    while (current != null) {
        execChain = new AsyncExecChainElement(current.getValue(), execChain);
        current = current.getPrevious();
    }
    Lookup<AuthSchemeFactory> authSchemeRegistryCopy = this.authSchemeRegistry;
    if (authSchemeRegistryCopy == null) {
        authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeFactory>create().register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE).register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE).register(StandardAuthScheme.NTLM, NTLMSchemeFactory.INSTANCE).register(StandardAuthScheme.SPNEGO, SPNegoSchemeFactory.DEFAULT).register(StandardAuthScheme.KERBEROS, KerberosSchemeFactory.DEFAULT).build();
    }
    Lookup<CookieSpecFactory> cookieSpecRegistryCopy = this.cookieSpecRegistry;
    if (cookieSpecRegistryCopy == null) {
        cookieSpecRegistryCopy = CookieSpecSupport.createDefault();
    }
    CookieStore cookieStoreCopy = this.cookieStore;
    if (cookieStoreCopy == null) {
        cookieStoreCopy = new BasicCookieStore();
    }
    CredentialsProvider credentialsProviderCopy = this.credentialsProvider;
    if (credentialsProviderCopy == null) {
        if (systemProperties) {
            credentialsProviderCopy = new SystemDefaultCredentialsProvider();
        } else {
            credentialsProviderCopy = new BasicCredentialsProvider();
        }
    }
    return new InternalHttpAsyncClient(ioReactor, execChain, pushConsumerRegistry, threadFactory != null ? threadFactory : new DefaultThreadFactory("httpclient-main", true), connManagerCopy, routePlannerCopy, tlsConfig, cookieSpecRegistryCopy, authSchemeRegistryCopy, cookieStoreCopy, credentialsProviderCopy, defaultRequestConfig, closeablesCopy);
}
Also used : BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) HttpProcessor(org.apache.hc.core5.http.protocol.HttpProcessor) DefaultHttpProcessor(org.apache.hc.core5.http.protocol.DefaultHttpProcessor) RequestDefaultHeaders(org.apache.hc.client5.http.protocol.RequestDefaultHeaders) Closeable(java.io.Closeable) ProxySelector(java.net.ProxySelector) DefaultThreadFactory(org.apache.hc.core5.concurrent.DefaultThreadFactory) ConnPoolControl(org.apache.hc.core5.pool.ConnPoolControl) HttpRoutePlanner(org.apache.hc.client5.http.routing.HttpRoutePlanner) IdleConnectionEvictor(org.apache.hc.client5.http.impl.IdleConnectionEvictor) SystemDefaultCredentialsProvider(org.apache.hc.client5.http.impl.auth.SystemDefaultCredentialsProvider) SystemDefaultRoutePlanner(org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner) RequestExpectContinue(org.apache.hc.client5.http.protocol.RequestExpectContinue) AsyncExecChainHandler(org.apache.hc.client5.http.async.AsyncExecChainHandler) DefaultConnectingIOReactor(org.apache.hc.core5.reactor.DefaultConnectingIOReactor) CookieStore(org.apache.hc.client5.http.cookie.CookieStore) BasicCookieStore(org.apache.hc.client5.http.cookie.BasicCookieStore) RequestTargetHost(org.apache.hc.core5.http.protocol.RequestTargetHost) H2RequestTargetHost(org.apache.hc.core5.http2.protocol.H2RequestTargetHost) BasicCookieStore(org.apache.hc.client5.http.cookie.BasicCookieStore) DefaultRoutePlanner(org.apache.hc.client5.http.impl.routing.DefaultRoutePlanner) SystemDefaultRoutePlanner(org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner) ConnectionReuseStrategy(org.apache.hc.core5.http.ConnectionReuseStrategy) DefaultClientConnectionReuseStrategy(org.apache.hc.client5.http.impl.DefaultClientConnectionReuseStrategy) AuthSchemeFactory(org.apache.hc.client5.http.auth.AuthSchemeFactory) DefaultAuthenticationStrategy(org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy) AuthenticationStrategy(org.apache.hc.client5.http.AuthenticationStrategy) H2RequestContent(org.apache.hc.core5.http2.protocol.H2RequestContent) DefaultProxyRoutePlanner(org.apache.hc.client5.http.impl.routing.DefaultProxyRoutePlanner) ShutdownCommand(org.apache.hc.core5.http.nio.command.ShutdownCommand) H2RequestConnControl(org.apache.hc.core5.http2.protocol.H2RequestConnControl) AsyncClientConnectionManager(org.apache.hc.client5.http.nio.AsyncClientConnectionManager) PrivilegedAction(java.security.PrivilegedAction) DefaultSchemePortResolver(org.apache.hc.client5.http.impl.DefaultSchemePortResolver) SchemePortResolver(org.apache.hc.client5.http.SchemePortResolver) ResponseProcessCookies(org.apache.hc.client5.http.protocol.ResponseProcessCookies) RedirectStrategy(org.apache.hc.client5.http.protocol.RedirectStrategy) DefaultRedirectStrategy(org.apache.hc.client5.http.impl.DefaultRedirectStrategy) NoopUserTokenHandler(org.apache.hc.client5.http.impl.NoopUserTokenHandler) DefaultUserTokenHandler(org.apache.hc.client5.http.impl.DefaultUserTokenHandler) UserTokenHandler(org.apache.hc.client5.http.UserTokenHandler) RequestAddCookies(org.apache.hc.client5.http.protocol.RequestAddCookies) ConnectionKeepAliveStrategy(org.apache.hc.client5.http.ConnectionKeepAliveStrategy) DefaultConnectionKeepAliveStrategy(org.apache.hc.client5.http.impl.DefaultConnectionKeepAliveStrategy) RequestUserAgent(org.apache.hc.core5.http.protocol.RequestUserAgent) BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) SystemDefaultCredentialsProvider(org.apache.hc.client5.http.impl.auth.SystemDefaultCredentialsProvider) CredentialsProvider(org.apache.hc.client5.http.auth.CredentialsProvider) NamedElementChain(org.apache.hc.core5.http.config.NamedElementChain) DefaultHttpProcessor(org.apache.hc.core5.http.protocol.DefaultHttpProcessor) HttpProcessorBuilder(org.apache.hc.core5.http.protocol.HttpProcessorBuilder) DefaultHttpRequestRetryStrategy(org.apache.hc.client5.http.impl.DefaultHttpRequestRetryStrategy) HttpRequestRetryStrategy(org.apache.hc.client5.http.HttpRequestRetryStrategy) CookieSpecFactory(org.apache.hc.client5.http.cookie.CookieSpecFactory) IOEventHandlerFactory(org.apache.hc.core5.reactor.IOEventHandlerFactory) H2RequestTargetHost(org.apache.hc.core5.http2.protocol.H2RequestTargetHost)

Aggregations

IOEventHandlerFactory (org.apache.hc.core5.reactor.IOEventHandlerFactory)5 IOSession (org.apache.hc.core5.reactor.IOSession)5 List (java.util.List)4 CredentialsProvider (org.apache.hc.client5.http.auth.CredentialsProvider)4 BasicCookieStore (org.apache.hc.client5.http.cookie.BasicCookieStore)4 CookieStore (org.apache.hc.client5.http.cookie.CookieStore)4 HttpHost (org.apache.hc.core5.http.HttpHost)4 CharCodingConfig (org.apache.hc.core5.http.config.CharCodingConfig)4 Http1Config (org.apache.hc.core5.http.config.Http1Config)4 ClientHttp1StreamDuplexerFactory (org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory)4 TlsStrategy (org.apache.hc.core5.http.nio.ssl.TlsStrategy)4 HttpProcessor (org.apache.hc.core5.http.protocol.HttpProcessor)4 ClientH2PrefaceHandler (org.apache.hc.core5.http2.impl.nio.ClientH2PrefaceHandler)4 ClientH2StreamMultiplexerFactory (org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory)4 Supplier (org.apache.hc.core5.function.Supplier)3 NamedElementChain (org.apache.hc.core5.http.config.NamedElementChain)3 DefaultConnectionReuseStrategy (org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy)3 Http1StreamListener (org.apache.hc.core5.http.impl.Http1StreamListener)3 HttpProcessors (org.apache.hc.core5.http.impl.HttpProcessors)3 AsyncServerExchangeHandler (org.apache.hc.core5.http.nio.AsyncServerExchangeHandler)3