}
public void onAxisMessageExchange(MessageContext msgContext, MessageContext outMsgContext, SOAPFactory soapFactory)
throws AxisFault {
boolean success = true;
MyRoleMessageExchange odeMex = null;
Future responseFuture = null;
try {
_txManager.begin();
if (__log.isDebugEnabled()) __log.debug("Starting transaction.");
// Creating message exchange
String messageId = new GUID().toString();
odeMex = _server.getEngine().createMessageExchange("" + messageId, _serviceName,
msgContext.getAxisOperation().getName().getLocalPart());
__log.debug("ODE routed to operation " + odeMex.getOperation() + " from service " + _serviceName);
odeMex.setProperty("isTwoWay", Boolean.toString(msgContext.getAxisOperation() instanceof TwoChannelAxisOperation));
if (odeMex.getOperation() != null) {
// Preparing message to send to ODE
Message odeRequest = odeMex.createMessage(odeMex.getOperation().getInput().getMessage().getQName());
_converter.parseSoapRequest(odeRequest, msgContext.getEnvelope(), odeMex.getOperation());
readHeader(msgContext, odeMex);
if (__log.isDebugEnabled()) {
__log.debug("Invoking ODE using MEX " + odeMex);
__log.debug("Message content: " + DOMUtils.domToString(odeRequest.getMessage()));
}
// Invoke ODE
responseFuture = odeMex.invoke(odeRequest);
__log.debug("Commiting ODE MEX " + odeMex);
try {
if (__log.isDebugEnabled()) __log.debug("Commiting transaction.");
_txManager.commit();
} catch (Exception e) {
__log.error("Commit failed", e);
success = false;
}
} else {
success = false;
}
} catch (Exception e) {
__log.error("Exception occured while invoking ODE", e);
success = false;
String message = e.getMessage();
if (message == null) {
message = "An exception occured while invoking ODE.";
}
throw new OdeFault(message, e);
} finally {
if (!success) {
if (odeMex != null) odeMex.release(success);
try {
_txManager.rollback();
} catch (Exception e) {
throw new OdeFault("Rollback failed", e);
}
}
}
if (odeMex.getOperation().getOutput() != null) {
// Waits for the response to arrive
try {
responseFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
} catch (Exception e) {
String errorMsg = "Timeout or execution error when waiting for response to MEX "
+ odeMex + " " + e.toString();
__log.error(errorMsg, e);
throw new OdeFault(errorMsg);
}
if (outMsgContext != null) {
SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
outMsgContext.setEnvelope(envelope);
// Hopefully we have a response
__log.debug("Handling response for MEX " + odeMex);
boolean commit = false;
try {
if (__log.isDebugEnabled()) __log.debug("Starting transaction.");
_txManager.begin();
} catch (Exception ex) {
throw new OdeFault("Error starting transaction!", ex);
}
try {
// Refreshing the message exchange
odeMex = (MyRoleMessageExchange) _server.getEngine().getMessageExchange(odeMex.getMessageExchangeId());
onResponse(odeMex, outMsgContext);
commit = true;
} catch (AxisFault af) {
__log.warn("MEX produced a fault " + odeMex, af);
commit = true;
throw af;
} catch (Exception e) {
__log.error("Error processing response for MEX " + odeMex, e);
throw new OdeFault("An exception occured when invoking ODE.", e);
} finally {
odeMex.release(commit);
if (commit) {
try {
if (__log.isDebugEnabled()) __log.debug("Comitting transaction.");
_txManager.commit();
} catch (Exception e) {
throw new OdeFault("Commit failed!", e);
}
} else {
try {
_txManager.rollback();
} catch (Exception ex) {
throw new OdeFault("Rollback failed!", ex);
}
}
}
}
if (!success) {
throw new OdeFault("Message was either unroutable or timed out!");
}
} else {
// One ways cleanup
odeMex.release(true);
}
}