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()));
}
}
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));
}
}
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()));
}
}
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()));
}
}
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()));
}
}
Aggregations