You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by marckropholler <m....@finan.nl> on 2012/03/26 15:25:16 UTC

Throwing a custom SOAP Fault

Dear all,

Could anybody give some help with returning a soap fault with custom fault
details (in the <details> tag in the SOAP Fault response) filled in? After
browsing the fora and trying for some time, we are still trying to fill the
details tag with some xml that is also used in one of our other webservices
- thus we are trying to make things work by passing a cxf-generated class
(wsdl2java) to the cxf fault handling code. JAXB throws an exception
complaining that the passed in class nor any of its super classes is known
to this context. To make things more clear:

Our customized interceptor that modifies the soap message:


The passed in DetailFault class that wraps the bean containing the info to
render the <detail> tag:



Part of the stacktrace:




I'm using JRebel to speed things up (thus changing classes and annotations
on the fly) but there doesn't appear to be any caching involved 
so I don't think it is giving trouble.

cxf 2.3.6
spring 3.0.5
java 1.5.0.22
JBoss 4.2.3

Things tried:
 - The FoutBerichtType is just a bean with two more beans with several
fields in it, without using generics.
Returning just an enum generated by wsdl2java caused the same error.
 - replacing @WebFault by @WebFault(name = "FoutberichtType",
targetNamespace="http://ns.fazont.nl/operations/fout/v1") caused the same
error.
 - returning a java.lang.Object by getFaultInfo(). This caused the same
error. I'm pretty sure I also saw something like, object not annotated with
with @XmlRootElement which makes me wonder whether that may give trouble
too, because FoutberichtType doesn't have @XmlRootElement on it.

Your help is very much appreciated,
Marc

--
View this message in context: http://cxf.547215.n5.nabble.com/Throwing-a-custom-SOAP-Fault-tp5595222p5595222.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Throwing a custom SOAP Fault

Posted by marckropholler <m....@finan.nl>.
I can't check it, but i'm pretty sure we did.

Marc

--
View this message in context: http://cxf.547215.n5.nabble.com/Throwing-a-custom-SOAP-Fault-tp5595222p5597930.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Throwing a custom SOAP Fault

Posted by Mark Streit <mc...@gmail.com>.
Do you have the @WebFault annotation on the exception class as noted in the
article?   Just curious.

http://io.typepad.com/eben_hewitt_on_java/2009/07/using-soap-faults-and-exceptions-in-java-jaxws-web-services.html


Mark
On Mar 27, 2012 7:35 AM, "marckropholler" <m....@finan.nl> wrote:

> Dear Mark,
>
> Thanks for the reply. I read the thread but still couldn't find what was
> causing the trouble, the required constructors and getFaultInfo info method
> are there. Maybe parsing the object manually would be the solution.
>
> Best wishes
> Marc
>
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Throwing-a-custom-SOAP-Fault-tp5595222p5597151.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Re: Throwing a custom SOAP Fault

Posted by marckropholler <m....@finan.nl>.
Dear Mark,

Thanks for the reply. I read the thread but still couldn't find what was
causing the trouble, the required constructors and getFaultInfo info method
are there. Maybe parsing the object manually would be the solution.

Best wishes
Marc



--
View this message in context: http://cxf.547215.n5.nabble.com/Throwing-a-custom-SOAP-Fault-tp5595222p5597151.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Throwing a custom SOAP Fault

Posted by Mark Streit <mc...@gmail.com>.
Would this be of any help?
Similar topic ... It has a ref to a helpful article on this.

http://comments.gmane.org/gmane.comp.apache.cxf.user/18286

Mark
On Mar 26, 2012 9:47 AM, "marckropholler" <m....@finan.nl> wrote:

> Dear all,
>
> Could anybody give some help with returning a soap fault with custom fault
> details (in the <details> tag in the SOAP Fault response) filled in? After
> browsing the fora and trying for some time, we are still trying to fill the
> details tag with some xml that is also used in one of our other webservices
> - thus we are trying to make things work by passing a cxf-generated class
> (wsdl2java) to the cxf fault handling code. JAXB throws an exception
> complaining that the passed in class nor any of its super classes is known
> to this context. To make things more clear:
>
> Our customized interceptor that modifies the soap message:
>
>
> The passed in DetailFault class that wraps the bean containing the info to
> render the <detail> tag:
>
>
>
> Part of the stacktrace:
>
>
>
>
> I'm using JRebel to speed things up (thus changing classes and annotations
> on the fly) but there doesn't appear to be any caching involved
> so I don't think it is giving trouble.
>
> cxf 2.3.6
> spring 3.0.5
> java 1.5.0.22
> JBoss 4.2.3
>
> Things tried:
>  - The FoutBerichtType is just a bean with two more beans with several
> fields in it, without using generics.
> Returning just an enum generated by wsdl2java caused the same error.
>  - replacing @WebFault by @WebFault(name = "FoutberichtType",
> targetNamespace="http://ns.fazont.nl/operations/fout/v1") caused the same
> error.
>  - returning a java.lang.Object by getFaultInfo(). This caused the same
> error. I'm pretty sure I also saw something like, object not annotated with
> with @XmlRootElement which makes me wonder whether that may give trouble
> too, because FoutberichtType doesn't have @XmlRootElement on it.
>
> Your help is very much appreciated,
> Marc
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Throwing-a-custom-SOAP-Fault-tp5595222p5595222.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

fixed

Posted by marckropholler <m....@finan.nl>.
Dear all,

Found the following two or three solutions:

1. instantiate custom JAXB/CXF classes that parse the object to xml. The
only thing is that you have to wrap the object in a class containing
@XmlRootElement, which ends up in the exception, but since the classes write
to a org.w3c.dom.Element it (looks like) you can get its child element and
use that. Sample code (without removing root element from xml):

public void handleFault(Message message) {
        Fault fault = (Fault) message.getContent(Exception.class);
	binding = new
org.apache.cxf.jaxb.JAXBDataBinding(FoutberichtTypeHolder.class);
	org.apache.cxf.jaxb.io.DataWriterImpl writer = new
org.apache.cxf.jaxb.io.DataWriterImpl(binding);
	writer.write(new FoutberichtTypeHolder(foutberichtType), null,
fault.getOrCreateDetail());


2. Hacky: create a document from an xml file and use that:

public void handleFault(Message message) {
        Fault fault = (Fault) message.getContent(Exception.class);
	InputStream inputStream = new
ClassPathResource("fault-details.xml").getInputStream();
	Document document = DOMUtils.createDocumentBuilder().parse(inputStream);
	Node node = XPathAPI.selectSingleNode(document, xpath);
	node.setTextContent(text);
	fault.setDetail(document.getDocumentElement());

3. Don't know if this one works, but it may: create a Fault object as you
want by specifying it in the wsdl, and setting
it using message.setContent(Exception.class, fault).

Best wishes
Marc




--
View this message in context: http://cxf.547215.n5.nabble.com/Throwing-a-custom-SOAP-Fault-tp5595222p5597436.html
Sent from the cxf-user mailing list archive at Nabble.com.