codehaus


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How-to: Return SOAPFault from JMS Queue Processor


Hi,

I've found multiple examples and forums posts regarding this, but not
exactly like what I have.

I've configured CXF Endpoint using Blueprint XML ( use XML tag cxfEndpoint
), and I forward SOAP requests to JMS queue - different for each SOAPAction.

<camelcxf:cxfEndpoint id="SoapWebserviceEndpoint" ... />

<camelContext id="SOAPWebservice_Master" xmlns="
http://camel.apache.org/schema/blueprint";>
<route id="Default">
            <from uri="SoapWebserviceEndpoint"/>
            <log message="Received SOAP Request."/>
            <choice>
                <when>
                    <simple>'GetVersion' ==
${in.headers['SOAPAction']}</simple>
                    <log message="Forward SOAP call to GetVersion."/>
                    <to uri="activemq:queue:SOAPWebservice/GetVersion"/>
                </when>
                <otherwise>
                    <throwException
exceptionType="java.lang.IllegalStateException" message="Method not
implemented. SOAP Action: ${in.headers['SOAPAction']}." />
                </otherwise>
            </choice>
        </route>

    </camelContext>

Works like a charm. No problem. Well, until there is a problem --
ExceptionHandling.

General idea is, to have "ExceptionHandler" queue, that will handle
exception and return "simple" SOAPFault, like this:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Method not implemented. SOAP Action:
GetSoapMethod.</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

I've added ( as sibling to route Default ):

        <route id="CatchException">
            <from uri="activemq:queue:SOAPWebservice/HandleException"/>
            <log message="Caught Exception. Will pass it to the Exception
Handler Processor now."/>
            <process ref="ExceptionHandlerProcessor"/>
        </route>

and at the beginning I've added:

<onException useOriginalMessage="true">
    <exception>java.lang.Exception</exception>
    <redeliveryPolicy maximumRedeliveries="0"/>
    <handled>
        <constant>true</constant>
    </handled>
    <to uri="activemq:queue:SOAPWebservice/HandleException" />
</onException>


But now, I get:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Part {
http://soap.example.com/SoapWebservice}parameters should be of type
com.example.soap.model.soapwebservice.GetSoapMethodResponse, not
java.lang.IllegalStateException</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

Exception Handler ( bean ExceptionHandlerProcessor ) is like:

public void process(final Exchange exchange) throws Exception {
        final Message message = exchange.getOut();
        message.setFault(true);
        message.setBody(exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
Exception.class));
}

I've checked RHEL, Talend, ... documentation, like this:
https://help.talend.com/reader/8avcOyufaVYo7Uoah0kOlA/0JGn1C8bhm~R_OP82fgzzg

And this all works using direct and similar routeing, until I do not move
routing to the JMS queue. What am I doing wrong?

Kind Regards,
Miroslav




-- 
Miroslav Beranič
MIBESIS
+386(0)40/814-843
miroslav.beranic@xxxxxxxxxx
http://www.mibesis.si