use of io.servicetalk.http.api.BlockingStreamingHttpResponse in project servicetalk by apple.
the class BlockingProtobufStreamingUrlClient 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/protobuf").payloadBody(asList(RequestMessage.newBuilder().setMessage("value1").build(), RequestMessage.newBuilder().setMessage("value22").build(), RequestMessage.newBuilder().setMessage("value333").build()), REQ_STREAMING_SERIALIZER));
System.out.println(response.toString((name, value) -> value));
// the full response payload body is drained in case of exceptions
try (BlockingIterator<ResponseMessage> payload = response.payloadBody(RESP_STREAMING_SERIALIZER).iterator()) {
while (payload.hasNext()) {
System.out.println(payload.next());
}
}
}
}
use of io.servicetalk.http.api.BlockingStreamingHttpResponse in project servicetalk by apple.
the class BlockingProtobufStreamingClient method main.
public static void main(String[] args) throws Exception {
try (BlockingStreamingHttpClient client = HttpClients.forSingleAddress("localhost", 8080).buildBlockingStreaming()) {
BlockingStreamingHttpResponse response = client.request(client.post("/protobuf").payloadBody(asList(RequestMessage.newBuilder().setMessage("value1").build(), RequestMessage.newBuilder().setMessage("value22").build(), RequestMessage.newBuilder().setMessage("value333").build()), REQ_STREAMING_SERIALIZER));
System.out.println(response.toString((name, value) -> value));
// the full response payload body is drained in case of exceptions
try (BlockingIterator<ResponseMessage> payload = response.payloadBody(RESP_STREAMING_SERIALIZER).iterator()) {
while (payload.hasNext()) {
System.out.println(payload.next());
}
}
}
}
use of io.servicetalk.http.api.BlockingStreamingHttpResponse in project servicetalk by apple.
the class BlockingHelloWorldStreamingClient method main.
public static void main(String[] args) throws Exception {
try (BlockingStreamingHttpClient client = HttpClients.forSingleAddress("localhost", 8080).buildBlockingStreaming()) {
BlockingStreamingHttpResponse response = client.request(client.get("/sayHello"));
System.out.println(response.toString((name, value) -> value));
// the full response payload body is drained in case of exceptions
try (BlockingIterator<String> payload = response.payloadBody(appSerializerUtf8FixLen()).iterator()) {
while (payload.hasNext()) {
System.out.println(payload.next());
}
}
}
}
use of io.servicetalk.http.api.BlockingStreamingHttpResponse in project servicetalk by apple.
the class BlockingHelloWorldStreamingUrlClient method main.
public static void main(String[] args) throws Exception {
try (BlockingStreamingHttpClient client = HttpClients.forMultiAddressUrl().buildBlockingStreaming()) {
BlockingStreamingHttpResponse response = client.request(client.get("http://localhost:8080/sayHello"));
System.out.println(response.toString((name, value) -> value));
// the full response payload body is drained in case of exceptions
try (BlockingIterator<String> payload = response.payloadBody(appSerializerUtf8FixLen()).iterator()) {
while (payload.hasNext()) {
System.out.println(payload.next());
}
}
}
}
use of io.servicetalk.http.api.BlockingStreamingHttpResponse in project servicetalk by apple.
the class BlockingStreamingHttpServiceTest method defaultResponseStatusNoPayload.
@Test
void defaultResponseStatusNoPayload() throws Exception {
BlockingStreamingHttpClient client = context((ctx, request, response) -> response.sendMetaData().close());
BlockingStreamingHttpResponse response = client.request(client.get("/"));
assertResponse(response);
assertThat(response.toResponse().toFuture().get().payloadBody(), is(EMPTY_BUFFER));
}
Aggregations