You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Mike O'Neil <mt...@gmail.com> on 2009/12/17 20:24:44 UTC

Fault thrown in Rest In-Interceptor not handled by ExceptionMapper

I have an ExceptionMapper which handles exceptions from my Rest
service just fine. However when my "In" Interceptor throws a Fault,
the ExceptionMapper does not handle it. Instead I get the standard
(ugly) XML, e.g.:

    <ns1:XMLFault><ns1:faultstring>error
message</ns1:faultstring></ns1:XMLFault>

Is that the expected behavior? My server is set up like:

<jaxrs:server id="service" address="/rest">
        <jaxrs:serviceBeans>
            <bean parent="myService" />
        </jaxrs:serviceBeans>
        <jaxrs:inInterceptors>
            <ref bean="myInterceptor"/>
        </jaxrs:inInterceptors>
        <jaxrs:providers>
            <ref bean="restExceptionMapper"/>
        </jaxrs:providers>
</jaxrs:server>


And my interceptor looks like:

public class MyInterceptor extends AbstractPhaseInterceptor<Message> {
    public FormatSettingInterceptor() {
        super(Phase.PRE_STREAM);
    }

    @Override
    public void handleMessage(Message message) throws Fault {
            throw new Fault("Not handled by ExceptionMapper!");
    }
}

Any insight or help would be appreciated.

Much thanks,
Mike

RE: Fault thrown in Rest In-Interceptor not handled by ExceptionMapper

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi,
Out interceptors deal with out messages, so you can get the original query like this :

outMessage.getExchange().getInputMessage().get(Message.QUERY_STRING)

cheers, Sergey

-----Original Message-----
From: Mike O'Neil [mailto:mtoneil@gmail.com] 
Sent: 18 December 2009 19:46
To: users@cxf.apache.org
Subject: Re: Fault thrown in Rest In-Interceptor not handled by ExceptionMapper

Thanks all. CustomOutFaultInterceptor + ResponseHandler handles all
use cases nicely for me. But, I notice the incoming Message to both is
missing most properties. In particular, QUERY_STRING is not set. I
need this to generate proper output in my application. I imagine in
ResponseHandler I can use @Context (UrlInfo) to access it, but what
about in the OutFault interceptor? Am I out of luck on this one?

Thanks,
Mike

