public Object invoke(Exchange exchange, Object request) {
Response response = exchange.get(Response.class);
if (response == null) {
AsyncResponse asyncResp = exchange.get(AsyncResponse.class);
if (asyncResp != null) {
AsyncResponseImpl asyncImpl = (AsyncResponseImpl)asyncResp;
if (asyncImpl.isResumedByApplication()) {
Object asyncObj = asyncImpl.getResponseObject();
if (asyncObj instanceof Throwable) {
return handleFault(new Fault((Throwable)asyncObj),
exchange.getInMessage(), null, null);
} else if (!(asyncObj instanceof Response)) {
response = Response.ok().entity(asyncObj).build();
} else {
response = (Response)asyncObj;
}
} else if (asyncImpl.handleTimeout()) {
return null;
} else {
return handleFault(new Fault(new WebApplicationException(503)),
exchange.getInMessage(), null, null);
}