From d7fc9a917af54a952c2d9d17ff018cf7ffbb212e Mon Sep 17 00:00:00 2001 From: Idel Pivnitskiy Date: Mon, 7 Mar 2022 09:37:59 -0800 Subject: [PATCH] Remove examples for multi-address client that similar to single-address Motivation: Some HTTP examples that use `HttpClients.forMultiAddressUrl()` are identical to the other example that uses `HttpClients.forSingleAddress(...)`. It doesn't provide much value for users because the top level client API is the same for both client factories. It's enough to demonstrate multi-address use-case in hello-world example only. Modifications: - Remove classes that target `forMultiAddressUrl()` from json, protobuf, and retry examples; - Remove link to `RetryUrlClient` from docs; Result: Less classes in examples to maintain. --- .../docs/modules/ROOT/pages/http/index.adoc | 2 - .../examples/http/retry/RetryUrlClient.java | 53 ------------------- .../json/async/PojoUrlClient.java | 40 -------------- .../streaming/PojoStreamingUrlClient.java | 41 -------------- .../json/blocking/BlockingPojoUrlClient.java | 35 ------------ .../BlockingPojoStreamingUrlClient.java | 48 ----------------- .../protobuf/async/ProtobufUrlClient.java | 40 -------------- .../streaming/ProtobufStreamingUrlClient.java | 42 --------------- .../blocking/BlockingProtobufUrlClient.java | 35 ------------ .../BlockingProtobufStreamingUrlClient.java | 49 ----------------- 10 files changed, 385 deletions(-) delete mode 100644 servicetalk-examples/http/retry/src/main/java/io/servicetalk/examples/http/retry/RetryUrlClient.java delete mode 100644 servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/async/PojoUrlClient.java delete mode 100644 servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/async/streaming/PojoStreamingUrlClient.java delete mode 100644 servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/blocking/BlockingPojoUrlClient.java delete mode 100644 servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/blocking/streaming/BlockingPojoStreamingUrlClient.java delete mode 100644 servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/async/ProtobufUrlClient.java delete mode 100644 servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/async/streaming/ProtobufStreamingUrlClient.java delete mode 100644 servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/blocking/BlockingProtobufUrlClient.java delete mode 100644 servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/blocking/streaming/BlockingProtobufStreamingUrlClient.java diff --git a/servicetalk-examples/docs/modules/ROOT/pages/http/index.adoc b/servicetalk-examples/docs/modules/ROOT/pages/http/index.adoc index 023ef14700..d3be9e01c0 100644 --- a/servicetalk-examples/docs/modules/ROOT/pages/http/index.adoc +++ b/servicetalk-examples/docs/modules/ROOT/pages/http/index.adoc @@ -253,8 +253,6 @@ A special "flaky" `Hello World` server that alternates "509" Gateway Timeout and requests to demonstrate client retry. * link:{source-root}/servicetalk-examples/http/retry/src/main/java/io/servicetalk/examples/http/retry/RetryClient.java[RetryClient.java] - Async `Hello World` example that demonstrates how retry can be requested for a single-address client. -* link:{source-root}/servicetalk-examples/http/retry/src/main/java/io/servicetalk/examples/http/retry/RetryUrlClient.java[RetryUrlClient.java] - -Async `Hello World` example that demonstrates how retry can be requested for a multi-address client. [#HTTP2] diff --git a/servicetalk-examples/http/retry/src/main/java/io/servicetalk/examples/http/retry/RetryUrlClient.java b/servicetalk-examples/http/retry/src/main/java/io/servicetalk/examples/http/retry/RetryUrlClient.java deleted file mode 100644 index 3646de5d4a..0000000000 --- a/servicetalk-examples/http/retry/src/main/java/io/servicetalk/examples/http/retry/RetryUrlClient.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright © 2022 Apple Inc. and the ServiceTalk project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.servicetalk.examples.http.retry; - -import io.servicetalk.http.api.HttpClient; -import io.servicetalk.http.netty.HttpClients; -import io.servicetalk.http.netty.RetryingHttpRequesterFilter; - -import static io.servicetalk.http.api.HttpResponseStatus.StatusClass.SERVER_ERROR_5XX; -import static io.servicetalk.http.api.HttpSerializers.textSerializerUtf8; - -/** - * Extends the Async "Hello World" client to immediately retry requests that get a 5XX response. Up to three attempts - * * will be made, one initial attempt and up to two retries, before failure. - */ -public final class RetryUrlClient { - public static void main(String[] args) throws Exception { - try (HttpClient client = HttpClients.forMultiAddressUrl().initializer((scheme, address, builder) -> { - builder.appendClientFilter(new RetryingHttpRequesterFilter.Builder() - .responseMapper(httpResponseMetaData -> SERVER_ERROR_5XX.contains(httpResponseMetaData.status()) ? - // Response status is 500-599, we request a retry - new RetryingHttpRequesterFilter.HttpResponseException("Retry 5XX", httpResponseMetaData) : - // Not a 5XX response, we do not know whether retry is required - null) - .retryResponses((meta, error) -> RetryingHttpRequesterFilter.BackOffPolicy.ofImmediate(2)) - .build() - ); - }).build()) { - client.request(client.get("http://localhost:8080/sayHello")) - .whenOnSuccess(resp -> { - System.out.println(resp.toString((name, value) -> value)); - System.out.println(resp.payloadBody(textSerializerUtf8())); - }) - // This example is demonstrating asynchronous execution, but needs to prevent the main thread from exiting - // before the response has been processed. This isn't typical usage for an asynchronous API but is useful - // for demonstration purposes. - .toFuture().get(); - } - } -} diff --git a/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/async/PojoUrlClient.java b/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/async/PojoUrlClient.java deleted file mode 100644 index bb5dc9729f..0000000000 --- a/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/async/PojoUrlClient.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright © 2018 Apple Inc. and the ServiceTalk project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.servicetalk.examples.http.serialization.json.async; - -import io.servicetalk.examples.http.serialization.json.CreatePojoRequest; -import io.servicetalk.http.api.HttpClient; -import io.servicetalk.http.netty.HttpClients; - -import static io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_SERIALIZER; -import static io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER; - -public final class PojoUrlClient { - public static void main(String[] args) throws Exception { - try (HttpClient client = HttpClients.forMultiAddressUrl().build()) { - client.request(client.post("http://localhost:8080/pojos") - .payloadBody(new CreatePojoRequest("value"), REQ_SERIALIZER)) - .whenOnSuccess(resp -> { - System.out.println(resp.toString((name, value) -> value)); - System.out.println(resp.payloadBody(RESP_SERIALIZER)); - }) - // This example is demonstrating asynchronous execution, but needs to prevent the main thread from exiting - // before the response has been processed. This isn't typical usage for an asynchronous API but is useful - // for demonstration purposes. - .toFuture().get(); - } - } -} diff --git a/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/async/streaming/PojoStreamingUrlClient.java b/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/async/streaming/PojoStreamingUrlClient.java deleted file mode 100644 index 694f35e4a4..0000000000 --- a/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/async/streaming/PojoStreamingUrlClient.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright © 2018 Apple Inc. and the ServiceTalk project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.servicetalk.examples.http.serialization.json.async.streaming; - -import io.servicetalk.examples.http.serialization.json.CreatePojoRequest; -import io.servicetalk.http.api.StreamingHttpClient; -import io.servicetalk.http.netty.HttpClients; - -import static io.servicetalk.concurrent.api.Publisher.from; -import static io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_STREAMING_SERIALIZER; -import static io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_STREAMING_SERIALIZER; - -public final class PojoStreamingUrlClient { - public static void main(String[] args) throws Exception { - try (StreamingHttpClient client = HttpClients.forMultiAddressUrl().buildStreaming()) { - client.request(client.post("http://localhost:8080/pojos") - .payloadBody(from("value1", "value2", "value3").map(CreatePojoRequest::new), - REQ_STREAMING_SERIALIZER)) - .beforeOnSuccess(response -> System.out.println(response.toString((name, value) -> value))) - .flatMapPublisher(resp -> resp.payloadBody(RESP_STREAMING_SERIALIZER)) - .whenOnNext(System.out::println) - // This example is demonstrating asynchronous execution, but needs to prevent the main thread from exiting - // before the response has been processed. This isn't typical usage for an asynchronous API but is useful - // for demonstration purposes. - .toFuture().get(); - } - } -} diff --git a/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/blocking/BlockingPojoUrlClient.java b/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/blocking/BlockingPojoUrlClient.java deleted file mode 100644 index 22e82c2fdb..0000000000 --- a/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/blocking/BlockingPojoUrlClient.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright © 2018 Apple Inc. and the ServiceTalk project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.servicetalk.examples.http.serialization.json.blocking; - -import io.servicetalk.examples.http.serialization.json.CreatePojoRequest; -import io.servicetalk.http.api.BlockingHttpClient; -import io.servicetalk.http.api.HttpResponse; -import io.servicetalk.http.netty.HttpClients; - -import static io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_SERIALIZER; -import static io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER; - -public final class BlockingPojoUrlClient { - public static void main(String[] args) throws Exception { - try (BlockingHttpClient client = HttpClients.forMultiAddressUrl().buildBlocking()) { - HttpResponse resp = client.request(client.post("http://localhost:8080/pojos") - .payloadBody(new CreatePojoRequest("value"), REQ_SERIALIZER)); - System.out.println(resp.toString((name, value) -> value)); - System.out.println(resp.payloadBody(RESP_SERIALIZER)); - } - } -} diff --git a/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/blocking/streaming/BlockingPojoStreamingUrlClient.java b/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/blocking/streaming/BlockingPojoStreamingUrlClient.java deleted file mode 100644 index 383f1af128..0000000000 --- a/servicetalk-examples/http/serialization/json/src/main/java/io/servicetalk/examples/http/serialization/json/blocking/streaming/BlockingPojoStreamingUrlClient.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright © 2018 Apple Inc. and the ServiceTalk project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.servicetalk.examples.http.serialization.json.blocking.streaming; - -import io.servicetalk.concurrent.BlockingIterator; -import io.servicetalk.examples.http.serialization.json.CreatePojoRequest; -import io.servicetalk.examples.http.serialization.json.PojoResponse; -import io.servicetalk.http.api.BlockingStreamingHttpClient; -import io.servicetalk.http.api.BlockingStreamingHttpResponse; -import io.servicetalk.http.netty.HttpClients; - -import static io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_STREAMING_SERIALIZER; -import static io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_STREAMING_SERIALIZER; -import static java.util.Arrays.asList; - -public final class BlockingPojoStreamingUrlClient { - 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)); - // While it's also possible to use for-each, it's recommended to use try-with-resources to make sure that - // the full response payload body is drained in case of exceptions - try (BlockingIterator payload = response.payloadBody(RESP_STREAMING_SERIALIZER).iterator()) { - while (payload.hasNext()) { - System.out.println(payload.next()); - } - } - } - } -} diff --git a/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/async/ProtobufUrlClient.java b/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/async/ProtobufUrlClient.java deleted file mode 100644 index da1208d2bf..0000000000 --- a/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/async/ProtobufUrlClient.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright © 2022 Apple Inc. and the ServiceTalk project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.servicetalk.examples.http.serialization.protobuf.async; - -import io.servicetalk.examples.http.serialization.protobuf.ExampleProtos; -import io.servicetalk.http.api.HttpClient; -import io.servicetalk.http.netty.HttpClients; - -import static io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.REQ_SERIALIZER; -import static io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.RESP_SERIALIZER; - -public final class ProtobufUrlClient { - public static void main(String[] args) throws Exception { - try (HttpClient client = HttpClients.forMultiAddressUrl().build()) { - client.request(client.post("http://localhost:8080/protobuf") - .payloadBody(ExampleProtos.RequestMessage.newBuilder().setMessage("hello").build(), REQ_SERIALIZER)) - .whenOnSuccess(resp -> { - System.out.println(resp.toString((name, value) -> value)); - System.out.println(resp.payloadBody(RESP_SERIALIZER)); - }) - // This example is demonstrating asynchronous execution, but needs to prevent the main thread from exiting - // before the response has been processed. This isn't typical usage for an asynchronous API but is useful - // for demonstration purposes. - .toFuture().get(); - } - } -} diff --git a/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/async/streaming/ProtobufStreamingUrlClient.java b/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/async/streaming/ProtobufStreamingUrlClient.java deleted file mode 100644 index 512357a78b..0000000000 --- a/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/async/streaming/ProtobufStreamingUrlClient.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 2022 Apple Inc. and the ServiceTalk project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.servicetalk.examples.http.serialization.protobuf.async.streaming; - -import io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.RequestMessage; -import io.servicetalk.http.api.StreamingHttpClient; -import io.servicetalk.http.netty.HttpClients; - -import static io.servicetalk.concurrent.api.Publisher.from; -import static io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.REQ_STREAMING_SERIALIZER; -import static io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.RESP_STREAMING_SERIALIZER; - -public final class ProtobufStreamingUrlClient { - public static void main(String[] args) throws Exception { - try (StreamingHttpClient client = HttpClients.forMultiAddressUrl().buildStreaming()) { - client.request(client.post("http://localhost:8080/protobuf") - .payloadBody(from("value1", "value22", "value333") - .map(message -> RequestMessage.newBuilder().setMessage(message).build()), - REQ_STREAMING_SERIALIZER)) - .beforeOnSuccess(response -> System.out.println(response.toString((name, value) -> value))) - .flatMapPublisher(resp -> resp.payloadBody(RESP_STREAMING_SERIALIZER)) - .whenOnNext(System.out::println) - // This example is demonstrating asynchronous execution, but needs to prevent the main thread from exiting - // before the response has been processed. This isn't typical usage for an asynchronous API but is useful - // for demonstration purposes. - .toFuture().get(); - } - } -} diff --git a/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/blocking/BlockingProtobufUrlClient.java b/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/blocking/BlockingProtobufUrlClient.java deleted file mode 100644 index 72cfe83550..0000000000 --- a/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/blocking/BlockingProtobufUrlClient.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright © 2022 Apple Inc. and the ServiceTalk project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.servicetalk.examples.http.serialization.protobuf.blocking; - -import io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.RequestMessage; -import io.servicetalk.http.api.BlockingHttpClient; -import io.servicetalk.http.api.HttpResponse; -import io.servicetalk.http.netty.HttpClients; - -import static io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.REQ_SERIALIZER; -import static io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.RESP_SERIALIZER; - -public final class BlockingProtobufUrlClient { - 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)); - } - } -} diff --git a/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/blocking/streaming/BlockingProtobufStreamingUrlClient.java b/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/blocking/streaming/BlockingProtobufStreamingUrlClient.java deleted file mode 100644 index dcd76a47f4..0000000000 --- a/servicetalk-examples/http/serialization/protobuf/src/main/java/io/servicetalk/examples/http/serialization/protobuf/blocking/streaming/BlockingProtobufStreamingUrlClient.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © 2022 Apple Inc. and the ServiceTalk project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.servicetalk.examples.http.serialization.protobuf.blocking.streaming; - -import io.servicetalk.concurrent.BlockingIterator; -import io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.RequestMessage; -import io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.ResponseMessage; -import io.servicetalk.http.api.BlockingStreamingHttpClient; -import io.servicetalk.http.api.BlockingStreamingHttpResponse; -import io.servicetalk.http.netty.HttpClients; - -import static io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.REQ_STREAMING_SERIALIZER; -import static io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.RESP_STREAMING_SERIALIZER; -import static java.util.Arrays.asList; - -public final class BlockingProtobufStreamingUrlClient { - 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)); - // While it's also possible to use for-each, it's recommended to use try-with-resources to make sure that - // the full response payload body is drained in case of exceptions - try (BlockingIterator payload = - response.payloadBody(RESP_STREAMING_SERIALIZER).iterator()) { - while (payload.hasNext()) { - System.out.println(payload.next()); - } - } - } - } -}