axis2Request.setCompleted(true);
if (errorCode == -1 && errorMessage == null && exceptionToRaise == null) {
return; // no need to continue
}
final MessageContext mc = axis2Request.getMsgContext();
// if the request message is a sandesha messag we ignore the
// exception handling
// we cannot use the declared sandesha2 constant since
// nhttp transport shouldn't take a sandesha2 dependency
String done = (String) mc.getProperty("Sandesha2AppProcessingDone");
if (JavaUtils.isTrueExplicitly(done)) {
return;
}
if (mc.getAxisOperation() != null &&
mc.getAxisOperation().getMessageReceiver() != null) {
if (metrics != null) {
if (metrics.getLevel() == MetricsCollector.LEVEL_FULL) {
if (errorCode == NhttpConstants.CONNECTION_TIMEOUT) {
metrics.incrementTimeoutsReceiving(mc);
} else {
metrics.incrementFaultsSending(errorCode, mc);
}
} else {
if (errorCode == NhttpConstants.CONNECTION_TIMEOUT) {
metrics.incrementTimeoutsReceiving();
} else {
metrics.incrementFaultsSending();
}
}
}
workerPool.execute( new Runnable() {
public void run() {
MessageReceiver mr = mc.getAxisOperation().getMessageReceiver();
try {
// This AxisFault is created to create the fault message context
// noinspection ThrowableInstanceNeverThrown
AxisFault axisFault = exceptionToRaise != null ?
new AxisFault(errorMessage, exceptionToRaise) :
new AxisFault(errorMessage);
MessageContext nioFaultMessageContext =
MessageContextBuilder.createFaultMessageContext(mc, axisFault);
SOAPEnvelope envelope = nioFaultMessageContext.getEnvelope();
if (log.isDebugEnabled()) {
log.debug("Sending Fault for Request with Message ID : "
+ mc.getMessageID());
}
nioFaultMessageContext.setProperty(
NhttpConstants.SENDING_FAULT, Boolean.TRUE);
nioFaultMessageContext.setProperty(
NhttpConstants.ERROR_MESSAGE, errorMessage);
if (errorCode != -1) {
nioFaultMessageContext.setProperty(
NhttpConstants.ERROR_CODE, errorCode);
}
if (exceptionToRaise != null) {
nioFaultMessageContext.setProperty(
NhttpConstants.ERROR_DETAIL, exceptionToRaise.toString());
nioFaultMessageContext.setProperty(
NhttpConstants.ERROR_EXCEPTION, exceptionToRaise);
envelope.getBody().getFault().getDetail().setText(
exceptionToRaise.toString());
} else {
nioFaultMessageContext.setProperty(
NhttpConstants.ERROR_DETAIL, errorMessage);
envelope.getBody().getFault().getDetail().setText(errorMessage);
}
nioFaultMessageContext.setProperty(CLIENT_CONNECTION_DEBUG,
mc.getProperty(CLIENT_CONNECTION_DEBUG));
mr.receive(nioFaultMessageContext);
} catch (AxisFault af) {
log.error("Unable to report back failure to the message receiver", af);