On Thu, Dec 17, 2009 at 6:25 PM, vickatvuuch <vl...@gmail.com> wrote:
>
> one more gotcha I hit with this is that SOAP Flex client can't handle
> HTTP response other than 200. If you reply with HTTP 500 it completely
> ignores your Soap fault, giving a useless IOError instead of SoapFault..
>
>
> Mike O'Neil-2 wrote:
>>
>> Thanks for your response. I gave this a shot and it seems to work
>> pretty well, though is a lot more cumbersome, seeing as how we need to
>> handle the marshalling directly. Unfortunately this also introduces a
>> different place where an exception is not properly handled: when
>> trying to find the target method in JAXRSUtils, if not found, a
>> WebApplicationException is thrown but the custom fault out interceptor
>> is not invoked. This results in an empty body in the HTTP response.
>> Have you run into that?
>>
>> Thanks for your help,
>> Mike
>>
>> On Thu, Dec 17, 2009 at 3:25 PM, vickatvuuch <vl...@gmail.com> wrote:
>>>
>>> I have had a similar problem and worked it around by building a
>>> CustomFaultOutInterceptor,
>>> which handles everything that gets thrown for both REST and SOAP. Once
>>> you
>>> have a single place to do it
>>> you can translate Exception into HTTP response codes as well as you can
>>> enchance
>>> the default Soap fault as appropriate.
>>>
>>>
>>> Mike O'Neil-2 wrote:
>>>>
>>>> I have an ExceptionMapper which handles exceptions from my Rest
>>>> service just fine. However when my "In" Interceptor throws a Fault,
>>>> the ExceptionMapper does not handle it. Instead I get the standard
>>>> (ugly) XML, e.g.:
>>>>
>>>>     <ns1:XMLFault><ns1:faultstring>error
>>>> message</ns1:faultstring></ns1:XMLFault>
>>>>
>>>> Is that the expected behavior? My server is set up like:
>>>>
>>>> <jaxrs:server id="service" address="/rest">
>>>>         <jaxrs:serviceBeans>
>>>>             <bean parent="myService" />
>>>>         </jaxrs:serviceBeans>
>>>>         <jaxrs:inInterceptors>
>>>>             <ref bean="myInterceptor"/>
>>>>         </jaxrs:inInterceptors>
>>>>         <jaxrs:providers>
>>>>             <ref bean="restExceptionMapper"/>
>>>>         </jaxrs:providers>
>>>> </jaxrs:server>
>>>>
>>>>
>>>> And my interceptor looks like:
>>>>
>>>> public class MyInterceptor extends AbstractPhaseInterceptor<Message> {
>>>>     public FormatSettingInterceptor() {
>>>>         super(Phase.PRE_STREAM);
>>>>     }
>>>>
>>>>     @Override
>>>>     public void handleMessage(Message message) throws Fault {
>>>>             throw new Fault("Not handled by ExceptionMapper!");
>>>>     }
>>>> }
>>>>
>>>> Any insight or help would be appreciated.
>>>>
>>>> Much thanks,
>>>> Mike
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Fault-thrown-in-Rest-In-Interceptor-not-handled-by-ExceptionMapper-tp26833555p26834406.html
>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Fault-thrown-in-Rest-In-Interceptor-not-handled-by-ExceptionMapper-tp26833555p26836759.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>

Re: Fault thrown in Rest In-Interceptor not handled by ExceptionMapper

Posted by Mike O'Neil <mt...@gmail.com>.
Thanks all. CustomOutFaultInterceptor + ResponseHandler handles all
use cases nicely for me. But, I notice the incoming Message to both is
missing most properties. In particular, QUERY_STRING is not set. I
need this to generate proper output in my application. I imagine in
ResponseHandler I can use @Context (UrlInfo) to access it, but what
about in the OutFault interceptor? Am I out of luck on this one?

Thanks,
Mike

On Thu, Dec 17, 2009 at 6:25 PM, vickatvuuch <vl...@gmail.com> wrote:
>
> one more gotcha I hit with this is that SOAP Flex client can't handle
> HTTP response other than 200. If you reply with HTTP 500 it completely
> ignores your Soap fault, giving a useless IOError instead of SoapFault..
>
>
> Mike O'Neil-2 wrote:
>>
>> Thanks for your response. I gave this a shot and it seems to work
>> pretty well, though is a lot more cumbersome, seeing as how we need to
>> handle the marshalling directly. Unfortunately this also introduces a
>> different place where an exception is not properly handled: when
>> trying to find the target method in JAXRSUtils, if not found, a
>> WebApplicationException is thrown but the custom fault out interceptor
>> is not invoked. This results in an empty body in the HTTP response.
>> Have you run into that?
>>
>> Thanks for your help,
>> Mike
>>
>> On Thu, Dec 17, 2009 at 3:25 PM, vickatvuuch <vl...@gmail.com> wrote:
>>>
>>> I have had a similar problem and worked it around by building a
>>> CustomFaultOutInterceptor,
>>> which handles everything that gets thrown for both REST and SOAP. Once
>>> you
>>> have a single place to do it
>>> you can translate Exception into HTTP response codes as well as you can
>>> enchance
>>> the default Soap fault as appropriate.
>>>
>>>
>>> Mike O'Neil-2 wrote:
>>>>
>>>> I have an ExceptionMapper which handles exceptions from my Rest
>>>> service just fine. However when my "In" Interceptor throws a Fault,
>>>> the ExceptionMapper does not handle it. Instead I get the standard
>>>> (ugly) XML, e.g.:
>>>>
>>>>     <ns1:XMLFault><ns1:faultstring>error
>>>> message</ns1:faultstring></ns1:XMLFault>
>>>>
>>>> Is that the expected behavior? My server is set up like:
>>>>
>>>> <jaxrs:server id="service" address="/rest">
>>>>         <jaxrs:serviceBeans>
>>>>             <bean parent="myService" />
>>>>         </jaxrs:serviceBeans>
>>>>         <jaxrs:inInterceptors>
>>>>             <ref bean="myInterceptor"/>
>>>>         </jaxrs:inInterceptors>
>>>>         <jaxrs:providers>
>>>>             <ref bean="restExceptionMapper"/>
>>>>         </jaxrs:providers>
>>>> </jaxrs:server>
>>>>
>>>>
>>>> And my interceptor looks like:
>>>>
>>>> public class MyInterceptor extends AbstractPhaseInterceptor<Message> {
>>>>     public FormatSettingInterceptor() {
>>>>         super(Phase.PRE_STREAM);
>>>>     }
>>>>
>>>>     @Override
>>>>     public void handleMessage(Message message) throws Fault {
>>>>             throw new Fault("Not handled by ExceptionMapper!");
>>>>     }
>>>> }
>>>>
>>>> Any insight or help would be appreciated.
>>>>
>>>> Much thanks,
>>>> Mike
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Fault-thrown-in-Rest-In-Interceptor-not-handled-by-ExceptionMapper-tp26833555p26834406.html
>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Fault-thrown-in-Rest-In-Interceptor-not-handled-by-ExceptionMapper-tp26833555p26836759.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>

