Search in sources :

Example 6 with AgentResponse

use of org.glassfish.jersey.examples.rx.domain.AgentResponse in project jersey by jersey.

the class RxClientsTest method testRxFlowableClient.

@Test
public void testRxFlowableClient() throws Exception {
    // warmup
    target("agent").path("flowable").request().get();
    final Response response = target("agent").path("flowable").request().get();
    response.bufferEntity();
    final AgentResponse agentResponse = response.readEntity(AgentResponse.class);
    assertThat(agentResponse.getVisited().size(), is(5));
    assertThat(agentResponse.getRecommended().size(), is(5));
    assertThat(agentResponse.getProcessingTime() > 850, is(true));
    assertThat(agentResponse.getProcessingTime() < 4500, is(true));
    System.out.println(response.readEntity(String.class));
    System.out.println("Processing Time: " + agentResponse.getProcessingTime());
}
Also used : Response(javax.ws.rs.core.Response) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 7 with AgentResponse

use of org.glassfish.jersey.examples.rx.domain.AgentResponse in project jersey by jersey.

the class RxClientsTest method testRxObservableClient.

@Test
public void testRxObservableClient() throws Exception {
    // warmup
    target("agent").path("observable").request().get();
    final Response response = target("agent").path("observable").request().get();
    response.bufferEntity();
    final AgentResponse agentResponse = response.readEntity(AgentResponse.class);
    assertThat(agentResponse.getVisited().size(), is(5));
    assertThat(agentResponse.getRecommended().size(), is(5));
    assertThat(agentResponse.getProcessingTime() > 850, is(true));
    assertThat(agentResponse.getProcessingTime() < 4500, is(true));
    System.out.println(response.readEntity(String.class));
    System.out.println("Processing Time: " + agentResponse.getProcessingTime());
}
Also used : Response(javax.ws.rs.core.Response) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 8 with AgentResponse

use of org.glassfish.jersey.examples.rx.domain.AgentResponse in project jersey by jersey.

the class RxClientsTest method testSyncClient.

@Test
public void testSyncClient() throws Exception {
    // warmup
    target("agent").path("sync").request().get();
    final Response response = target("agent").path("sync").request().get();
    response.bufferEntity();
    final AgentResponse agentResponse = response.readEntity(AgentResponse.class);
    assertThat(agentResponse.getVisited().size(), is(5));
    assertThat(agentResponse.getRecommended().size(), is(5));
    assertThat(agentResponse.getProcessingTime() > 4500, is(true));
    System.out.println(response.readEntity(String.class));
    System.out.println("Processing Time: " + agentResponse.getProcessingTime());
}
Also used : Response(javax.ws.rs.core.Response) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 9 with AgentResponse

use of org.glassfish.jersey.examples.rx.domain.AgentResponse in project jersey by jersey.

the class RxClientsTest method testRxCompletionStageClient.

@Test
public void testRxCompletionStageClient() throws Exception {
    // warmup
    target("agent").path("completion").request().get();
    final Response response = target("agent").path("completion").request().get();
    response.bufferEntity();
    final AgentResponse agentResponse = response.readEntity(AgentResponse.class);
    assertThat(agentResponse.getVisited().size(), is(5));
    assertThat(agentResponse.getRecommended().size(), is(5));
    assertThat(agentResponse.getProcessingTime() > 850, is(true));
    assertThat(agentResponse.getProcessingTime() < 4500, is(true));
    System.out.println(response.readEntity(String.class));
    System.out.println("Processing Time: " + agentResponse.getProcessingTime());
}
Also used : Response(javax.ws.rs.core.Response) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 10 with AgentResponse

use of org.glassfish.jersey.examples.rx.domain.AgentResponse in project jersey by jersey.

the class FlowableAgentResource method flowable.

@GET
public void flowable(@Suspended final AsyncResponse async) {
    final long time = System.nanoTime();
    final Queue<String> errors = new ConcurrentLinkedQueue<>();
    Flowable.just(new AgentResponse()).zipWith(visited(errors), (agentResponse, visited) -> {
        agentResponse.setVisited(visited);
        return agentResponse;
    }).zipWith(recommended(errors), (agentResponse, recommendations) -> {
        agentResponse.setRecommended(recommendations);
        return agentResponse;
    }).observeOn(Schedulers.io()).subscribe(agentResponse -> {
        agentResponse.setProcessingTime((System.nanoTime() - time) / 1000000);
        async.resume(agentResponse);
    }, async::resume);
}
Also used : Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AsyncResponse(javax.ws.rs.container.AsyncResponse) Path(javax.ws.rs.Path) Singleton(javax.inject.Singleton) Suspended(javax.ws.rs.container.Suspended) Calculation(org.glassfish.jersey.examples.rx.domain.Calculation) Uri(org.glassfish.jersey.server.Uri) Destination(org.glassfish.jersey.examples.rx.domain.Destination) GenericType(javax.ws.rs.core.GenericType) Forecast(org.glassfish.jersey.examples.rx.domain.Forecast) List(java.util.List) Flowable(io.reactivex.Flowable) Recommendation(org.glassfish.jersey.examples.rx.domain.Recommendation) Schedulers(io.reactivex.schedulers.Schedulers) Queue(java.util.Queue) WebTarget(javax.ws.rs.client.WebTarget) RxFlowableInvoker(org.glassfish.jersey.client.rx.rxjava2.RxFlowableInvoker) RxFlowableInvokerProvider(org.glassfish.jersey.client.rx.rxjava2.RxFlowableInvokerProvider) Collections(java.util.Collections) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) GET(javax.ws.rs.GET)

Aggregations

AgentResponse (org.glassfish.jersey.examples.rx.domain.AgentResponse)11 GET (javax.ws.rs.GET)6 List (java.util.List)5 Response (javax.ws.rs.core.Response)5 Calculation (org.glassfish.jersey.examples.rx.domain.Calculation)5 Destination (org.glassfish.jersey.examples.rx.domain.Destination)5 Forecast (org.glassfish.jersey.examples.rx.domain.Forecast)5 Recommendation (org.glassfish.jersey.examples.rx.domain.Recommendation)5 JerseyTest (org.glassfish.jersey.test.JerseyTest)5 Test (org.junit.Test)5 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)4 GenericType (javax.ws.rs.core.GenericType)4 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WebTarget (javax.ws.rs.client.WebTarget)3 AsyncResponse (javax.ws.rs.container.AsyncResponse)3 Suspended (javax.ws.rs.container.Suspended)3 ManagedAsync (org.glassfish.jersey.server.ManagedAsync)3 Uri (org.glassfish.jersey.server.Uri)3 ArrayList (java.util.ArrayList)2