// we receive a CXF request when this method is called
public Object invoke(Exchange cxfExchange, Object o) {
if (LOG.isTraceEnabled()) {
LOG.trace("Received CXF Request: " + cxfExchange);
}
Continuation continuation;
if (!endpoint.isSynchronous() && (continuation = getContinuation(cxfExchange)) != null) {
if (LOG.isTraceEnabled()) {
LOG.trace("Calling the Camel async processors.");
}
return asyncInvoke(cxfExchange, continuation);
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("Calling the Camel sync processors.");
}
return syncInvoke(cxfExchange);
}
}
// NOTE this code cannot work with CXF 2.2.x
private Object asyncInvoke(Exchange cxfExchange, final Continuation continuation) {
synchronized (continuation) {
if (continuation.isNew()) {
final org.apache.camel.Exchange camelExchange = perpareCamelExchange(cxfExchange);
// Now we don't set up the timeout value
if (LOG.isTraceEnabled()) {
LOG.trace("Suspending continuation of exchangeId: " + camelExchange.getExchangeId());
}
// TODO Support to set the timeout in case the Camel can't send the response back on time.
// The continuation could be called before the suspend is called
continuation.suspend(0);
// use the asynchronous API to process the exchange
getAsyncProcessor().process(camelExchange, new AsyncCallback() {
public void done(boolean doneSync) {
// make sure the continuation resume will not be called before the suspend method in other thread
synchronized (continuation) {
if (LOG.isTraceEnabled()) {
LOG.trace("Resuming continuation of exchangeId: "
+ camelExchange.getExchangeId());
}
// resume processing after both, sync and async callbacks
continuation.setObject(camelExchange);
continuation.resume();
}
}
});
} else if (continuation.isResumed()) {
org.apache.camel.Exchange camelExchange = (org.apache.camel.Exchange)continuation
.getObject();
setResponseBack(cxfExchange, camelExchange);
}
}