use of io.servicetalk.http.api.BlockingStreamingHttpClient in project servicetalk by apple.
the class BlockingPojoStreamingClient method main.
public static void main(String[] args) throws Exception {
try (BlockingStreamingHttpClient client = HttpClients.forSingleAddress("localhost", 8080).buildBlockingStreaming()) {
BlockingStreamingHttpResponse response = client.request(client.post("/pojos").payloadBody(asList(new CreatePojoRequest("value1"), new CreatePojoRequest("value2"), new CreatePojoRequest("value3")), REQ_STREAMING_SERIALIZER));
System.out.println(response.toString((name, value) -> value));
// the full response payload body is drained in case of exceptions
try (BlockingIterator<PojoResponse> payload = response.payloadBody(RESP_STREAMING_SERIALIZER).iterator()) {
while (payload.hasNext()) {
System.out.println(payload.next());
}
}
}
}
use of io.servicetalk.http.api.BlockingStreamingHttpClient in project servicetalk by apple.
the class BlockingPojoStreamingUrlClient method main.
public static void main(String[] args) throws Exception {
try (BlockingStreamingHttpClient client = HttpClients.forMultiAddressUrl().buildBlockingStreaming()) {
BlockingStreamingHttpResponse response = client.request(client.post("http://localhost:8080/pojos").payloadBody(asList(new CreatePojoRequest("value1"), new CreatePojoRequest("value2"), new CreatePojoRequest("value3")), REQ_STREAMING_SERIALIZER));
System.out.println(response.toString((name, value) -> value));
// the full response payload body is drained in case of exceptions
try (BlockingIterator<PojoResponse> payload = response.payloadBody(RESP_STREAMING_SERIALIZER).iterator()) {
while (payload.hasNext()) {
System.out.println(payload.next());
}
}
}
}
use of io.servicetalk.http.api.BlockingStreamingHttpClient in project servicetalk by apple.
the class ServiceTalkContentCodingTest method assertSuccessful.
protected void assertSuccessful(final ContentCodec encoding) throws Throwable {
assertResponse(client().request(client().get("/").encoding(encoding).payloadBody(payloadAsString((byte) 'a'), textSerializerUtf8())).toStreamingResponse());
final BlockingStreamingHttpClient blockingStreamingHttpClient = client().asBlockingStreamingClient();
assertResponse(blockingStreamingHttpClient.request(blockingStreamingHttpClient.get("/").encoding(encoding).payloadBody(singletonList(payloadAsString((byte) 'a')), textSerializer())).toStreamingResponse());
final StreamingHttpClient streamingHttpClient = client().asStreamingClient();
assertResponse(streamingHttpClient.request(streamingHttpClient.get("/").encoding(encoding).payloadBody(from(payloadAsString((byte) 'a')), textSerializer())).toFuture().get());
}
use of io.servicetalk.http.api.BlockingStreamingHttpClient in project servicetalk by apple.
the class AsyncContextHttpFilterVerifier method verifyServerFilterAsyncContextVisibility.
/**
* Verify that all interactions with the request/response and message-body from a request that goes through
* the provided {@link StreamingHttpServiceFilterFactory} filter, have valid visibility of the {@link AsyncContext}.
*
* @param filter The {@link StreamingHttpServiceFilterFactory} filter to verify.
*/
public static void verifyServerFilterAsyncContextVisibility(final StreamingHttpServiceFilterFactory filter) throws Exception {
final BlockingQueue<Throwable> errors = new LinkedBlockingDeque<>();
final List<String> payload = singletonList("Hello World");
final ServerContext serverContext = forAddress(localAddress(0)).appendServiceFilter(asyncContextAssertionFilter(errors)).appendServiceFilter(filter).listenStreamingAndAwait(asyncContextRequestHandler(errors));
final BlockingStreamingHttpClient client = forSingleAddress(serverHostAndPort(serverContext)).buildBlockingStreaming();
final BlockingStreamingHttpRequest request = client.post("/test").payloadBody(payload, appSerializerUtf8FixLen());
final BlockingStreamingHttpResponse resp = client.request(request);
assertThat(resp.status(), is(OK));
Iterator<String> itr = resp.payloadBody(appSerializerUtf8FixLen()).iterator();
assertThat(itr.hasNext(), is(true));
assertThat(itr.next(), is(payload.get(0)));
assertThat(itr.hasNext(), is(false));
assertNoAsyncErrors(errors);
}
Aggregations