On Oct 31, 2013, at 12:29 PM, Faz <[email protected]> wrote:

> Hi ALL,
> 
> I'm using CXf's fault out interceptor to intercept the exception from the
> web services method. That works fine within the handleMessage method.. Now I
> have two queries,
> 
> 1. How do I had extra information to the Fault object apart from setting the
> faultcode.?

Most likely, what you would need/want to do is take the Exception/Fault out of 
the message, create a new SoapFault with the new information, and set that back 
in the message and let the rest of CXF’s chain do it’s thing:


public void handleMessage(SoapMessage message) throws Fault {
        Fault f = (Fault) message.getContent(Exception.class);
        SoapFault fault = SoapFault.createFault(f, message.getVersion());
        //modify the SoapFault or create a new one or something
        message.setContent(Exception.class, fault);
}

The default Soap[12|11]FaultOutInterceptor will then grab that SoapFault from 
the message and output it correctly.


> 2. Say if there is any error in the handleMessage method, the control goes
> to handleFault method but in the handle fault method it simply unwinds and
> logs something like - *GetMth has thrown exception, unwinding now:
> java.lang.Exception:*. But the fault message(in xml format) is not being
> sent to the client as Output mesasage, How do I make sure that the fault
> message is sent as SOAPfault  to the clinet?

Do not throw any exceptions from the Fault chain.   If there is a fault thrown 
from the fault chain, there is really no way for us to be able to know what can 
be done about, how to fix the situation, etc… The assumption is that if a fault 
is thrown from the fault chain, then something seriously has gone wrong and we 
cannot write anything out to the client.   The normal case that this occurs is 
if we cannot write to the OutputStream due to the network closing the 
connection or similar.   In that case, there is nothing we can do except log 
the issue and move on.

Dan


> [in the hanldeMessage bleow, i have place *f=null *to introduce the fault ]
> 
> Handle message and handleFault methods:
> 
> 
>         *public class SimpleSOAPFaultInterceptor extends
> AbstractSoapInterceptor {
>       private static Logger log = Logger.getLogger("org.apache");
>       
>       public SimpleSOAPFaultInterceptor() {
>               super(Phase.MARSHAL);
>       }
>       
>       public void handleMessage(SoapMessage message) throws Fault {
>               // TODO Auto-generated method stub
>               try {
>               
>                       Fault f = (Fault) message.getContent(Exception.class);
>                       //f=null; /[Introduing an excpetion so that handleFault 
> is called]/             
> log.debug(" f ::::: "+ f.getCode());
>                       Throwable cause = f.getCause();
>                       if (cause instanceof MyServiceException) {
>                               f.setFaultCode(new QName("", 
> String.valueOf("100000")));
>                       } else {
>                               log.warn("!!!!!!Unexpected Exception thrown ", 
> cause);
>                       }
>                       } catch (SOAPException e) {
>                               // TODO Auto-generated catch block
>                               System.out.println("CAUGHT HERE "+e);
>                               e.printStackTrace();
>                       }  catch (Exception e) {
>                               // TODO Auto-generated catch block
>                               System.out.println("CAUGHT HERE Exception "+e);
>                               throw new Fault(new Exception(
>                        "Exception...."));
>                       }
>       }
>       
>       
>       
>       @Override
>       public void handleFault(SoapMessage message) {
>               // TODO Auto-generated method stub
>               super.handleFault(message);
>               
>               System.out.println("**handleFault the message ** "+message);
>               Fault f = (Fault) message.getContent(Exception.class);
>               System.out.println("**the f ** "+f);
>           //f.setFaultCode(new QName("", String.valueOf("8")));
>               //SoapFault sf = new SoapFault("message",new QName("",
> String.valueOf("99000")));
>               //SoapFault.createFault(f, message.getVersion())
>           //                   .setMessage("INSIDE DIUDE");
>               
>       }*
> 
> 
> 
> --
> View this message in context: 
> http://cxf.547215.n5.nabble.com/HandleFault-in-CXF-tp5735813.html
> Sent from the cxf-user mailing list archive at Nabble.com.

-- 
Daniel Kulp
[email protected] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Reply via email to