jsr370-experts@jax-rs-spec.java.net

Re: JAX-RS Client Reactive API review

From: Sergey Beryozkin <sberyozkin_at_talend.com>
Date: Thu, 19 Jan 2017 09:48:47 +0000

Sorry, had some typo, will get back a bit later on

Sergey
On 18/01/17 21:46, Sergey Beryozkin wrote:
Hi Pavel

I'm trying to check m02 against the custom ObservableRxInvokerProvider which returns an implementation of ObservableRxInvoker (which extends RxInvoker<Observable> and is done identically to CompletionStageRxInvoker) and I can't compile the below example



Observable<List<String>> cs =
        client.target("remote/forecast/{destination}")
                .resolveTemplate("destination", "mars")
                .request()
                .header("Rx-User", "Java8")
                .rx(ObservableRxInvokerProvider.class) // gets CompletionStageRxInvoker
                .get(new GenericType<List<String>>() {
                });

I'll check in the next couple of days if I did something wrong, I saw you had a TestRxInvoker which is typed to return Strings, but what about T, can you please prototype an Observable provider and see if it works for you...

Thanks, Sergey

https://github.com/jax-rs/api/blob/2.1-m02/jaxrs-api/src/main/java/javax/ws/rs/client/CompletionStageRxInvoker.java
[https://avatars1.githubusercontent.com/u/9721421?v=3&s=400]<https://github.com/jax-rs/api/blob/2.1-m02/jaxrs-api/src/main/java/javax/ws/rs/client/CompletionStageRxInvoker.java>

jax-rs/api<https://github.com/jax-rs/api/blob/2.1-m02/jaxrs-api/src/main/java/javax/ws/rs/client/CompletionStageRxInvoker.java>
github.com
api - JAX-RS API Source Code



On 13/01/17 20:36, Pavel Bucek wrote:

Dear experts,

please review following wiki and APIs:

https://java.net/projects/jax-rs-spec/pages/RxClient

All added classes related to Reactive Client APIs are linked from that page, but let me allow a short recap.

JAX-RS Client is being extended by the ability to provide a way how to process responses in reactive fashion. The change consists of:

- adding rx(...) methods to Invocation.Builder
- defining RxInvoker
- allowing users to extend this API by providing RxInvokerProvider

Specification will mandate implementation for CompletionStage from Java SE 8.

Client code examples:

- basic use

CompletionStage<List<String>> cs =
        client.target("remote/forecast/{destination}")
                .resolveTemplate("destination", "mars")
                .request()
                .header("Rx-User", "Java8")
                .rx() // gets CompletionStageRxInvoker
                .get(new GenericType<List<String>>() {
                });

cs.thenAccept(System.out::println);



- using custom RxInvokerFactory (this is little artificial, since the factory just returns CompletionStageRxInvoker, but support for Observable from RxJava or ListenableFuture from Guava can be done in the exact same manner)

CompletionStage<List<String>> cs =
        client.target("remote/forecast/{destination}")
                .resolveTemplate("destination", "mars")
                .request()
                .header("Rx-User", "Java8")
                .rx(CompletionStageRxInvokerProvider.class)
                .get(new GenericType<List<String>>() {
                });

cs.thenAccept(System.out::println);


Source links:

- https://github.com/jax-rs/api/blob/2.1-m02/jaxrs-api/src/main/java/javax/ws/rs/client/Invocation.java#L298
- https://github.com/jax-rs/api/blob/2.1-m02/jaxrs-api/src/main/java/javax/ws/rs/client/RxInvoker.java
- https://github.com/jax-rs/api/blob/2.1-m02/jaxrs-api/src/main/java/javax/ws/rs/client/RxInvokerProvider.java

Examples & tests:

- https://github.com/jax-rs/api/blob/2.1-m02/jaxrs-api/src/test/java/javax/ws/rs/core/RxClientTest.java
- https://github.com/jersey/jersey/blob/2.x/core-client/src/test/java/org/glassfish/jersey/client/ClientRxTest.java#L86

The last link is to the Jersey repository. Jersey version 2.26 will be JAX-RS 2.1 RI and branch 2.x is where the development will happen. Jersey 2.26-b01 (which is being released right now) implements all rx(...) methods; feel free to test/evaluate it there.

Looking forward to your feedback!

Thanks and regards,
Pavel