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

The following examples show how to use org.glassfish.jersey.client.rx.rxjava.RxObservableInvokerProvider. 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: RxJerseyClientFeature.java    From rx-jersey with MIT License 5 votes vote down vote up
private Client createClient() {
    int cores = Runtime.getRuntime().availableProcessors();
    ClientConfig config = new ClientConfig();
    config.connectorProvider(new GrizzlyConnectorProvider());
    config.property(ClientProperties.ASYNC_THREADPOOL_SIZE, cores);
    config.register(RxObservableInvokerProvider.class);

    return ClientBuilder.newClient(config);
}
 
Example #3
Source File: RxJava2HttpBinService.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 4 votes vote down vote up
public RxJava2HttpBinService() {
	this.client = ClientBuilder.newClient();
	this.client.register(RxObservableInvokerProvider.class);
	this.client.register(RxFlowableInvokerProvider.class);
}
 
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);
}