use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class HttpServerFilterOrderTest method prependOrder.
@Test
void prependOrder() throws Exception {
StreamingHttpService filter1 = newMockService();
StreamingHttpService filter2 = newMockService();
ServerContext serverContext = HttpServers.forAddress(localAddress(0)).appendServiceFilter(addFilter(filter1)).appendServiceFilter(addFilter(filter2)).listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
BlockingHttpClient client = forSingleAddress(serverHostAndPort(serverContext)).buildBlocking();
HttpResponse resp = client.request(client.get("/"));
assertThat("Unexpected response.", resp.status(), is(OK));
InOrder verifier = inOrder(filter1, filter2);
verifier.verify(filter1).handle(any(), any(), any());
verifier.verify(filter2).handle(any(), any(), any());
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class HttpServerFilterOrderTest method conditionalNonOffload.
@Test
void conditionalNonOffload() throws Exception {
StreamingHttpService filter0 = newMockService();
StreamingHttpService filter1 = newMockService();
StreamingHttpService filter2 = newMockService();
StreamingHttpService filter3 = newMockService();
ServerContext serverContext = HttpServers.forAddress(localAddress(0)).appendServiceFilter(addFilter(filter0)).appendNonOffloadingServiceFilter(req -> true, addFilter(filter1)).appendNonOffloadingServiceFilter(req -> false, addFilter(filter2)).appendNonOffloadingServiceFilter(req -> true, addFilter(filter3)).listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
BlockingHttpClient client = forSingleAddress(serverHostAndPort(serverContext)).buildBlocking();
HttpResponse resp = client.request(client.get("/"));
assertThat("Unexpected response.", resp.status(), is(OK));
InOrder verifier = inOrder(filter1, filter2, filter3, filter0);
verifier.verify(filter1).handle(any(), any(), any());
verifier.verify(filter2, never()).handle(any(), any(), any());
verifier.verify(filter3).handle(any(), any(), any());
verifier.verify(filter0).handle(any(), any(), any());
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class HttpServerFilterOrderTest method conditional.
@Test
void conditional() throws Exception {
StreamingHttpService filter1 = newMockService();
StreamingHttpService filter2 = newMockService();
StreamingHttpService filter3 = newMockService();
ServerContext serverContext = HttpServers.forAddress(localAddress(0)).appendServiceFilter(req -> true, addFilter(filter1)).appendServiceFilter(req -> false, addFilter(filter2)).appendServiceFilter(req -> true, addFilter(filter3)).listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
BlockingHttpClient client = forSingleAddress(serverHostAndPort(serverContext)).buildBlocking();
HttpResponse resp = client.request(client.get("/"));
assertThat("Unexpected response.", resp.status(), is(OK));
InOrder verifier = inOrder(filter1, filter2, filter3);
verifier.verify(filter1).handle(any(), any(), any());
verifier.verify(filter2, never()).handle(any(), any(), any());
verifier.verify(filter3).handle(any(), any(), any());
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class BlockingProtobufClient method main.
public static void main(String[] args) throws Exception {
try (BlockingHttpClient client = HttpClients.forSingleAddress("localhost", 8080).buildBlocking()) {
HttpResponse resp = client.request(client.post("/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 OpenTracingClient method main.
public static void main(String[] args) throws Exception {
// Publishing to Zipkin is optional, but demonstrated for completeness.
try (ZipkinPublisher zipkinPublisher = new ZipkinPublisher.Builder("servicetalk-test-client", LoggingReporter.CONSOLE).build();
Tracer tracer = new DefaultInMemoryTracer.Builder(SCOPE_MANAGER).addListener(zipkinPublisher).build();
BlockingHttpClient client = HttpClients.forSingleAddress("localhost", 8080).appendClientFilter(new TracingHttpRequesterFilter(tracer, "servicetalk-test-client")).buildBlocking()) {
HttpResponse response = client.request(client.get("/1"));
System.out.println(response.toString((name, value) -> value));
HttpResponse response2 = client.request(client.get("/2"));
System.out.println(response2.toString((name, value) -> value));
}
}
Aggregations