Search in sources :

Example 6 with BasicServerTlsStrategy

use of org.apache.hc.core5.http.nio.ssl.BasicServerTlsStrategy in project httpcomponents-core by apache.

the class H2TLSIntegrationTest method testTLSClientAuthFailure.

@Test
public void testTLSClientAuthFailure() throws Exception {
    server = AsyncServerBootstrap.bootstrap().setLookupRegistry(new UriPatternMatcher<>()).setIOReactorConfig(IOReactorConfig.custom().setSoTimeout(TIMEOUT).build()).setTlsStrategy(new BasicServerTlsStrategy(SSLTestContexts.createServerSSLContext(), (endpoint, sslEngine) -> sslEngine.setNeedClientAuth(true), null)).setStreamListener(LoggingHttp1StreamListener.INSTANCE_SERVER).setIOSessionDecorator(LoggingIOSessionDecorator.INSTANCE).setExceptionCallback(LoggingExceptionCallback.INSTANCE).setIOSessionListener(LoggingIOSessionListener.INSTANCE).register("*", () -> new EchoHandler(2048)).create();
    server.start();
    requester = H2RequesterBootstrap.bootstrap().setIOReactorConfig(IOReactorConfig.custom().setSoTimeout(TIMEOUT).build()).setTlsStrategy(new BasicClientTlsStrategy(SSLTestContexts.createClientSSLContext())).setStreamListener(LoggingHttp1StreamListener.INSTANCE_CLIENT).setConnPoolListener(LoggingConnPoolListener.INSTANCE).setIOSessionDecorator(LoggingIOSessionDecorator.INSTANCE).setExceptionCallback(LoggingExceptionCallback.INSTANCE).setIOSessionListener(LoggingIOSessionListener.INSTANCE).create();
    server.start();
    final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
    final ListenerEndpoint listener = future.get();
    final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
    requester.start();
    final HttpHost target = new HttpHost(URIScheme.HTTPS.id, "localhost", address.getPort());
    final Future<Message<HttpResponse, String>> resultFuture1 = requester.execute(new BasicRequestProducer(Method.POST, target, "/stuff", new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null);
    final ExecutionException exception = Assertions.assertThrows(ExecutionException.class, () -> resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()));
    final Throwable cause = exception.getCause();
    assertThat(cause, CoreMatchers.instanceOf(IOException.class));
}
Also used : StringAsyncEntityConsumer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer) Message(org.apache.hc.core5.http.Message) InetSocketAddress(java.net.InetSocketAddress) BasicRequestProducer(org.apache.hc.core5.http.nio.support.BasicRequestProducer) BasicServerTlsStrategy(org.apache.hc.core5.http.nio.ssl.BasicServerTlsStrategy) StringAsyncEntityProducer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer) IOException(java.io.IOException) BasicClientTlsStrategy(org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy) ListenerEndpoint(org.apache.hc.core5.reactor.ListenerEndpoint) HttpHost(org.apache.hc.core5.http.HttpHost) UriPatternMatcher(org.apache.hc.core5.http.protocol.UriPatternMatcher) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)6 BasicServerTlsStrategy (org.apache.hc.core5.http.nio.ssl.BasicServerTlsStrategy)6 ListenerEndpoint (org.apache.hc.core5.reactor.ListenerEndpoint)6 HttpHost (org.apache.hc.core5.http.HttpHost)5 Message (org.apache.hc.core5.http.Message)5 StringAsyncEntityConsumer (org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer)5 StringAsyncEntityProducer (org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer)5 BasicClientTlsStrategy (org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy)5 BasicRequestProducer (org.apache.hc.core5.http.nio.support.BasicRequestProducer)5 UriPatternMatcher (org.apache.hc.core5.http.protocol.UriPatternMatcher)5 Test (org.junit.jupiter.api.Test)5 ExecutionException (java.util.concurrent.ExecutionException)4 IOException (java.io.IOException)3 URL (java.net.URL)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 SSLContext (javax.net.ssl.SSLContext)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 SSLSession (javax.net.ssl.SSLSession)1 HttpResponse (org.apache.hc.core5.http.HttpResponse)1 ProtocolVersion (org.apache.hc.core5.http.ProtocolVersion)1