Search in sources :

Example 71 with GenericType

use of javax.ws.rs.core.GenericType in project jersey by jersey.

the class ObservableAgentResource method recommended.

private Observable<List<Recommendation>> recommended(final Queue<String> errors) {
    destination.register(RxObservableInvokerProvider.class);
    // Recommended places.
    final Observable<Destination> recommended = destination.path("recommended").request().header("Rx-User", "RxJava").rx(RxObservableInvoker.class).get(new GenericType<List<Destination>>() {
    }).onErrorReturn(throwable -> {
        errors.offer("Recommended: " + throwable.getMessage());
        return Collections.emptyList();
    }).flatMap(Observable::from).cache();
    forecast.register(RxObservableInvokerProvider.class);
    // Forecasts. (depend on recommended destinations)
    final Observable<Forecast> forecasts = recommended.flatMap(destination -> forecast.resolveTemplate("destination", destination.getDestination()).request().rx(RxObservableInvoker.class).get(Forecast.class).onErrorReturn(throwable -> {
        errors.offer("Forecast: " + throwable.getMessage());
        return new Forecast(destination.getDestination(), "N/A");
    }));
    calculation.register(RxObservableInvokerProvider.class);
    // Calculations. (depend on recommended destinations)
    final Observable<Calculation> calculations = recommended.flatMap(destination -> calculation.resolveTemplate("from", "Moon").resolveTemplate("to", destination.getDestination()).request().rx(RxObservableInvoker.class).get(Calculation.class).onErrorReturn(throwable -> {
        errors.offer("Calculation: " + throwable.getMessage());
        return new Calculation("Moon", destination.getDestination(), -1);
    }));
    return Observable.zip(recommended, forecasts, calculations, Recommendation::new).toList();
}
Also used : Produces(javax.ws.rs.Produces) RxObservableInvokerProvider(org.glassfish.jersey.client.rx.rxjava.RxObservableInvokerProvider) GET(javax.ws.rs.GET) AsyncResponse(javax.ws.rs.container.AsyncResponse) RxObservableInvoker(org.glassfish.jersey.client.rx.rxjava.RxObservableInvoker) 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) Observable(rx.Observable) GenericType(javax.ws.rs.core.GenericType) Forecast(org.glassfish.jersey.examples.rx.domain.Forecast) List(java.util.List) Recommendation(org.glassfish.jersey.examples.rx.domain.Recommendation) Schedulers(rx.schedulers.Schedulers) Queue(java.util.Queue) WebTarget(javax.ws.rs.client.WebTarget) Collections(java.util.Collections) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Destination(org.glassfish.jersey.examples.rx.domain.Destination) GenericType(javax.ws.rs.core.GenericType) Forecast(org.glassfish.jersey.examples.rx.domain.Forecast) Calculation(org.glassfish.jersey.examples.rx.domain.Calculation) RxObservableInvoker(org.glassfish.jersey.client.rx.rxjava.RxObservableInvoker)

Example 72 with GenericType

use of javax.ws.rs.core.GenericType in project jersey by jersey.

the class JsonWithPaddingTest method testGetOnChangesJSONFormat.

/**
     * Test check GET on the "changes" resource in "application/json" format.
     */
@Test
public void testGetOnChangesJSONFormat() {
    WebTarget target = target();
    GenericType<List<ChangeRecordBean>> genericType = new GenericType<List<ChangeRecordBean>>() {
    };
    // get the initial representation
    List<ChangeRecordBean> changes = target.path("changes").request("application/json").get(genericType);
    // check that there are two changes entries
    assertEquals("Expected number of initial changes not found", 5, changes.size());
}
Also used : GenericType(javax.ws.rs.core.GenericType) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 73 with GenericType

use of javax.ws.rs.core.GenericType in project jersey by jersey.

the class BasicClientTest method testSyncClientInvocation.

