}
org.apache.axis2.context.MessageContext axisRequestMsgCtx = request.getAxisMessageContext();
org.apache.axis2.context.MessageContext axisResponseMsgCtx = null;
MessageContext response = null;
AxisFault faultexception =
null; // don't let the keyword "fault" confuse you. This is an exception class.
try {
execute(opClient, true, axisRequestMsgCtx);
} catch (AxisFault af) {
// If an AxisFault was thrown, we need to cleanup the original OperationContext.
// Failure to do so results in a memory leak.
opClient.getOperationContext().cleanup();
// save the fault in case it didn't come from the endpoint, and thus
// there would be no message on the MessageContext
faultexception = af;
if (log.isDebugEnabled()) {
log.debug(axisRequestMsgCtx.getLogIDString() + " AxisFault received from client: " +
af.getMessage());
}
}
try {
// Collect the response MessageContext and envelope
axisResponseMsgCtx = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
response = new MessageContext(axisResponseMsgCtx);
response.setMEPContext(request.getMEPContext());
// If there was a local exception caught and either there is no response message
// OR the response message exists but is not a fault, then set the local exception
// on the response and determine how to set the response message to correspond to
// the local exception
if ((faultexception != null) && ((response.getMessage() == null)
|| (!response.getMessage().isFault()))) {
// Unless this behavior is disabled, convert the local exception to SOAPFaultException
// and set it on the response message. This will also cause the JAX-WS application handler
// handleFault() methods to be called.
if (!isSOAPFaultForLocalExceptionDisabled(response)) {
HandlerChainProcessor.convertToFaultMessage(request.getMEPContext(), faultexception,
request.getMessage().getProtocol());
response.setLocalException(faultexception);
} else {
// The behavior was disabled, so instead of creating a SOAPFaultException
// just create an empty message and set the local exception on it. This will cause the
// JAX-WS application handler handleMessage() methods to be called with the empty message.
MessageFactory factory =
(MessageFactory)FactoryRegistry.getFactory(MessageFactory.class);
Message message = factory.create(request.getMessage().getProtocol());
response.setLocalException(faultexception);
response.setMessage(message);
}
}
// This assumes that we are on the ultimate execution thread
ThreadContextMigratorUtil.performMigrationToThread(