Re: Fault thrown in Rest In-Interceptor not handled by ExceptionMapper

Posted by vickatvuuch <vl...@gmail.com>.
one more gotcha I hit with this is that SOAP Flex client can't handle 
HTTP response other than 200. If you reply with HTTP 500 it completely 
ignores your Soap fault, giving a useless IOError instead of SoapFault.. 


Mike O'Neil-2 wrote:
> 
> Thanks for your response. I gave this a shot and it seems to work
> pretty well, though is a lot more cumbersome, seeing as how we need to
> handle the marshalling directly. Unfortunately this also introduces a
> different place where an exception is not properly handled: when
> trying to find the target method in JAXRSUtils, if not found, a
> WebApplicationException is thrown but the custom fault out interceptor
> is not invoked. This results in an empty body in the HTTP response.
> Have you run into that?
> 
> Thanks for your help,
> Mike
> 
> On Thu, Dec 17, 2009 at 3:25 PM, vickatvuuch <vl...@gmail.com> wrote:
>>
>> I have had a similar problem and worked it around by building a
>> CustomFaultOutInterceptor,
>> which handles everything that gets thrown for both REST and SOAP. Once
>> you
>> have a single place to do it
>> you can translate Exception into HTTP response codes as well as you can
>> enchance
>> the default Soap fault as appropriate.
>>
>>
>> Mike O'Neil-2 wrote:
>>>
>>> I have an ExceptionMapper which handles exceptions from my Rest
>>> service just fine. However when my "In" Interceptor throws a Fault,
>>> the ExceptionMapper does not handle it. Instead I get the standard
>>> (ugly) XML, e.g.:
>>>
>>>     <ns1:XMLFault><ns1:faultstring>error
>>> message</ns1:faultstring></ns1:XMLFault>
>>>
>>> Is that the expected behavior? My server is set up like:
>>>
>>> <jaxrs:server id="service" address="/rest">
>>>         <jaxrs:serviceBeans>
>>>             <bean parent="myService" />
>>>         </jaxrs:serviceBeans>
>>>         <jaxrs:inInterceptors>
>>>             <ref bean="myInterceptor"/>
>>>         </jaxrs:inInterceptors>
>>>         <jaxrs:providers>
>>>             <ref bean="restExceptionMapper"/>
>>>         </jaxrs:providers>
>>> </jaxrs:server>
>>>
>>>
>>> And my interceptor looks like:
>>>
>>> public class MyInterceptor extends AbstractPhaseInterceptor<Message> {
>>>     public FormatSettingInterceptor() {
>>>         super(Phase.PRE_STREAM);
>>>     }
>>>
>>>     @Override
>>>     public void handleMessage(Message message) throws Fault {
>>>             throw new Fault("Not handled by ExceptionMapper!");
>>>     }
>>> }
>>>
>>> Any insight or help would be appreciated.
>>>
>>> Much thanks,
>>> Mike
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Fault-thrown-in-Rest-In-Interceptor-not-handled-by-ExceptionMapper-tp26833555p26834406.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Fault-thrown-in-Rest-In-Interceptor-not-handled-by-ExceptionMapper-tp26833555p26836759.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Fault thrown in Rest In-Interceptor not handled by ExceptionMapper

