private void reply(final String odeMexId, final Operation operation, final MessageContext reply, final boolean isFault) {
// ODE MEX needs to be invoked in a TX.
try {
_sched.execTransaction(new Callable<Void>() {
public Void call() throws Exception {
PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange) _server.getEngine().getMessageExchange(odeMexId);
// Setting the response
try {
if (__log.isDebugEnabled()) __log.debug("Received response for MEX " + odeMex);
if (isFault) {
Document odeMsg = DOMUtils.newDocument();
Element odeMsgEl = odeMsg.createElementNS(null, "message");
odeMsg.appendChild(odeMsgEl);
Fault fault = _converter.parseSoapFault(odeMsgEl, reply.getEnvelope(), operation);
if (fault != null) {
if (__log.isWarnEnabled())
__log.warn("Fault response: faultName=" + fault.getName() + " faultType=" + fault.getMessage().getQName() + "\n" + DOMUtils.domToString(odeMsgEl));
QName faultType = fault.getMessage().getQName();
QName faultName = new QName(_definition.getTargetNamespace(), fault.getName());
Message response = odeMex.createMessage(faultType);
response.setMessage(odeMsgEl);
odeMex.replyWithFault(faultName, response);
} else {
if (__log.isWarnEnabled())
__log.warn("Fault response: faultType=(unkown)\n" + reply.getEnvelope().toString());
final SOAPFaultReason r = reply.getEnvelope().getBody().getFault().getReason();
SOAPFault f = reply.getEnvelope().getBody().getFault();
String reason = r != null ? r.getText() : "Unspecified";
Element details = f != null ? OMUtils.toDOM(f) : null;
odeMex.replyWithFailure(FailureType.OTHER, reason, details);
}
} else {
Message response = odeMex.createMessage(odeMex.getOperation().getOutput().getMessage().getQName());
_converter.parseSoapResponse(response, reply.getEnvelope(), operation);
if (__log.isInfoEnabled()) __log.info("Response:\n" + (response.getMessage() != null ?
DOMUtils.domToString(response.getMessage()) : "empty"));
odeMex.reply(response);
}
} catch (Exception ex) {
String errmsg = "Unable to process response: " + ex.getMessage();
__log.error(errmsg, ex);
odeMex.replyWithFailure(FailureType.OTHER, errmsg, null);
}
return null;
}
});