räph
räph

Reputation: 3674

How to handle SOAP faults from external systems in CXF?

I'm using CXF 2.6.2 to access a webservice from an external system. Stubs are generated from WSDL file. This works fine when the websevice responds correctly, but not in fault case.

Then I get the following exception:

Caused by: org.w3c.dom.DOMException: Operation not supported on this type of node: [ExceptionDetail: null] at org.jboss.ws.core.soap.NodeImpl.convertDOMNode(NodeImpl.java:557) at org.jboss.ws.core.soap.NodeImpl.appendChild(NodeImpl.java:459) at org.apache.cxf.jaxws.JaxWsClientProxy.createSoapFault(JaxWsClientProxy.java:234) at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:152)

The actual response I get from the webservice is:

ID: 6
Response-Code: 500
Encoding: UTF-8
Content-Type: text/xml; charset=utf-8
Headers: {Content-Length=[1925], content-type=[text/xml; charset=utf-8], Date=[Wed, 16 Oct 2013 05:40:21 GMT], Persistent-Auth=[true], Server=[Microsoft-IIS/7.5], X-Powered-By=[ASP.NET]}
Payload: 
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body><s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>
<faultstring xml:lang="en-US">External Exception Message</faultstring>
<detail><ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><HelpLink i:nil="true"/><InnerException i:nil="true"/><Message>External Exception Message</Message><StackTrace>...stacktrace from external system...</StackTrace><Type>XXXException</Type></ExceptionDetail></detail>
</s:Fault></s:Body>
</s:Envelope>

So my question is how can I handle soapfaults correctly with CXF? What I need is to get the faultstring out of the response.

Of course I could parse the returned message, but this would be very cumbersome.

I already registered an own interceptor (extending AbstractSoapInerceptor) which gets the returned soapmessage, but the message only includes an inputstream with the response and doesn't seem to recognize the XML inside.

Thanks

Upvotes: 1

Views: 823

Answers (1)

r&#228;ph
r&#228;ph

Reputation: 3674

Problem solved. After more indetail debugging I found out that the problem is actually caused by my JBoss 4.2.3 on which I'm using the CXF implementation.

For some reason JBoss WS got involved in the process and this one couldn't pasrse the detail tag of the fault message. After deleting the detail tag I cam across the next exception: An instantiation exception for org.jboss.ws.core.soap.SOAPFaultElementImpl. This class actually was not in my classpath as I thought I don't need to use jbossws. Now I've included it and everything is working as expected!

Upvotes: 1

Related Questions