Posted by vickatvuuch <vl...@gmail.com>.
I put my fault out interceptor into the PRE_PROTOCOL phase and after
SOAPHandlerFaultOutInterceptor,
so I get the default processing and then step on the result of it as I find
fit depending on what comes
my way..


Mike O'Neil-2 wrote:
> 
> Thanks for your response. I gave this a shot and it seems to work
> pretty well, though is a lot more cumbersome, seeing as how we need to
> handle the marshalling directly. Unfortunately this also introduces a
> different place where an exception is not properly handled: when
> trying to find the target method in JAXRSUtils, if not found, a
> WebApplicationException is thrown but the custom fault out interceptor
> is not invoked. This results in an empty body in the HTTP response.
> Have you run into that?
> 
> Thanks for your help,
> Mike
> 
> On Thu, Dec 17, 2009 at 3:25 PM, vickatvuuch <vl...@gmail.com> wrote:
>>
>> I have had a similar problem and worked it around by building a
>> CustomFaultOutInterceptor,
>> which handles everything that gets thrown for both REST and SOAP. Once
>> you
>> have a single place to do it
>> you can translate Exception into HTTP response codes as well as you can
>> enchance
>> the default Soap fault as appropriate.
>>
>>
>> Mike O'Neil-2 wrote:
>>>
>>> I have an ExceptionMapper which handles exceptions from my Rest
>>> service just fine. However when my "In" Interceptor throws a Fault,
>>> the ExceptionMapper does not handle it. Instead I get the standard
>>> (ugly) XML, e.g.:
>>>
>>>     <ns1:XMLFault><ns1:faultstring>error
>>> message</ns1:faultstring></ns1:XMLFault>
>>>
>>> Is that the expected behavior? My server is set up like:
>>>
>>> <jaxrs:server id="service" address="/rest">
>>>         <jaxrs:serviceBeans>
>>>             <bean parent="myService" />
>>>         </jaxrs:serviceBeans>
>>>         <jaxrs:inInterceptors>
>>>             <ref bean="myInterceptor"/>
>>>         </jaxrs:inInterceptors>
>>>         <jaxrs:providers>
>>>             <ref bean="restExceptionMapper"/>
>>>         </jaxrs:providers>
>>> </jaxrs:server>
>>>
>>>
>>> And my interceptor looks like:
>>>
>>> public class MyInterceptor extends AbstractPhaseInterceptor<Message> {
>>>     public FormatSettingInterceptor() {
>>>         super(Phase.PRE_STREAM);
>>>     }
>>>
>>>     @Override
>>>     public void handleMessage(Message message) throws Fault {
>>>             throw new Fault("Not handled by ExceptionMapper!");
>>>     }
>>> }
>>>
>>> Any insight or help would be appreciated.
>>>
>>> Much thanks,
>>> Mike
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Fault-thrown-in-Rest-In-Interceptor-not-handled-by-ExceptionMapper-tp26833555p26834406.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Fault-thrown-in-Rest-In-Interceptor-not-handled-by-ExceptionMapper-tp26833555p26836730.html
Sent from the cxf-user mailing list archive at Nabble.com.


