Search in sources :

Example 11 with HttpServerBuilder

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

the class HttpProtocolConfigTest method serverWithDuplicatedH1ProtocolConfig.

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

Example 12 with HttpServerBuilder

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

the class HttpProtocolConfigTest method serverWithDuplicatedH2ProtocolConfig.

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

Example 13 with HttpServerBuilder

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

the class HttpProtocolConfigTest method serverWithEmptyProtocolConfig.

@Test
void serverWithEmptyProtocolConfig() {
    HttpServerBuilder builder = HttpServers.forAddress(localAddress(0));
    Exception e = assertThrows(IllegalArgumentException.class, () -> builder.protocols(new HttpProtocolConfig[0]));
    assertEquals("No protocols specified", e.getMessage());
}
Also used : HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder) HttpProtocolConfig(io.servicetalk.http.api.HttpProtocolConfig) Test(org.junit.jupiter.api.Test)

Example 14 with HttpServerBuilder

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

the class AbstractJerseyStreamingHttpServiceTest method setUp.

protected void setUp(final RouterApi api) throws Exception {
    this.api = api;
    HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0));
    HttpJerseyRouterBuilder routerBuilder = new HttpJerseyRouterBuilder();
    configureBuilders(serverBuilder, routerBuilder);
    DefaultJerseyStreamingHttpRouter router = routerBuilder.from(application());
    final Configuration config = router.configuration();
    streamingJsonEnabled = getValue(config.getProperties(), config.getRuntimeType(), JSON_FEATURE, "", String.class).toLowerCase().contains("servicetalk");
    HttpServerBuilder httpServerBuilder = serverBuilder.ioExecutor(serverCtx.ioExecutor()).bufferAllocator(serverCtx.bufferAllocator());
    switch(api) {
        case ASYNC_AGGREGATED:
            serverContext = buildRouter(httpServerBuilder, toAggregated(router));
            break;
        case ASYNC_STREAMING:
            serverContext = buildRouter(httpServerBuilder, router);
            break;
        case BLOCKING_AGGREGATED:
            serverContext = buildRouter(httpServerBuilder, toBlocking(router));
            break;
        case BLOCKING_STREAMING:
            serverContext = buildRouter(httpServerBuilder, toBlockingStreaming(router));
            break;
        default:
            throw new IllegalArgumentException(api.name());
    }
    final HostAndPort hostAndPort = serverHostAndPort(serverContext);
    httpClient = HttpClients.forSingleAddress(hostAndPort).buildStreaming();
    hostHeader = hostHeader(hostAndPort);
}
Also used : AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) HostAndPort(io.servicetalk.transport.api.HostAndPort) Configuration(javax.ws.rs.core.Configuration) HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder) TestUtils.getContentAsString(io.servicetalk.http.router.jersey.TestUtils.getContentAsString) CharSequences.newAsciiString(io.servicetalk.buffer.api.CharSequences.newAsciiString)

Example 15 with HttpServerBuilder

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

the class NettyHttpServerConnectionDrainTest method server.

private static ServerContext server(boolean autoDrain, StreamingHttpService handler) throws Exception {
    HttpServerBuilder httpServerBuilder = HttpServers.forAddress(AddressUtils.localAddress(0));
    if (!autoDrain) {
        httpServerBuilder = httpServerBuilder.drainRequestPayloadBody(false);
    }
    ServerContext serverContext = httpServerBuilder.listenStreamingAndAwait(handler);
    return new ServerContext() {

        @Override
        public SocketAddress listenAddress() {
            return serverContext.listenAddress();
        }

        @Override
        public ExecutionContext<?> executionContext() {
            return serverContext.executionContext();
        }

        @Override
        public void acceptConnections(final boolean accept) {
            serverContext.acceptConnections(accept);
        }

        @Override
        public Completable onClose() {
            return serverContext.onClose();
        }

        @Override
        public Completable closeAsync() {
            return serverContext.closeAsync();
        }

        @Override
        public void close() {
            // Without draining the request is expected to hang, don't wait too long unless on CI
            int timeoutSeconds = CI ? 15 : 1;
            awaitTermination(serverContext.closeAsyncGracefully().timeout(timeoutSeconds, SECONDS).onErrorResume(t -> serverContext.closeAsync().concat(Completable.failed(t))).toFuture());
        }
    };
}
Also used : ServerContext(io.servicetalk.transport.api.ServerContext) HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder)

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