* Creates the message processor chain in which we will delegate the process of mule events.
* The chain composes a string transformer, a CXF client proxy and and outbound endpoint.
*/
private MessageProcessor createMessageProcessor() throws MuleException
{
MessageProcessorChainBuilder chainBuilder = new DefaultMessageProcessorChainBuilder();
chainBuilder.chain(new AbstractInterceptingMessageProcessor()
{
@Override
public MuleEvent process(MuleEvent event) throws MuleException
{
try
{
/* If the requestBody variable is set, it will be used as the payload to send instead
* of the payload of the message. This will happen when an operation required no input parameters. */
if (requestBody != null)
{
event.getMessage().setPayload(requestBody);
}
copyAttachmentsRequest(event);
MuleEvent result = processNext(event);
copyAttachmentsResponse(result);
return result;
}
catch (DispatchException e)
{
/* When a Soap Fault is returned in the response, CXF raises a SoapFault exception.
* We need to wrap the information of this exception into a new exception of the WS consumer module */
if (e.getCause() instanceof SoapFault)
{
SoapFault soapFault = (SoapFault) e.getCause();
event.getMessage().setPayload(soapFault.getDetail());
throw new SoapFaultException(event, soapFault.getFaultCode(), soapFault.getSubCode(),
soapFault.getMessage(), soapFault.getDetail());
}
else
{
throw e;
}
}
}
});
// Add a message processor that removes the invocation property CxfConstants.OPERATION if present
// (as it may change the behavior of CXF proxy client). It is added again after executing the proxy client.
chainBuilder.chain(new AbstractInterceptingMessageProcessor()
{
@Override
public MuleEvent process(MuleEvent event) throws MuleException
{
Object operation = event.getMessage().removeProperty(CxfConstants.OPERATION, PropertyScope.INVOCATION);
MuleEvent result = processNext(event);
if (operation != null)
{
result.getMessage().setInvocationProperty(CxfConstants.OPERATION, operation);
}
return result;
}
});
chainBuilder.chain(createCxfOutboundMessageProcessor(config.getSecurity()));
chainBuilder.chain(new AbstractInterceptingMessageProcessor()
{
@Override
public MuleEvent process(MuleEvent event) throws MuleException
{
// Remove outbound properties that are mapped to SOAP headers, so that the
// underlying transport does not include them as headers.
List<String> outboundProperties = new ArrayList<String>(event.getMessage().getOutboundPropertyNames());
for (String outboundProperty : outboundProperties)
{
if (outboundProperty.startsWith(SOAP_HEADERS_PROPERTY_PREFIX))
{
event.getMessage().removeProperty(outboundProperty, PropertyScope.OUTBOUND);
}
}
// Send the request through the transport/connector
MuleEvent result = processNext(event);
// Ensure that the http.status code inbound property (if present) is a String.
Object statusCode = result.getMessage().getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, null);
if (statusCode != null && !(statusCode instanceof String))
{
result.getMessage().setProperty(HttpConnector.HTTP_STATUS_PROPERTY, statusCode.toString(), PropertyScope.INBOUND);
}
return result;
}
});
chainBuilder.chain(config.createOutboundMessageProcessor());
return chainBuilder.build();
}