RE: Fault thrown in Rest In-Interceptor not handled by ExceptionMapper

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi

There is a default WebApplicationExceptionMapper out there which maps an exception into the Response. The empty body in this specific case is actually mandated by the JAX-RS spec. You can register your own custom 
WebApplicationExceptionMapper or you can register a custom ResponseHandler filter and override a Response returned by the default mapper

Sergey

-----Original Message-----
From: Mike O'Neil [mailto:mtoneil@gmail.com] 
Sent: 17 December 2009 21:12
To: users@cxf.apache.org
Subject: Re: Fault thrown in Rest In-Interceptor not handled by ExceptionMapper

Thanks for your response. I gave this a shot and it seems to work
pretty well, though is a lot more cumbersome, seeing as how we need to
handle the marshalling directly. Unfortunately this also introduces a
different place where an exception is not properly handled: when
trying to find the target method in JAXRSUtils, if not found, a
WebApplicationException is thrown but the custom fault out interceptor
is not invoked. This results in an empty body in the HTTP response.
Have you run into that?

Thanks for your help,
Mike

On Thu, Dec 17, 2009 at 3:25 PM, vickatvuuch <vl...@gmail.com> wrote:
>
> I have had a similar problem and worked it around by building a
> CustomFaultOutInterceptor,
> which handles everything that gets thrown for both REST and SOAP. Once you
> have a single place to do it
> you can translate Exception into HTTP response codes as well as you can
> enchance
> the default Soap fault as appropriate.
>
>
> Mike O'Neil-2 wrote:
>>
>> I have an ExceptionMapper which handles exceptions from my Rest
>> service just fine. However when my "In" Interceptor throws a Fault,
>> the ExceptionMapper does not handle it. Instead I get the standard
>> (ugly) XML, e.g.:
>>
>>     <ns1:XMLFault><ns1:faultstring>error
>> message</ns1:faultstring></ns1:XMLFault>
>>
>> Is that the expected behavior? My server is set up like:
>>
>> <jaxrs:server id="service" address="/rest">
>>         <jaxrs:serviceBeans>
>>             <bean parent="myService" />
>>         </jaxrs:serviceBeans>
>>         <jaxrs:inInterceptors>
>>             <ref bean="myInterceptor"/>
>>         </jaxrs:inInterceptors>
>>         <jaxrs:providers>
>>             <ref bean="restExceptionMapper"/>
>>         </jaxrs:providers>
>> </jaxrs:server>
>>
>>
>> And my interceptor looks like:
>>
>> public class MyInterceptor extends AbstractPhaseInterceptor<Message> {
>>     public FormatSettingInterceptor() {
>>         super(Phase.PRE_STREAM);
>>     }
>>
>>     @Override
>>     public void handleMessage(Message message) throws Fault {
>>             throw new Fault("Not handled by ExceptionMapper!");
>>     }
>> }
>>
>> Any insight or help would be appreciated.
>>
>> Much thanks,
>> Mike
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Fault-thrown-in-Rest-In-Interceptor-not-handled-by-ExceptionMapper-tp26833555p26834406.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>

Re: Fault thrown in Rest In-Interceptor not handled by ExceptionMapper

Posted by Mike O'Neil <mt...@gmail.com>.
Thanks for your response. I gave this a shot and it seems to work
pretty well, though is a lot more cumbersome, seeing as how we need to
handle the marshalling directly. Unfortunately this also introduces a
different place where an exception is not properly handled: when
trying to find the target method in JAXRSUtils, if not found, a
WebApplicationException is thrown but the custom fault out interceptor
is not invoked. This results in an empty body in the HTTP response.
Have you run into that?

Thanks for your help,
Mike

