use of javax.ws.rs.core.GenericType in project opennms by OpenNMS.
the class DefaultRemoteRepository method getOnlineReports.
/**
* {@inheritDoc}
*/
@Override
public List<BasicReportDefinition> getOnlineReports() {
List<BasicReportDefinition> resultReports = new ArrayList<>();
List<RemoteReportSDO> webCallResult = new ArrayList<>();
if (isConfigOk()) {
WebTarget target = getTarget(m_remoteRepositoryDefintion.getURI() + "onlineReports" + "/" + m_jasperReportsVersion);
try {
webCallResult = getBuilder(target).get(new GenericType<List<RemoteReportSDO>>() {
});
} catch (Exception e) {
logger.error("Error requesting online reports. Error message: '{}' URI was: '{}'", e.getMessage(), target.getUri());
e.printStackTrace();
}
logger.debug("getOnlineReports got '{}' RemoteReportSDOs from uri '{}'", webCallResult.size(), target.getUri());
resultReports = this.mapSDOListToBasicReportList(webCallResult);
}
return resultReports;
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class JerseyInvocation method submit.
/**
* Submit the request for an asynchronous invocation and register an
* {@link InvocationCallback} to process the future result of the invocation.
* <p>
* Response type in this case is taken from {@code responseType} param (if not {@code null}) rather
* than from {@code callback}. This allows to pass callbacks like {@code new InvocationCallback<>() {...}}.
* </p>
*
* @param <T> response type
* @param responseType response type that is used instead of obtaining types from {@code callback}.
* @param callback invocation callback for asynchronous processing of the
* request invocation result.
* @return future response object of the specified type as a result of the
* request invocation.
*/
public <T> Future<T> submit(final GenericType<T> responseType, final InvocationCallback<T> callback) {
final CompletableFuture<T> responseFuture = new CompletableFuture<>();
try {
final ReflectionHelper.DeclaringClassInterfacePair pair = ReflectionHelper.getClass(callback.getClass(), InvocationCallback.class);
final Type callbackParamType;
final Class<T> callbackParamClass;
if (responseType == null) {
// If we don't have response use callback to obtain param types.
final Type[] typeArguments = ReflectionHelper.getParameterizedTypeArguments(pair);
if (typeArguments == null || typeArguments.length == 0) {
callbackParamType = Object.class;
} else {
callbackParamType = typeArguments[0];
}
callbackParamClass = ReflectionHelper.erasure(callbackParamType);
} else {
callbackParamType = responseType.getType();
callbackParamClass = ReflectionHelper.erasure(responseType.getRawType());
}
final ResponseCallback responseCallback = new ResponseCallback() {
@Override
public void completed(final ClientResponse response, final RequestScope scope) {
if (responseFuture.isCancelled()) {
response.close();
failed(new ProcessingException(new CancellationException(LocalizationMessages.ERROR_REQUEST_CANCELLED())));
return;
}
final T result;
if (callbackParamClass == Response.class) {
result = callbackParamClass.cast(new InboundJaxrsResponse(response, scope));
responseFuture.complete(result);
callback.completed(result);
} else if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
result = response.readEntity(new GenericType<T>(callbackParamType));
responseFuture.complete(result);
callback.completed(result);
} else {
failed(convertToException(new InboundJaxrsResponse(response, scope)));
}
}
@Override
public void failed(final ProcessingException error) {
try {
if (error.getCause() instanceof WebApplicationException) {
responseFuture.completeExceptionally(error.getCause());
} else if (!responseFuture.isCancelled()) {
responseFuture.completeExceptionally(error);
}
} finally {
callback.failed(error.getCause() instanceof CancellationException ? error.getCause() : error);
}
}
};
request().getClientRuntime().submit(requestForCall(requestContext), responseCallback);
} catch (final Throwable error) {
final ProcessingException ce;
//noinspection ChainOfInstanceofChecks
if (error instanceof ProcessingException) {
ce = (ProcessingException) error;
responseFuture.completeExceptionally(ce);
} else if (error instanceof WebApplicationException) {
ce = new ProcessingException(error);
responseFuture.completeExceptionally(error);
} else {
ce = new ProcessingException(error);
responseFuture.completeExceptionally(ce);
}
callback.failed(ce);
}
return responseFuture;
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class ModelEntityOnListTest method myBeanAndGet.
@Test
public void myBeanAndGet() {
WebTarget target = target("empty/getbean");
final Response response = target.request(MediaType.APPLICATION_JSON).get();
assertEquals(200, response.getStatus());
GenericType<List<MyBean>> ge = new GenericType<List<MyBean>>() {
};
List<MyBean> teb = response.readEntity(ge);
assertEquals("one element in list: " + teb, 1, teb.size());
assertEquals("value", "hello", teb.get(0).getValue());
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class RxObservableTest method testReadEntityViaGenericType.
@Test
public void testReadEntityViaGenericType() throws Throwable {
final String response = client.target("http://jersey.java.net").request().rx(RxObservableInvoker.class).get(new GenericType<String>() {
}).toBlocking().toFuture().get();
assertThat(response, is("NO-ENTITY"));
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class RxFlowableTest method testReadEntityViaGenericType.
@Test
public void testReadEntityViaGenericType() throws Throwable {
final String response = client.target("http://jersey.java.net").request().rx(RxFlowableInvoker.class).get(new GenericType<String>() {
}).blockingFirst();
assertThat(response, is("NO-ENTITY"));
}
Aggregations