Search in sources :

Example 1 with BlockingStreamingHttpResponse

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());
            }
        }
    }
}
Also used : BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) Arrays.asList(java.util.Arrays.asList) RESP_STREAMING_SERIALIZER(io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.RESP_STREAMING_SERIALIZER) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse) REQ_STREAMING_SERIALIZER(io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.REQ_STREAMING_SERIALIZER) ResponseMessage(io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.ResponseMessage) BlockingIterator(io.servicetalk.concurrent.BlockingIterator) RequestMessage(io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.RequestMessage) HttpClients(io.servicetalk.http.netty.HttpClients) BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse) ResponseMessage(io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.ResponseMessage)

Example 2 with BlockingStreamingHttpResponse

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());
            }
        }
    }
}
Also used : BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) Arrays.asList(java.util.Arrays.asList) RESP_STREAMING_SERIALIZER(io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.RESP_STREAMING_SERIALIZER) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse) REQ_STREAMING_SERIALIZER(io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.REQ_STREAMING_SERIALIZER) ResponseMessage(io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.ResponseMessage) BlockingIterator(io.servicetalk.concurrent.BlockingIterator) RequestMessage(io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.RequestMessage) HttpClients(io.servicetalk.http.netty.HttpClients) BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse) ResponseMessage(io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.ResponseMessage)

Example 3 with BlockingStreamingHttpResponse

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());
            }
        }
    }
}
Also used : BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) HttpSerializers.appSerializerUtf8FixLen(io.servicetalk.http.api.HttpSerializers.appSerializerUtf8FixLen) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse) BlockingIterator(io.servicetalk.concurrent.BlockingIterator) HttpClients(io.servicetalk.http.netty.HttpClients) BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse)

Example 4 with BlockingStreamingHttpResponse

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());
            }
        }
    }
}
Also used : BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) HttpSerializers.appSerializerUtf8FixLen(io.servicetalk.http.api.HttpSerializers.appSerializerUtf8FixLen) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse) BlockingIterator(io.servicetalk.concurrent.BlockingIterator) HttpClients(io.servicetalk.http.netty.HttpClients) BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse)

Example 5 with BlockingStreamingHttpResponse

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));
}
Also used : BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

BlockingStreamingHttpClient (io.servicetalk.http.api.BlockingStreamingHttpClient)19 BlockingStreamingHttpResponse (io.servicetalk.http.api.BlockingStreamingHttpResponse)19 Test (org.junit.jupiter.api.Test)9 BlockingIterator (io.servicetalk.concurrent.BlockingIterator)7 HttpClients (io.servicetalk.http.netty.HttpClients)6 BlockingStreamingHttpRequest (io.servicetalk.http.api.BlockingStreamingHttpRequest)4 Arrays.asList (java.util.Arrays.asList)4 Buffer (io.servicetalk.buffer.api.Buffer)3 CreatePojoRequest (io.servicetalk.examples.http.serialization.json.CreatePojoRequest)2 PojoResponse (io.servicetalk.examples.http.serialization.json.PojoResponse)2 REQ_STREAMING_SERIALIZER (io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_STREAMING_SERIALIZER)2 RESP_STREAMING_SERIALIZER (io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_STREAMING_SERIALIZER)2 RequestMessage (io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.RequestMessage)2 ResponseMessage (io.servicetalk.examples.http.serialization.protobuf.ExampleProtos.ResponseMessage)2 REQ_STREAMING_SERIALIZER (io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.REQ_STREAMING_SERIALIZER)2 RESP_STREAMING_SERIALIZER (io.servicetalk.examples.http.serialization.protobuf.SerializerUtils.RESP_STREAMING_SERIALIZER)2 HttpHeaders (io.servicetalk.http.api.HttpHeaders)2 HttpSerializers.appSerializerUtf8FixLen (io.servicetalk.http.api.HttpSerializers.appSerializerUtf8FixLen)2 PlatformDependent.throwException (io.servicetalk.utils.internal.PlatformDependent.throwException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2