Add files via upload

This commit is contained in:
k0l0ssus 2018-08-10 08:24:46 -04:00 committed by GitHub
parent 2b53d29985
commit 2b229332b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 73 deletions

View File

@ -40,7 +40,7 @@
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22</version>
<version>2.25</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>

View File

@ -1,7 +1,6 @@
package com.baeldung.samples.jerseyrx;
import io.reactivex.Flowable;
import io.reactivex.disposables.Disposable;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@ -29,26 +28,20 @@ import rx.Observable;
public class ClientOrchestration {
Client client = ClientBuilder.newClient();
WebTarget userIdService = client.target("http://localhost:8080/serviceA/id");
WebTarget nameService = client.target("http://localhost:8080/serviceA/{empId}/name");
WebTarget hashService = client.target("http://localhost:8080/serviceA/{comboIDandName}/hash");
LinkedList<Throwable> failures = new LinkedList<>();
Logger logger = Logger.getLogger("ClientOrchestrator");
public static void main(String[] args) {
ClientOrchestration orchestrator = new ClientOrchestration();
orchestrator.callBackOrchestrate();
orchestrator.rxOrchestrate();
orchestrator.observableJavaOrchestrate();
orchestrator.flowableJavaOrchestrate();
}
public void callBackOrchestrate() {
logger.info("Orchestrating with the pyramid of doom");
userIdService.request().accept(MediaType.APPLICATION_JSON)
userIdService.request()
.accept(MediaType.APPLICATION_JSON)
.async()
.get(new InvocationCallback<EmployeeDTO>() {
@Override
@ -152,13 +145,13 @@ public class ClientOrchestration {
public void observableJavaOrchestrate() {
logger.info("Orchestrating with Observables");
Observable<EmployeeDTO> userIdObservable = userIdService.register(RxObservableInvokerProvider.class).request()
Observable<EmployeeDTO> observableUserIdService = userIdService.register(RxObservableInvokerProvider.class).request()
.accept(MediaType.APPLICATION_JSON)
.rx(RxObservableInvoker.class)
.get(new GenericType<EmployeeDTO>() {
});
}).asObservable();
userIdObservable.subscribe((EmployeeDTO empIdList) -> {
observableUserIdService.subscribe((EmployeeDTO empIdList) -> {
logger.info("[Observable] Got all the IDs " + empIdList.getEmpIds());
Observable.from(empIdList.getEmpIds()).subscribe(id
-> nameService.register(RxObservableInvokerProvider.class)
@ -171,8 +164,7 @@ public class ClientOrchestration {
failures.add(throwable);
logger.log(Level.WARNING, " [Observable] An error has occurred in the username request step {0}", throwable.getMessage());
})
.subscribe(userName -> hashService
.register(RxObservableInvokerProvider.class)
.subscribe(userName -> hashService.register(RxObservableInvokerProvider.class)
.resolveTemplate("comboIDandName", userName + id)
.request()
.rx(RxObservableInvoker.class)
@ -189,16 +181,16 @@ public class ClientOrchestration {
public void flowableJavaOrchestrate() {
logger.info("Orchestrating with Flowable");
Flowable<EmployeeDTO> userIdObservable = userIdService.register(RxFlowableInvokerProvider.class)
Flowable<EmployeeDTO> userIdFlowable = userIdService.register(RxFlowableInvokerProvider.class)
.request()
.rx(RxFlowableInvoker.class)
.get(new GenericType<EmployeeDTO>() {
});
Disposable subscribe = userIdObservable.subscribe((EmployeeDTO dto) -> {
userIdFlowable.subscribe((EmployeeDTO dto) -> {
logger.info("Orchestrating with Flowable");
List<Long> listOfIds = dto.getEmpIds();
Observable.from(listOfIds).map(id
Flowable.just(listOfIds).subscribe(id
-> nameService.register(RxFlowableInvokerProvider.class)
.resolveTemplate("empId", id)
.request()

View File

@ -1,6 +1,7 @@
package com.baeldung.samples.jerseyrx;
import java.util.List;
import java.util.Objects;
/**
*
@ -18,4 +19,36 @@ public class EmployeeDTO {
this.empIds = empIds;
}
@Override
public int hashCode() {
int hash = 5;
hash = 59 * hash + Objects.hashCode(this.empIds);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final EmployeeDTO other = (EmployeeDTO) obj;
if (!Objects.equals(this.empIds, other.empIds)) {
return false;
}
return true;
}
@Override
public String toString() {
return "EmployeeDTO{" + "empIds=" + empIds + '}';
}
}

View File

@ -1,15 +1,18 @@
package com.baeldung.samples.jerseyrx;
import com.github.tomakehurst.wiremock.WireMockServer;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import junit.framework.Assert;
import org.junit.After;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import java.util.LinkedList;
import java.util.logging.Logger;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import static junit.framework.Assert.assertTrue;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
/**
@ -18,6 +21,16 @@ import org.junit.Test;
*/
public class ClientOrchestrationTest {
Client client = ClientBuilder.newClient();
WebTarget userIdService = client.target("http://localhost:8080/serviceA/id");
WebTarget nameService = client.target("http://localhost:8080/serviceA/{empId}/name");
WebTarget hashService = client.target("http://localhost:8080/serviceA/{comboIDandName}/hash");
LinkedList<Throwable> failures = new LinkedList<>();
Logger logger = Logger.getLogger("ClientOrchestrator");
ClientOrchestration orchestrator = new ClientOrchestration();
String jsonIdList = "{\"empIds\":[1,2,3,4,5,6]}";
@ -26,12 +39,12 @@ public class ClientOrchestrationTest {
String[] hashResultList = new String[]{"roht1", "kluh2", "WodiwKcalb3", "RehtnapKclab4", "kciteht5", "eyekwah6"};
WireMockServer wireMockServer = new WireMockServer();
@Rule
public WireMockRule wireMockServer = new WireMockRule();
@Before
public void setup() {
wireMockServer.start();
configureFor("localhost", 8080);
stubFor(get(urlEqualTo("/serviceA/id")).willReturn(aResponse().withBody(jsonIdList).withHeader("Content-Type", "application/json")));
stubFor(get(urlEqualTo("/serviceA/1/name")).willReturn(aResponse().withBody(nameList[1])));
@ -58,12 +71,8 @@ public class ClientOrchestrationTest {
orchestrator.observableJavaOrchestrate();
orchestrator.flowableJavaOrchestrate();
Assert.assertTrue(orchestrator.failures.isEmpty());
assertTrue(orchestrator.failures.isEmpty());
}
@After
public void tearDown() {
}
}