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();
}
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());
}
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());
}
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));
}
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());
}
Aggregations