use of io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.REQ_STREAMING_SERIALIZER 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.examples.http.serialization.protobuf.SerializerUtils.REQ_STREAMING_SERIALIZER 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.examples.http.serialization.protobuf.SerializerUtils.REQ_STREAMING_SERIALIZER in project servicetalk by apple.
the class BlockingProtobufStreamingServer method main.
public static void main(String[] args) throws Exception {
HttpServers.forPort(8080).listenBlockingStreamingAndAwait((ctx, request, response) -> {
if (!"/protobuf".equals(request.requestTarget())) {
response.status(NOT_FOUND).sendMetaData().close();
} else if (!POST.equals(request.method())) {
response.status(METHOD_NOT_ALLOWED).addHeader(ALLOW, POST.name()).sendMetaData().close();
} else {
BlockingIterable<RequestMessage> values = request.payloadBody(REQ_STREAMING_SERIALIZER);
response.status(CREATED);
try (HttpPayloadWriter<ResponseMessage> writer = response.sendMetaData(RESP_STREAMING_SERIALIZER)) {
for (RequestMessage req : values) {
writer.write(ResponseMessage.newBuilder().setLength(req.getMessage().length()).build());
}
}
}
}).awaitShutdown();
}
Aggregations