public void receive(MessageContext msgContext) throws AxisFault {
RelatesTo relatesTO = msgContext.getOptions().getRelatesTo();
if (relatesTO == null) {
throw new AxisFault("Cannot identify correct Callback object. RelatesTo is null");
}
String messageID = relatesTO.getValue();
Object callbackObj = callbackStore.remove(messageID);
if (log.isDebugEnabled()) log.debug("CallbackReceiver: receive found callback " + callbackObj + ", " + messageID + ", " + this + ", " + msgContext.getAxisOperation());
if (callbackObj == null) {
throw new AxisFault("The Callback for MessageID " + messageID + " was not found");
}
if (callbackObj instanceof AxisCallback) {
AxisCallback axisCallback = (AxisCallback)callbackObj;
if (msgContext.isFault()) {
axisCallback.onFault(msgContext);
} else {
axisCallback.onMessage(msgContext);
}
// Either way we're done.
axisCallback.onComplete();
return;
}
// THIS NEXT PART WILL EVENTUALLY GO AWAY WHEN Callback DOES
// OK, this must be an old-style Callback
Callback callback = (Callback)callbackObj;
AsyncResult result = new AsyncResult(msgContext);
// check whether the result is a fault.
try {
SOAPEnvelope envelope = result.getResponseEnvelope();
OperationContext opContext = msgContext.getOperationContext();
if (opContext != null && !opContext.isComplete()) {
opContext.addMessageContext(msgContext);
}
if (envelope.hasFault()) {
AxisFault axisFault =
Utils.getInboundFaultFromMessageContext(msgContext);
callback.onError(axisFault);
} else {
callback.onComplete(result);
}
} catch (Exception e) {
callback.onError(e);
} finally {
callback.setComplete(true);
}
}
|