You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by seanhouse79 <se...@gmail.com> on 2012/08/13 22:49:46 UTC

How to simulate a soap fault response with LogicalHandler or SOAPHandler?

Hi,

I am trying to create a SOAPHandler or LogicalHandler to simulate a soap
fault response. My response fault response is like this:

<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/><env:Body><env:Fault><faultcode>env:Server</faultcode><faultstring>An
unexpected/unhandled exception
occurred</faultstring><detail><ns2:GeneralException
xmlns:ns2="http://my.webservice/"><message>An unexpected/unhandled exception
occurred</message></ns2:GeneralException></detail></env:Fault></env:Body></env:Envelope>

I tried to create a payload from JAXBContext out of the soap body and set
that payload to the LogicalMessageContext but it doesn't work. The error is
saying that "The prefix "env" for element "env:Fault" is not bound".

Here is what I did:
// the responseMessage is   <env:Fault> ...</env:Fault>
ByteArrayInputStream bais = new
ByteArrayInputStream(responseMessage.getBytes());
Object obj = jaxbContext.createUnmarshaller().unmarshal(bais);
logicalMessageContext.getMessage().setPayload(obj, jaxbContext);

Can you help me figure it out? 

Thanks,

Sean Nguyen




--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-simulate-a-soap-fault-response-with-LogicalHandler-or-SOAPHandler-tp5712444.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to simulate a soap fault response with LogicalHandler or SOAPHandler?

Posted by Glen Mazza <gm...@talend.com>.
You can also throw a RuntimeException: 
http://docs.oracle.com/javase/6/docs/api/javax/xml/ws/handler/Handler.html, 
which SOAPFaultException subclasses: 
http://docs.oracle.com/javase/6/docs/api/javax/xml/ws/soap/SOAPFaultException.html.

You can also of course throw the SOAP fault from a web service provider 
instead: 
http://www.jroller.com/gmazza/entry/updating_databases_with_jaxws (look 
at class EmployeePortTypeImpl.java).

Finally, another option is to throw the exception from a CXF 
Interceptor: 
http://www.jroller.com/gmazza/entry/jaxwshandlers_to_cxfinterceptors. 
Those throw 
http://cxf.apache.org/javadoc/latest/org/apache/cxf/interceptor/Fault.html, 
which may give you more flexibility.

HTH,
Glen

On 08/13/2012 06:02 PM, seanhouse79 wrote:
> I have tried to look at your tutorial but it seems like I need to throw a
> subclass of Exception inside my public boolean
> handleMessage(LogicalMessageContext context) method. But that method doesn't
> allow for Exception to be thrown. I tried to throw ProtocolException but the
> HandlerChainInvoker doesn't convert that into Exception type. Do you have
> any idea?
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-simulate-a-soap-fault-response-with-LogicalHandler-or-SOAPHandler-tp5712444p5712452.html
> Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to simulate a soap fault response with LogicalHandler or SOAPHandler?

Posted by seanhouse79 <se...@gmail.com>.
I have tried to look at your tutorial but it seems like I need to throw a
subclass of Exception inside my public boolean
handleMessage(LogicalMessageContext context) method. But that method doesn't
allow for Exception to be thrown. I tried to throw ProtocolException but the
HandlerChainInvoker doesn't convert that into Exception type. Do you have
any idea?



--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-simulate-a-soap-fault-response-with-LogicalHandler-or-SOAPHandler-tp5712444p5712452.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to simulate a soap fault response with LogicalHandler or SOAPHandler?

Posted by Glen Mazza <gm...@talend.com>.
Hi Sean, my JAX-WS handler tutorial 
(http://www.jroller.com/gmazza/entry/jaxws_handler_tutorial) throws a 
few exceptions, it might have code useful for you.

Regards,
Glen

On 08/13/2012 04:49 PM, seanhouse79 wrote:
> Hi,
>
> I am trying to create a SOAPHandler or LogicalHandler to simulate a soap
> fault response. My response fault response is like this:
>
> <env:Envelope
> xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/><env:Body><env:Fault><faultcode>env:Server</faultcode><faultstring>An
> unexpected/unhandled exception
> occurred</faultstring><detail><ns2:GeneralException
> xmlns:ns2="http://my.webservice/"><message>An unexpected/unhandled exception
> occurred</message></ns2:GeneralException></detail></env:Fault></env:Body></env:Envelope>
>
> I tried to create a payload from JAXBContext out of the soap body and set
> that payload to the LogicalMessageContext but it doesn't work. The error is
> saying that "The prefix "env" for element "env:Fault" is not bound".
>
> Here is what I did:
> // the responseMessage is   <env:Fault> ...</env:Fault>
> ByteArrayInputStream bais = new
> ByteArrayInputStream(responseMessage.getBytes());
> Object obj = jaxbContext.createUnmarshaller().unmarshal(bais);
> logicalMessageContext.getMessage().setPayload(obj, jaxbContext);
>
> Can you help me figure it out?
>
> Thanks,
>
> Sean Nguyen
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-simulate-a-soap-fault-response-with-LogicalHandler-or-SOAPHandler-tp5712444.html
> Sent from the cxf-user mailing list archive at Nabble.com.