@Override
public void completed(ClientResponse response, 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.set(result);
callback.completed(result);
} else if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
result = response.readEntity(new GenericType<T>(callbackParamType));
responseFuture.set(result);
callback.completed(result);
} else {
failed(convertToException(new InboundJaxrsResponse(response, scope)));
}
}
@Override
public void failed(ProcessingException error) {
try {
if (error.getCause() instanceof WebApplicationException) {
responseFuture.setException(error.getCause());
} else if (!responseFuture.isCancelled()) {
responseFuture.setException(error);
}
} finally {
callback.failed(error.getCause() instanceof CancellationException ? error.getCause() : error);
}
}
};
request().getClientRuntime().submit(requestContext, responseCallback);
} catch (Throwable error) {
ProcessingException ce;
if (error instanceof ProcessingException) {
ce = (ProcessingException) error;
responseFuture.setException(ce);
} else if (error instanceof WebApplicationException) {
ce = new ProcessingException(error);
responseFuture.setException(error);
} else {
ce = new ProcessingException(error);
responseFuture.setException(ce);
}
callback.failed(ce);
}