You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Faz <ar...@gmail.com> on 2013/11/03 13:37:26 UTC

Re: Handling fault in interceptor...

Hi Dan, Sergey,

I know its a very old thread, but need some help on this.

I have registered the out interceptor and am able to get the fault object in
the *handleFault* method, but i'm unable to send this to the outbound
handle. The message is suppressed in the handleFult metod wherein it just
logs the error to the console log (saying unwinding thr error...) and
terminates. I need it to send the modified fault message to the client.

Could you please throw some light?

Thanks.



--
View this message in context: http://cxf.547215.n5.nabble.com/Handling-fault-in-interceptor-tp4469616p5735870.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Handling fault in interceptor...

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
Exceptions thrown from out fault interceptors are actually propagated to 
the servlet container.
JAXRSDefaultFaultOutInterceptor will ensure a registered exception 
mapper is invoked, register a custom ConstraintViolationException mapper.

Sergey

On 05/03/15 09:31, Atul wrote:
> Hi All,
>
> I am facing a similar problem.
>
> JAXRSValidationInINterceptor is throwing an exception in PRE_INVOKE phase. I
> want to catch this exception and return a custom json response to the
> client. I have created a custom interceptor which catches the exception ,
> takes out the message . I have one exception mapper registered. I am using
> that but its not working. No json content is going to the client. Please
> help. I want to send JSON response to the client.
>
>   @Override
>      public void handleMessage(Message aInMessage) throws Fault
>      {
>          Exception e = aInMessage.getContent(Exception.class);
>          Fault f = (Fault)e;
>          if(f.getCause() instanceof ConstraintViolationException){
>              ConstraintViolationException exception =
> (ConstraintViolationException)f.getCause();
>              String message =
> exception.getConstraintViolations().iterator().next().getMessage();
>              XRouterError error = new XRouterError("401",message);
>              throw new OperationFailedException(error);
>          }
>      }
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Handling-fault-in-interceptor-tp4469616p5754766.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: Handling fault in interceptor...

Posted by Atul <at...@gmail.com>.
Hi All, 

I am facing a similar problem. 

JAXRSValidationInINterceptor is throwing an exception in PRE_INVOKE phase. I
want to catch this exception and return a custom json response to the
client. I have created a custom interceptor which catches the exception ,
takes out the message . I have one exception mapper registered. I am using
that but its not working. No json content is going to the client. Please
help. I want to send JSON response to the client. 

 @Override 
    public void handleMessage(Message aInMessage) throws Fault 
    { 
        Exception e = aInMessage.getContent(Exception.class); 
        Fault f = (Fault)e; 
        if(f.getCause() instanceof ConstraintViolationException){ 
            ConstraintViolationException exception =  
(ConstraintViolationException)f.getCause(); 
            String message =
exception.getConstraintViolations().iterator().next().getMessage(); 
            XRouterError error = new XRouterError("401",message); 
            throw new OperationFailedException(error); 
        } 
    } 



--
View this message in context: http://cxf.547215.n5.nabble.com/Handling-fault-in-interceptor-tp4469616p5754766.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Handling fault in interceptor...

Posted by Faz <ar...@gmail.com>.
Hi ,
Could you please suggest on this?

Thnx,




--
View this message in context: http://cxf.547215.n5.nabble.com/Handling-fault-in-interceptor-tp4469616p5735920.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Handling fault in interceptor...

Posted by Faz <ar...@gmail.com>.
Thanks for the response.
 I'm actually trying to achieve soemthing that I have mentioned in
http://cxf.547215.n5.nabble.com/HandleFault-in-CXF-Interceptors-tried-possible-options-td5735813.html

I managed to write the SoapMessage to the XMLwriter class , but for some
resaons I'm not able to pass or broadcast the message/fault to the client.
(even the outbound handle message isn't getting displayed in the logs). But
when i do a soapmessage.writeTo(system.out) I get the below displayed in the
logs

<env:Envelope
xmlns:env="http://www.w3.org/2003/05/soap-envelope"><env:Header/><env:Body><env:Fault><env:Code><env:Value>env:Receiver</env:Value></env:Code><env:Reason><env:Text
xml:lang="en-US">Strange</env:Text></env:Reason></env:Fault></env:Body></env:Envelope>

In short, I need to send the above message(fault) to the client just like
any other apt message sent to the client.

Please let me know if you need further info,
Thnaks.



--
View this message in context: http://cxf.547215.n5.nabble.com/Handling-fault-in-interceptor-tp4469616p5735882.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Handling fault in interceptor...

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 03/11/13 12:37, Faz wrote:
> Hi Dan, Sergey,
>
> I know its a very old thread, but need some help on this.
>
> I have registered the out interceptor and am able to get the fault object in
> the *handleFault* method, but i'm unable to send this to the outbound
> handle. The message is suppressed in the handleFult metod wherein it just
> logs the error to the console log (saying unwinding thr error...) and
> terminates. I need it to send the modified fault message to the client.
>
> Could you please throw some light?
>

Can you please clarify what exactly you'd like to achieve and how you 
implement it ?

Thanks, Sergey


> Thanks.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Handling-fault-in-interceptor-tp4469616p5735870.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com