Search in sources :

Example 11 with BlockingHttpClient

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

the class HttpConnectionContextProtocolTest method testProtocol.

@ParameterizedTest
@EnumSource(Config.class)
void testProtocol(Config config) throws Exception {
    try (ServerContext serverContext = startServer(config);
        BlockingHttpClient client = newClient(serverContext, config);
        BlockingHttpConnection connection = client.reserveConnection(client.get("/"))) {
        assertThat("Client-side connection protocol does not match expected value", connection.connectionContext().protocol(), equalTo(config.expectedProtocol));
        assertThat("Server-side connection protocol does not match expected value", connection.request(connection.get("/")).payloadBody(textSerializerUtf8()), equalTo(config.expectedProtocol.name()));
    }
}
Also used : ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpConnection(io.servicetalk.http.api.BlockingHttpConnection) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with BlockingHttpClient

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

the class BlockingProtobufUrlClient method main.

public static void main(String[] args) throws Exception {
    try (BlockingHttpClient client = HttpClients.forMultiAddressUrl().buildBlocking()) {
        HttpResponse resp = client.request(client.post("http://localhost:8080/protobuf").payloadBody(RequestMessage.newBuilder().setMessage("value").build(), REQ_SERIALIZER));
        System.out.println(resp.toString((name, value) -> value));
        System.out.println(resp.payloadBody(RESP_SERIALIZER));
    }
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) REQ_SERIALIZER(io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.REQ_SERIALIZER) HttpResponse(io.servicetalk.http.api.HttpResponse) RESP_SERIALIZER(io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.RESP_SERIALIZER) RequestMessage(io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.RequestMessage) HttpClients(io.servicetalk.http.netty.HttpClients) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse)

Example 13 with BlockingHttpClient

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

the class BlockingHelloWorldUrlClient method main.

public static void main(String[] args) throws Exception {
    try (BlockingHttpClient client = HttpClients.forMultiAddressUrl().buildBlocking()) {
        HttpResponse response = client.request(client.get("http://localhost:8080/sayHello"));
        System.out.println(response.toString((name, value) -> value));
        System.out.println(response.payloadBody(textSerializerUtf8()));
    }
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpSerializers.textSerializerUtf8(io.servicetalk.http.api.HttpSerializers.textSerializerUtf8) HttpResponse(io.servicetalk.http.api.HttpResponse) HttpClients(io.servicetalk.http.netty.HttpClients) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse)

Example 14 with BlockingHttpClient

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

the class HttpClientWithAlpn method main.

public static void main(String[] args) throws Exception {
    // streaming API see helloworld examples.
    try (BlockingHttpClient client = HttpClients.forSingleAddress("localhost", 8080).protocols(h2Default(), // Configure support for HTTP/2 and HTTP/1.1 protocols
    h1Default()).sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).build()).buildBlocking()) {
        HttpResponse response = client.request(client.get("/"));
        System.out.println(response.toString((name, value) -> value));
        System.out.println(response.payloadBody(textSerializerUtf8()));
    }
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpProtocolConfigs.h1Default(io.servicetalk.http.netty.HttpProtocolConfigs.h1Default) HttpProtocolConfigs.h2Default(io.servicetalk.http.netty.HttpProtocolConfigs.h2Default) HttpSerializers.textSerializerUtf8(io.servicetalk.http.api.HttpSerializers.textSerializerUtf8) HttpResponse(io.servicetalk.http.api.HttpResponse) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) HttpClients(io.servicetalk.http.netty.HttpClients) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder)

Example 15 with BlockingHttpClient

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

the class HttpClientMutualTLS method main.

public static void main(String[] args) throws Exception {
    // streaming API see helloworld examples.
    try (BlockingHttpClient client = HttpClients.forSingleAddress("localhost", 8080).sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).keyManager(DefaultTestCerts::loadClientPem, DefaultTestCerts::loadClientKey).build()).buildBlocking()) {
        HttpResponse response = client.request(client.get("/"));
        System.out.println(response.toString((name, value) -> value));
        System.out.println(response.payloadBody(textSerializerUtf8()));
    }
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpSerializers.textSerializerUtf8(io.servicetalk.http.api.HttpSerializers.textSerializerUtf8) HttpResponse(io.servicetalk.http.api.HttpResponse) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) HttpClients(io.servicetalk.http.netty.HttpClients) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder)

Aggregations

BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)86 HttpResponse (io.servicetalk.http.api.HttpResponse)57 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45 ServerContext (io.servicetalk.transport.api.ServerContext)43 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)27 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)26 InetSocketAddress (java.net.InetSocketAddress)26 MethodSource (org.junit.jupiter.params.provider.MethodSource)25 Test (org.junit.jupiter.api.Test)24 HttpRequest (io.servicetalk.http.api.HttpRequest)20 HttpSerializers.textSerializerUtf8 (io.servicetalk.http.api.HttpSerializers.textSerializerUtf8)20 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)20 Single (io.servicetalk.concurrent.api.Single)19 OK (io.servicetalk.http.api.HttpResponseStatus.OK)17 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Matchers.is (org.hamcrest.Matchers.is)16 HostAndPort (io.servicetalk.transport.api.HostAndPort)15 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)14 HttpExecutionStrategy (io.servicetalk.http.api.HttpExecutionStrategy)13 ReservedBlockingHttpConnection (io.servicetalk.http.api.ReservedBlockingHttpConnection)13