On Thu, Dec 17, 2009 at 3:25 PM, vickatvuuch <vl...@gmail.com> wrote:
>
> I have had a similar problem and worked it around by building a
> CustomFaultOutInterceptor,
> which handles everything that gets thrown for both REST and SOAP. Once you
> have a single place to do it
> you can translate Exception into HTTP response codes as well as you can
> enchance
> the default Soap fault as appropriate.
>
>
> Mike O'Neil-2 wrote:
>>
>> I have an ExceptionMapper which handles exceptions from my Rest
>> service just fine. However when my "In" Interceptor throws a Fault,
>> the ExceptionMapper does not handle it. Instead I get the standard
>> (ugly) XML, e.g.:
>>
>>     <ns1:XMLFault><ns1:faultstring>error
>> message</ns1:faultstring></ns1:XMLFault>
>>
>> Is that the expected behavior? My server is set up like:
>>
>> <jaxrs:server id="service" address="/rest">
>>         <jaxrs:serviceBeans>
>>             <bean parent="myService" />
>>         </jaxrs:serviceBeans>
>>         <jaxrs:inInterceptors>
>>             <ref bean="myInterceptor"/>
>>         </jaxrs:inInterceptors>
>>         <jaxrs:providers>
>>             <ref bean="restExceptionMapper"/>
>>         </jaxrs:providers>
>> </jaxrs:server>
>>
>>
>> And my interceptor looks like:
>>
>> public class MyInterceptor extends AbstractPhaseInterceptor<Message> {
>>     public FormatSettingInterceptor() {
>>         super(Phase.PRE_STREAM);
>>     }
>>
>>     @Override
>>     public void handleMessage(Message message) throws Fault {
>>             throw new Fault("Not handled by ExceptionMapper!");
>>     }
>> }
>>
>> Any insight or help would be appreciated.
>>
>> Much thanks,
>> Mike
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Fault-thrown-in-Rest-In-Interceptor-not-handled-by-ExceptionMapper-tp26833555p26834406.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>

Re: Fault thrown in Rest In-Interceptor not handled by ExceptionMapper

Posted by vickatvuuch <vl...@gmail.com>.
I have had a similar problem and worked it around by building a
CustomFaultOutInterceptor,
which handles everything that gets thrown for both REST and SOAP. Once you
have a single place to do it
you can translate Exception into HTTR response codes as well as you can
enchance 
default Soap fault as appropriate.


Mike O'Neil-2 wrote:
> 
> I have an ExceptionMapper which handles exceptions from my Rest
> service just fine. However when my "In" Interceptor throws a Fault,
> the ExceptionMapper does not handle it. Instead I get the standard
> (ugly) XML, e.g.:
> 
>     <ns1:XMLFault><ns1:faultstring>error
> message</ns1:faultstring></ns1:XMLFault>
> 
> Is that the expected behavior? My server is set up like:
> 
> <jaxrs:server id="service" address="/rest">
>         <jaxrs:serviceBeans>
>             <bean parent="myService" />
>         </jaxrs:serviceBeans>
>         <jaxrs:inInterceptors>
>             <ref bean="myInterceptor"/>
>         </jaxrs:inInterceptors>
>         <jaxrs:providers>
>             <ref bean="restExceptionMapper"/>
>         </jaxrs:providers>
> </jaxrs:server>
> 
> 
> And my interceptor looks like:
> 
> public class MyInterceptor extends AbstractPhaseInterceptor<Message> {
>     public FormatSettingInterceptor() {
>         super(Phase.PRE_STREAM);
>     }
> 
>     @Override
>     public void handleMessage(Message message) throws Fault {
>             throw new Fault("Not handled by ExceptionMapper!");
>     }
> }
> 
> Any insight or help would be appreciated.
> 
> Much thanks,
> Mike
> 
> 

-- 
View this message in context: http://old.nabble.com/Fault-thrown-in-Rest-In-Interceptor-not-handled-by-ExceptionMapper-tp26833555p26834406.html
Sent from the cxf-user mailing list archive at Nabble.com.