PDA

View Full Version : Converting exceptions to SOAP faults



nealcs
Jun 24th, 2010, 09:20 AM
Hi all. I'm developing a SOAP web service using Spring-WS (1.5.9). I've been trying to figure out how to convert server-side exceptions to SOAP faults, and have had limited success.

Here's my exception resolver definition:


<bean class="org.springframework.ws.soap.server.endpoint.SoapFa ultMappingExceptionResolver">
<property name="defaultFault" value="SERVER" />
<property name="exceptionMappings">
<props>
<prop key="Exception">SERVER,Internal server error</prop>
</props>
</property>
</bean>


If any exception occurs after the request has been handed off to the annotated endpoint, then this exception resolver works as expected. What I'm trying to figure out is how to handle exceptions that occur before the request is handed off to the endpoint.

For example, if the XML is malformed the declared exception resolver doesn't get invoked. Instead the following is output in the response:
Error 500: Request processing failed - nested exception is org.springframework.ws.soap.saaj.SaajSoapMessageEx ception: Could not access envelope....

Similarly, if I make a request for an endpoint that doesn't exist I get an HTTP 404 status (with an empty response), but no SOAP fault.

I've debugged MessageDispatcher but am still struggling with how to tell Spring to handle these cases. Any help is greatly appreciated. :)

Thanks,
--Neal

saradhi
Jun 27th, 2010, 09:38 AM
HI Neal... do you got any solution or work around for this issue...just curious to know. Please post it.

nealcs
Jun 30th, 2010, 10:14 AM
Unfortunately, I was unable to find a Spring solution to the problem. Instead I created error-page definitions in web.xml to map HTTP status codes to static responses. I did this for 404 and 500 status codes.

In web.xml:


<error-page>
<error-code>404</error-code>
<location>/soapErrorResponses/404.soap</location>
</error-page>


404.soap:


<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<env:Fault>
<faultcode>env:Server</faultcode>
<faultstring>404:System</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>


I found this solution a few days ago from some google searching. Does anyone have any feedback on this solution?

Thanks,
--Neal