Search in sources :

Example 86 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class GrpcSslAndNonSslConnectionsTest method secureClientToNonSecureServerClosesConnection.

@Test
void secureClientToNonSecureServerClosesConnection() throws Exception {
    try (ServerContext serverContext = nonSecureGrpcServer();
        BlockingTesterClient client = secureGrpcClient(serverContext, new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).peerHost(serverPemHostname())).buildBlocking(clientFactory())) {
        GrpcStatusException e = assertThrows(GrpcStatusException.class, () -> client.test(REQUEST));
        assertThat(e.getCause(), instanceOf(SSLHandshakeException.class));
    }
}
Also used : GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) ServerContext(io.servicetalk.transport.api.ServerContext) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) Test(org.junit.jupiter.api.Test)

Example 87 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project baremaps by baremaps.

the class Edit method call.

@Override
public Integer call() throws Exception {
    BlobStore blobStore = options.blobStore();
    DataSource dataSource = PostgresUtils.datasource(database);
    // Configure serialization
    ObjectMapper objectMapper = defaultObjectMapper();
    // Configure the application
    ResourceConfig application = new ResourceConfig().register(CorsFilter.class).register(EditorResources.class).register(contextResolverFor(objectMapper)).register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(tileset).to(URI.class).named("tileset");
            bind(style).to(URI.class).named("style");
            bind(blobStore).to(BlobStore.class);
            bind(dataSource).to(DataSource.class);
            bind(objectMapper).to(ObjectMapper.class);
        }
    });
    BlockingStreamingHttpService httpService = new HttpJerseyRouterBuilder().buildBlockingStreaming(application);
    ServerContext serverContext = HttpServers.forPort(port).listenBlockingStreamingAndAwait(httpService);
    logger.info("Listening on {}", serverContext.listenAddress());
    serverContext.awaitShutdown();
    return 0;
}
Also used : CorsFilter(com.baremaps.server.common.CorsFilter) BlockingStreamingHttpService(io.servicetalk.http.api.BlockingStreamingHttpService) ServerContext(io.servicetalk.transport.api.ServerContext) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) BlobStore(com.baremaps.blob.BlobStore) DefaultObjectMapper.defaultObjectMapper(com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataSource(javax.sql.DataSource) HttpJerseyRouterBuilder(io.servicetalk.http.router.jersey.HttpJerseyRouterBuilder)

Aggregations

ServerContext (io.servicetalk.transport.api.ServerContext)87 Test (org.junit.jupiter.api.Test)40 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)32 HttpResponse (io.servicetalk.http.api.HttpResponse)29 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)29 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)28 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)27 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)24 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)23 MethodSource (org.junit.jupiter.params.provider.MethodSource)20 Single (io.servicetalk.concurrent.api.Single)18 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)17 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)17 InetSocketAddress (java.net.InetSocketAddress)17 ClientSslConfigBuilder (io.servicetalk.transport.api.ClientSslConfigBuilder)14 Publisher.from (io.servicetalk.concurrent.api.Publisher.from)13 DefaultTestCerts (io.servicetalk.test.resources.DefaultTestCerts)13 StreamingHttpService (io.servicetalk.http.api.StreamingHttpService)12 Matchers.is (org.hamcrest.Matchers.is)12