You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by STEVEN THEIN <st...@oracle.com> on 2011/07/12 20:36:50 UTC

Re: Handling fault in interceptor...

Hi Dan,
I can get the exception using  message.getContent(Exception.class).

After I got the exception I would like to add some more information and 
I would like to create a SoapMessage and  insert it into the output stream.
After that I would like to suppress the exception or remove the 
exception from the existing message object.

Is it possible to do these?

  Thanks
  steve

On 6/8/2011 1:33 PM, Daniel Kulp wrote:
> On Wednesday, June 08, 2011 10:07:56 AM STEVEN THEIN wrote:
>> Hi,
>>
>> I created an inbound interceptor on server side which have two override
>> methods:-
>>
>> handleMessage() and handleFault()
>>
>> When an exception is thrown while processing the message in
>> handleMessage(),  it called into handleFault() method.
>> In handleFault() method, how can I retrieve the fault that was thrown
>> from handleMessage().
> I think you can call message.getContent(Fault.class) or
> message.getContent(Exception.class).   Likely the latter.
>
>

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

Re: Handling fault in interceptor...

Posted by Faz <ar...@gmail.com>.
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 Aki Yoshida <el...@googlemail.com>.
Hi Steve,
yes. The WS-RM's org.apache.cxf.ws.rm.RetransmissionInterceptor does
something similar, namely removing the exception from the
message/exchange container when an exception occurs after the message
is queued for retransmission. In this way, the exception is not thrown
back the the client.

regards, aki

2011/7/12 STEVEN THEIN <st...@oracle.com>:
> Hi Dan,
> I can get the exception using  message.getContent(Exception.class).
>
> After I got the exception I would like to add some more information and I
> would like to create a SoapMessage and  insert it into the output stream.
> After that I would like to suppress the exception or remove the exception
> from the existing message object.
>
> Is it possible to do these?
>
>  Thanks
>  steve
>
> On 6/8/2011 1:33 PM, Daniel Kulp wrote:
>>
>> On Wednesday, June 08, 2011 10:07:56 AM STEVEN THEIN wrote:
>>>
>>> Hi,
>>>
>>> I created an inbound interceptor on server side which have two override
>>> methods:-
>>>
>>> handleMessage() and handleFault()
>>>
>>> When an exception is thrown while processing the message in
>>> handleMessage(),  it called into handleFault() method.
>>> In handleFault() method, how can I retrieve the fault that was thrown
>>> from handleMessage().
>>
>> I think you can call message.getContent(Fault.class) or
>> message.getContent(Exception.class).   Likely the latter.
>>
>>
>