@Test
public void testSyncClientInvocation() throws InterruptedException, ExecutionException {
    final WebTarget resource = target().path("resource");
    Response r1 = resource.request().post(text("post1"));
    assertEquals("post1", r1.readEntity(String.class));
    String r2 = resource.request().post(text("post2"), String.class);
    assertEquals("post2", r2);
    List<JaxbString> r3 = resource.request().get(new GenericType<List<JaxbString>>() {
    });
    assertEquals(Arrays.asList("a", "b", "c").toString(), r3.stream().map(input -> input.value).collect(Collectors.toList()).toString());
}
Also used : Response(javax.ws.rs.core.Response) Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ClientConfig(org.glassfish.jersey.client.ClientConfig) Assert.assertNotSame(org.junit.Assert.assertNotSame) Path(javax.ws.rs.Path) Client(javax.ws.rs.client.Client) CompletableFuture(java.util.concurrent.CompletableFuture) Application(javax.ws.rs.core.Application) ClientRequestFilter(javax.ws.rs.client.ClientRequestFilter) AsyncInvoker(javax.ws.rs.client.AsyncInvoker) ClientBuilder(javax.ws.rs.client.ClientBuilder) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) JerseyTest(org.glassfish.jersey.test.JerseyTest) InvocationCallback(javax.ws.rs.client.InvocationCallback) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Assert.fail(org.junit.Assert.fail) WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) POST(javax.ws.rs.POST) ClientRequestContext(javax.ws.rs.client.ClientRequestContext) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Invocation(javax.ws.rs.client.Invocation) ThreadPoolExecutorProvider(org.glassfish.jersey.spi.ThreadPoolExecutorProvider) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Collectors(java.util.stream.Collectors) Entity.text(javax.ws.rs.client.Entity.text) NotFoundException(javax.ws.rs.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) WriterInterceptorContext(javax.ws.rs.ext.WriterInterceptorContext) Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) WebTarget(javax.ws.rs.client.WebTarget) ClientAsyncExecutor(org.glassfish.jersey.client.ClientAsyncExecutor) Assert.assertEquals(org.junit.Assert.assertEquals) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 74 with GenericType

use of javax.ws.rs.core.GenericType in project jersey by jersey.

the class GenericResponseTest method testGet.

@Test
public void testGet() {
    GenericType<Response> generic = new GenericType<Response>(Response.class);
    WebTarget target = target("resource");
    SyncInvoker sync = target.request();
    Response response = sync.get(generic);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("get", response.readEntity(String.class));
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) SyncInvoker(javax.ws.rs.client.SyncInvoker) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 75 with GenericType

use of javax.ws.rs.core.GenericType in project jersey by jersey.

the class XmlJaxBElementProviderTest method _test.

private void _test(String path) {
    WebTarget target = target(path);
    final Response res = target.request("application/atom+xml").post(Entity.entity(new JAXBElement<String>(new QName("atom"), String.class, "value"), "application/atom+xml"));
    assertEquals(200, res.getStatus());
    final GenericType<JAXBElement<String>> genericType = new GenericType<JAXBElement<String>>() {
    };
    final JAXBElement<String> stringJAXBElement = res.readEntity(genericType);
    assertEquals("value", stringJAXBElement.getValue());
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) QName(javax.xml.namespace.QName) WebTarget(javax.ws.rs.client.WebTarget) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

GenericType (javax.ws.rs.core.GenericType)126 List (java.util.List)64 WebTarget (javax.ws.rs.client.WebTarget)64 Response (javax.ws.rs.core.Response)60 Test (org.junit.Test)51 Client (javax.ws.rs.client.Client)24 ArrayList (java.util.ArrayList)17 Message (com.remswork.project.alice.model.support.Message)16 WebClient (org.apache.cxf.jaxrs.client.WebClient)16 GenericEntity (javax.ws.rs.core.GenericEntity)15 MediaType (javax.ws.rs.core.MediaType)15 Collection (java.util.Collection)14 Set (java.util.Set)14 LinkedList (java.util.LinkedList)12 HashSet (java.util.HashSet)11 Test (org.junit.jupiter.api.Test)11 JerseyTest (org.glassfish.jersey.test.JerseyTest)10 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)9 Collections (java.util.Collections)9 Entity (javax.ws.rs.client.Entity)9