Search in sources :

Example 6 with HttpServerBuilder

use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.

the class MutualSslTest method mutualSsl.

@ParameterizedTest
@MethodSource("params")
void mutualSsl(SslProvider serverSslProvider, SslProvider clientSslProvider, @SuppressWarnings("rawtypes") Map<SocketOption, Object> serverListenOptions, @SuppressWarnings("rawtypes") Map<SocketOption, Object> clientOptions) throws Exception {
    assumeTcpFastOpen(clientOptions);
    HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0)).sslConfig(new ServerSslConfigBuilder(DefaultTestCerts::loadServerPem, DefaultTestCerts::loadServerKey).trustManager(DefaultTestCerts::loadClientCAPem).clientAuthMode(REQUIRE).provider(serverSslProvider).build());
    for (@SuppressWarnings("rawtypes") Entry<SocketOption, Object> entry : serverListenOptions.entrySet()) {
        @SuppressWarnings("unchecked") SocketOption<Object> option = entry.getKey();
        serverBuilder.listenSocketOption(option, entry.getValue());
    }
    try (ServerContext serverContext = serverBuilder.listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
        BlockingHttpClient client = newClientBuilder(serverContext, clientOptions).sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).provider(clientSslProvider).peerHost(serverPemHostname()).keyManager(DefaultTestCerts::loadClientPem, DefaultTestCerts::loadClientKey).build()).buildBlocking()) {
        assertEquals(HttpResponseStatus.OK, client.request(client.get("/")).status());
    }
}
Also used : SocketOption(java.net.SocketOption) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) ServerSslConfigBuilder(io.servicetalk.transport.api.ServerSslConfigBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with HttpServerBuilder

use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.

the class InvokingThreadsRecorder method init.

void init(BiFunction<IoExecutor, HttpServerBuilder, Single<HttpServerContext>> serverStarter, BiConsumer<IoExecutor, SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress>> clientUpdater) {
    try {
        HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0));
        context = serverStarter.apply(ioExecutor, serverBuilder).toFuture().get();
    } catch (Exception e) {
        fail("Exception in initialization", e);
    }
    SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = HttpClients.forSingleAddress(serverHostAndPort(context));
    clientUpdater.accept(ioExecutor, clientBuilder);
    client = clientBuilder.buildStreaming();
}
Also used : AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) HostAndPort(io.servicetalk.transport.api.HostAndPort) InetSocketAddress(java.net.InetSocketAddress) HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder)

Example 8 with HttpServerBuilder

use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.

the class NettyHttpServerTest method testServiceThrowsReturnsErrorResponse.

@ParameterizedTest(name = "{displayName} [{index}] disableOffloading={0}")
@ValueSource(booleans = { true, false })
void testServiceThrowsReturnsErrorResponse(boolean disableOffloading) throws Exception {
    // the test suite state isn't used by this individual test, but cleanup code requires it is initialized.
    setUp(IMMEDIATE, IMMEDIATE);
    HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0));
    if (disableOffloading) {
        serverBuilder.executionStrategy(offloadNever());
    }
    try (ServerContext serverCtx = serverBuilder.listenStreamingAndAwait((ctx, request, responseFactory) -> {
        throw DELIBERATE_EXCEPTION;
    });
        BlockingHttpClient client = disableOffloading(HttpClients.forResolvedAddress(serverHostAndPort(serverCtx)), disableOffloading).buildBlocking()) {
        HttpResponse resp = client.request(client.get("/"));
        assertThat(resp.status(), is(INTERNAL_SERVER_ERROR));
    }
}
Also used : ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with HttpServerBuilder

use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.

the class BasicAuthStrategyInfluencerTest method setup.

private BlockingHttpClient setup(boolean noOffloadsInfluence) throws Exception {
    ioExecutor = NettyIoExecutors.createIoExecutor(IO_EXECUTOR_NAME_PREFIX);
    HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0));
    when(credentialsVerifier.apply(anyString(), anyString())).thenReturn(succeeded("success"));
    when(credentialsVerifier.closeAsync()).thenReturn(completed());
    when(credentialsVerifier.closeAsyncGracefully()).thenReturn(completed());
    CredentialsVerifier<String> verifier = credentialsVerifier;
    if (noOffloadsInfluence) {
        verifier = new InfluencingVerifier(verifier, offloadNone());
        serverBuilder.executionStrategy(offloadNever());
    }
    serverBuilder.appendServiceFilter(new BasicAuthHttpServiceFilter.Builder<>(verifier, "dummy").buildServer());
    serverBuilder.ioExecutor(ioExecutor);
    service = new OffloadCheckingService();
    serverContext = serverBuilder.listenStreamingAndAwait(service);
    SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = HttpClients.forSingleAddress(serverHostAndPort(serverContext));
    this.client = clientBuilder.buildBlocking();
    return this.client;
}
Also used : AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) HostAndPort(io.servicetalk.transport.api.HostAndPort) InetSocketAddress(java.net.InetSocketAddress) HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 10 with HttpServerBuilder

use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.

the class HttpProtocolConfigTest method serverWithUnsupportedProtocolConfig.

@Test
void serverWithUnsupportedProtocolConfig() {
    HttpServerBuilder builder = HttpServers.forAddress(localAddress(0));
    Exception e = assertThrows(IllegalArgumentException.class, () -> builder.protocols(UNKNOWN_CONFIG));
    assertThat(e.getMessage(), startsWith("Unsupported HttpProtocolConfig"));
}
Also used : HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

HttpServerBuilder (io.servicetalk.http.api.HttpServerBuilder)19 HostAndPort (io.servicetalk.transport.api.HostAndPort)9 ServerContext (io.servicetalk.transport.api.ServerContext)9 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)6 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)6 InetSocketAddress (java.net.InetSocketAddress)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)5 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)5 Single (io.servicetalk.concurrent.api.Single)4 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)4 DefaultTestCerts (io.servicetalk.test.resources.DefaultTestCerts)4 ServerSslConfigBuilder (io.servicetalk.transport.api.ServerSslConfigBuilder)4 Nullable (javax.annotation.Nullable)4 Test (org.junit.jupiter.api.Test)4 Buffer (io.servicetalk.buffer.api.Buffer)3 AfterEach (org.junit.jupiter.api.AfterEach)3