How to trigger custom SOAP interceptor?
mh1 Aug 15, 2014 8:22 AMThe Problem:
We've built a web-service using SwitchYard running on Fuse Service Works. (jboss-fsw-6.0.0.GA-redhat-4) When an invalid XML request to our web-service is received, we want to be able to customise the text in the SOAP Fault message sent in response. At the current time, the actual response sent out is produced by the Soap12FaultOutInterceptor and contains a message that describes the problem - be it a missing tag, an empty request or whatever. We've been tasked with consolidating all such responses to send a standard message of "Message Format Invalid" hence the motivation to pursue this.
Our Attempted Solution:
To do this, we've created a custom interceptor (via the '<class> extends AbstractSoapInterceptor' route) and used the constructor to set the phase in the interceptor chain that our custom interceptor is inserted. We've implemented the 'handleMessage' method with a simple LOG/SYSO message for testing while we develop this. We've declared this interceptor on the SOAP binding of our SwitchYard diagram and confirmed it produced the expected XML config in the switchyard.xml file.
Here's some examples of the code produced to illustrate:
Config that appears in the switchyard.xml file after we add our interceptor to the SOAP binding.
<soap:binding.soap name="OurWebServiceSoapBinding">
<soap:contextMapper soapHeadersType="DOM"/>
...<snip>...
<soap:outInterceptors>
<soap:interceptor class="com.ourweb.service.bean.interceptor.MessageFormatInvalidOutFaultInterceptor"/>
</soap:outInterceptors>
</soap:binding.soap>
The custom interceptor we created:
public class MessageFormatInvalidOutFaultInterceptor extends AbstractSoapInterceptor
{
/** Logger Constant - Represents the log-instance to use when logging messages. */
private static final Logger LOG = LoggerFactory.getLogger(MessageFormatInvalidOutFaultInterceptor.class);
public MessageFormatInvalidOutFaultInterceptor()
{
super(Phase.INVOKE);
getAfter().add(Soap12FaultOutInterceptor.class.getName());
}
public void handleMessage(SoapMessage message) throws Fault
{
// Fault fault = (Fault) message.getContent(Exception.class);
Fault fault = message.getContent(Fault.class);
LOG.debug("########## -> MessageFormatInvalidOutFaultInterceptor!!!");
LOG.debug("########## -> [" + fault.getDetail().getFirstChild().getTextContent() + "]");
System.out.println("########## -> MessageFormatInvalidOutFaultInterceptor!!!");
System.out.println("########## -> [" + fault.getDetail().getFirstChild().getTextContent() + "]");
}
}
Note: We've tried testing this at each of the phases in the chain (here quoted it's INVOKE but really we'd have thought this should be around PREPARE_SEND) and we've added the 'getAfter' in a final bid of desperation!
No matter what we do, we cannot get a request message sent into our web-service to trigger this interceptor.
Thus, we're rather stuck for ideas and would be grateful if anyone can lend some thoughts or advice on things we may need to do/try/test. This is our/my first time working with this technology stack so we're learning as we go.
Many thanks in advance.
Mark.