org.glassfish.jersey.client.rx.rxjava.RxObservableInvoker Java Examples

The following examples show how to use org.glassfish.jersey.client.rx.rxjava.RxObservableInvoker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObservableClient.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
public final static void main(String[] args) throws Exception {
    Client client = ClientBuilder.newClient();
    
    client.register(RxObservableInvokerProvider.class);
    WebTarget target = client.target("http://localhost:8080/jaxrs-async/rest/ejb");

    target.request()
            .rx(RxObservableInvoker.class)
            .get(String.class)
            .subscribe(new Observer<String>() {
                @Override
                public void onCompleted() {
                    System.out.println("onCompleted");
                }

                @Override
                public void onError(Throwable e) {
                    System.out.println("onError:" + e.getMessage());
                }

                @Override
                public void onNext(String t) {
                    System.out.println("onNext:" + t);
                }
            });

}
 
Example #2
Source File: ObservableClientMethodInvoker.java    From rx-jersey with MIT License 4 votes vote down vote up
@Override
public <T> Object method(Invocation.Builder builder, String name, GenericType<T> responseType) {
    Observable<T> observable = builder.rx(RxObservableInvoker.class).method(name, responseType);
    return convert(observable, responseType);
}
 
Example #3
Source File: ObservableClientMethodInvoker.java    From rx-jersey with MIT License 4 votes vote down vote up
@Override
public <T> Object method(Invocation.Builder builder, String name, Entity<?> entity, GenericType<T> responseType) {
    Observable<T> observable = builder.rx(RxObservableInvoker.class).method(name, entity, responseType);
    return convert(observable, responseType);
}
 
Example #4
Source File: ClientOrchestrationIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void observableJavaOrchestrate() throws InterruptedException {
    List<String> receivedHashValues = new ArrayList<>();

    final CountDownLatch completionTracker = new CountDownLatch(expectedHashValues.size()); // used to keep track of the progress of the subsequent calls

    Observable<List<Long>> observableUserIdService = getUserIdService().register(RxObservableInvokerProvider.class).request().accept(MediaType.APPLICATION_JSON).rx(RxObservableInvoker.class).get(new GenericType<List<Long>>() {
    }).asObservable();

    observableUserIdService.subscribe((List<Long> employeeIds) -> {
        logger.info("[ObservableExample] id-service result: {}", employeeIds);
        Observable.from(employeeIds).subscribe(id -> getNameService().register(RxObservableInvokerProvider.class).resolveTemplate("userId", id).request().rx(RxObservableInvoker.class).get(String.class).asObservable() // gotten the name for the given
                // userId
                .doOnError((throwable) -> {
                    logger.warn("[ObservableExample] An error has occurred in the username request step {}", throwable.getMessage());
                }).subscribe(userName -> {
                    logger.info("[ObservableExample] name-service result: {}", userName);
                    getHashService().register(RxObservableInvokerProvider.class).resolveTemplate("rawValue", userName + id).request().rx(RxObservableInvoker.class).get(String.class).asObservable() // gotten the hash value for
                            // userId+username
                            .doOnError((throwable) -> {
                                logger.warn("[ObservableExample] An error has occurred in the hashing request step {}", throwable.getMessage());
                            }).subscribe(hashValue -> {
                        logger.info("[ObservableExample] hash-service result: {}", hashValue);
                        receivedHashValues.add(hashValue);
                        completionTracker.countDown();
                    });
                }));
    });

    // wait for async calls to complete
    try {
        // wait for inner requests to complete in 10 seconds
        if (!completionTracker.await(10, TimeUnit.SECONDS)) {
            logger.warn("[CallbackExample] Some requests didn't complete within the timeout");
        }
    } catch (InterruptedException e) {
        logger.error("Interrupted!", e);
    }

    assertThat(receivedHashValues).containsAll(expectedHashValues);
}