if (__log.isDebugEnabled()) {
__log.debug("Axis2 sending message to " + axisEPR.getAddress() + " using MEX " + odeMex);
__log.debug("Message: " + soapEnv);
}
final OperationClient operationClient = client.createClient(isTwoWay ? ServiceClient.ANON_OUT_IN_OP
: ServiceClient.ANON_OUT_ONLY_OP);
operationClient.addMessageContext(mctx);
// this Options can be alter without impacting the ServiceClient options (which is a requirement)
Options operationOptions = operationClient.getOptions();
// provide HTTP credentials if any
AuthenticationHelper.setHttpAuthentication(odeMex, operationOptions);
operationOptions.setAction(mctx.getSoapAction());
operationOptions.setTo(axisEPR);
if (isTwoWay) {
final String mexId = odeMex.getMessageExchangeId();
final Operation operation = odeMex.getOperation();
// Defer the invoke until the transaction commits.
_sched.registerSynchronizer(new Scheduler.Synchronizer() {
public void afterCompletion(boolean success) {
// If the TX is rolled back, then we don't send the request.
if (!success) return;
// The invocation must happen in a separate thread, holding on the afterCompletion
// blocks other operations that could have been listed there as well.
_executorService.submit(new Callable<Object>() {
public Object call() throws Exception {
try {
operationClient.execute(true);
MessageContext response = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
MessageContext flt = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_FAULT_VALUE);
if (response != null && __log.isDebugEnabled())
__log.debug("Service response:\n" + response.getEnvelope().toString());
if (flt != null) {
reply(mexId, operation, flt, true);
} else {
reply(mexId, operation, response, response.isFault());
}
} catch (Throwable t) {
String errmsg = "Error sending message (mex=" + odeMex + "): " + t.getMessage();
__log.error(errmsg, t);
replyWithFailure(mexId, MessageExchange.FailureType.COMMUNICATION_ERROR, errmsg);
} finally {
// release the HTTP connection, we don't need it anymore
TransportOutDescription out = mctx.getTransportOut();
if (out != null && out.getSender() != null) {
out.getSender().cleanup(mctx);
}
}
return null;
}
});
}
public void beforeCompletion() {
}
});
odeMex.replyAsync();
} else { /** one-way case * */
_executorService.submit(new Callable<Object>() {
public Object call() throws Exception {
try {
operationClient.execute(true);
} catch (Throwable t) {
String errmsg = "Error sending message (mex=" + odeMex + "): " + t.getMessage();
__log.error(errmsg, t);
} finally {
// release the HTTP connection, we don't need it anymore