diff --git a/jersey-client-rx/pom.xml b/jersey-client-rx/pom.xml index 3857c16730..cc5f28c938 100644 --- a/jersey-client-rx/pom.xml +++ b/jersey-client-rx/pom.xml @@ -6,6 +6,11 @@ 1.0 jar + + org.glassfish.jersey.inject + jersey-hk2 + 2.27 + org.glassfish.jersey.core jersey-client diff --git a/jersey-client-rx/src/main/java/com/baeldung/samples/jerseyrx/ClientOrchestration.java b/jersey-client-rx/src/main/java/com/baeldung/samples/jerseyrx/ClientOrchestration.java index 4adf5e50b8..d3e6986b39 100644 --- a/jersey-client-rx/src/main/java/com/baeldung/samples/jerseyrx/ClientOrchestration.java +++ b/jersey-client-rx/src/main/java/com/baeldung/samples/jerseyrx/ClientOrchestration.java @@ -28,9 +28,9 @@ import rx.Observable; public class ClientOrchestration { Client client = ClientBuilder.newClient(); - WebTarget userIdService = client.target("http:localhost:8080/serviceA/id?limit=10"); - WebTarget nameService = client.target("http:localhost:8080/serviceA/{empId}/name"); - WebTarget hashService = client.target("http:localhost:8080/serviceA/{comboIDandName}/address"); + WebTarget userIdService = client.target("http://localhost:8080/serviceA/id?limit=10"); + WebTarget nameService = client.target("http://localhost:8080/serviceA/{empId}/name"); + WebTarget hashService = client.target("http://localhost:8080/serviceA/{comboIDandName}/address"); Logger logger = Logger.getLogger("ClientOrchestrator"); @@ -73,6 +73,7 @@ public class ClientOrchestration { } }); } + @Override public void failed(Throwable throwable) { completionTracker.countDown(); @@ -80,7 +81,7 @@ public class ClientOrchestration { } }); }); - + try { if (!completionTracker.await(10, TimeUnit.SECONDS)) { //wait for inner requests to complete in 10 seconds logger.warning("Some requests didn't complete within the timeout"); @@ -88,7 +89,7 @@ public class ClientOrchestration { } catch (InterruptedException ex) { Logger.getLogger(ClientOrchestration.class.getName()).log(Level.SEVERE, null, ex); } - + } @Override @@ -109,12 +110,8 @@ public class ClientOrchestration { return null; }); - CompletionStage>> completedNameStage = userIdStage.thenApplyAsync(list -> list.stream().map((Long id) -> { - CompletionStage nameStage = nameService.resolveTemplate("empId", id).request().rx().get(String.class); - }).collect(Collectors.toList())); - userIdStage.thenAcceptAsync(listOfIds -> { - listOfIds.stream().map((Long id) -> { + listOfIds.stream().forEach((Long id) -> { CompletableFuture completable = nameService.resolveTemplate("empId", id) .request() .rx() @@ -143,10 +140,7 @@ public class ClientOrchestration { public void observableJavaOrchestrate() { logger.info("Orchestrating with Observables"); - - client.register(RxObservableInvokerProvider.class); - - Observable> userIdObservable = userIdService.request() + Observable> userIdObservable = userIdService.register(RxObservableInvokerProvider.class).request() .rx(RxObservableInvoker.class) .get(new GenericType>() { }); @@ -173,10 +167,7 @@ public class ClientOrchestration { public void flowableJavaOrchestrate() { logger.info("Orchestrating with Flowable"); - - client.register(RxFlowableInvokerProvider.class); - - Flowable> userIdObservable = userIdService.request() + Flowable> userIdObservable = userIdService.register(RxFlowableInvokerProvider.class).request() .rx(RxFlowableInvoker.class) .get(new GenericType>() { });