You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by James Carman <ja...@carmanconsulting.com> on 2015/09/18 19:09:54 UTC
ClientResponseFilter and Customized Error Messages...
I've got a REST service that returns error messages as JSON like this:
{
"errorMessages": ["foo", "bar"]
}
When I create a client proxy and call that service, I don't see any error
message in the exceptions (I might get a NotFoundException with no message
for instance). That's understandable, since how in the heck would CXF know
how to convert my JSON into something readable? Anyway, I would like to
help CXF along here and get the right error message to it (maybe "foo, bar"
in the above example) so that it can include it in the constructor for
NotFoundException. I'm thinking ClientResponseFilter might be the way to
go, but thought I'd check in with you guys before I go too far down the
rabbit hole. I've tried throwing an exception from my "filter" method and
CXF doesn't appear to really like that idea. Any thoughts/guidance?
Thanks,
James
Re: ClientResponseFilter and Customized Error Messages...
Posted by James Carman <ja...@carmanconsulting.com>.
Standard would mean using the JAX-RS API, but I see your point about the
proxies themselves not being standard, so it's somewhat moot.
On Mon, Sep 21, 2015 at 5:26 AM Sergey Beryozkin <sb...@gmail.com>
wrote:
> What is a standard way in your view ? Convert JSON messages into a
> standard exception's message ?
> JAX-RS 2.0 API does offer you a standard way, by reading the message
> from the exception's response but that is not good for you so CXF
> offers you an option to manage it with its providers - true that is not
> standard, but the actual proxy approach is not standard either
>
> Sergey
>
> On 20/09/15 23:07, James Carman wrote:
> > No "standard" way to do it, though :(.
> > On Sun, Sep 20, 2015 at 7:37 AM Sergey Beryozkin <sb...@gmail.com>
> > wrote:
> >
> >> If you using proxies: register ResponseExceptionMapper as a provider
> >> when creating proxies
> >>
> >> Sergey
> >> On 18/09/15 23:39, James Carman wrote:
> >>> Is there nothing I can do to just have the exception message in the
> >>> exception itself without having to do the extraction? I don't want to
> put
> >>> this burden on my clients. The clients are generating proxy is using
> the
> >>> rest interface
> >>> On Fri, Sep 18, 2015 at 5:11 PM Sergey Beryozkin <sberyozkin@gmail.com
> >
> >>> wrote:
> >>>
> >>>> Hi
> >>>>
> >>>> I think you can catch NotFoundException, and then do
> >>>> ex.getResponse().readEntity(String.class) or may be
> >>>>
> >>>> ex.getResponse().readEntity(ErrorResponses.class)
> >>>>
> >>>> where a registered Jackson/etc provider will convert JSON to
> >>>> ErrorResponses bean - assuming the error response has Content-Type
> set.
> >>>>
> >>>> I know you can block a request on the client side from
> >>>> ClientRequestFilter and return Response thus emulating various server
> >>>> responses.
> >>>>
> >>>> I believe the exceptions thrown from ClientResponseFilter are wrapped
> >>>> into ResponseProcessingException which points to a client side
> response
> >>>> processing issue
> >>>>
> >>>> Cheers, Sergey
> >>>>
> >>>> On 18/09/15 18:09, James Carman wrote:
> >>>>> I've got a REST service that returns error messages as JSON like
> this:
> >>>>>
> >>>>> {
> >>>>> "errorMessages": ["foo", "bar"]
> >>>>> }
> >>>>>
> >>>>> When I create a client proxy and call that service, I don't see any
> >> error
> >>>>> message in the exceptions (I might get a NotFoundException with no
> >>>> message
> >>>>> for instance). That's understandable, since how in the heck would
> CXF
> >>>> know
> >>>>> how to convert my JSON into something readable? Anyway, I would like
> >> to
> >>>>> help CXF along here and get the right error message to it (maybe
> "foo,
> >>>> bar"
> >>>>> in the above example) so that it can include it in the constructor
> for
> >>>>> NotFoundException. I'm thinking ClientResponseFilter might be the
> way
> >> to
> >>>>> go, but thought I'd check in with you guys before I go too far down
> the
> >>>>> rabbit hole. I've tried throwing an exception from my "filter"
> method
> >>>> and
> >>>>> CXF doesn't appear to really like that idea. Any thoughts/guidance?
> >>>>>
> >>>>> Thanks,
> >>>>>
> >>>>> James
> >>>>>
> >>>>
> >>>>
> >>>> --
> >>>> Sergey Beryozkin
> >>>>
> >>>> Talend Community Coders
> >>>> http://coders.talend.com/
> >>>>
> >>>
> >>
> >>
> >> --
> >> Sergey Beryozkin
> >>
> >> Talend Community Coders
> >> http://coders.talend.com/
> >>
> >
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
Re: ClientResponseFilter and Customized Error Messages...
Posted by Sergey Beryozkin <sb...@gmail.com>.
What is a standard way in your view ? Convert JSON messages into a
standard exception's message ?
JAX-RS 2.0 API does offer you a standard way, by reading the message
from the exception's response but that is not good for you so CXF
offers you an option to manage it with its providers - true that is not
standard, but the actual proxy approach is not standard either
Sergey
On 20/09/15 23:07, James Carman wrote:
> No "standard" way to do it, though :(.
> On Sun, Sep 20, 2015 at 7:37 AM Sergey Beryozkin <sb...@gmail.com>
> wrote:
>
>> If you using proxies: register ResponseExceptionMapper as a provider
>> when creating proxies
>>
>> Sergey
>> On 18/09/15 23:39, James Carman wrote:
>>> Is there nothing I can do to just have the exception message in the
>>> exception itself without having to do the extraction? I don't want to put
>>> this burden on my clients. The clients are generating proxy is using the
>>> rest interface
>>> On Fri, Sep 18, 2015 at 5:11 PM Sergey Beryozkin <sb...@gmail.com>
>>> wrote:
>>>
>>>> Hi
>>>>
>>>> I think you can catch NotFoundException, and then do
>>>> ex.getResponse().readEntity(String.class) or may be
>>>>
>>>> ex.getResponse().readEntity(ErrorResponses.class)
>>>>
>>>> where a registered Jackson/etc provider will convert JSON to
>>>> ErrorResponses bean - assuming the error response has Content-Type set.
>>>>
>>>> I know you can block a request on the client side from
>>>> ClientRequestFilter and return Response thus emulating various server
>>>> responses.
>>>>
>>>> I believe the exceptions thrown from ClientResponseFilter are wrapped
>>>> into ResponseProcessingException which points to a client side response
>>>> processing issue
>>>>
>>>> Cheers, Sergey
>>>>
>>>> On 18/09/15 18:09, James Carman wrote:
>>>>> I've got a REST service that returns error messages as JSON like this:
>>>>>
>>>>> {
>>>>> "errorMessages": ["foo", "bar"]
>>>>> }
>>>>>
>>>>> When I create a client proxy and call that service, I don't see any
>> error
>>>>> message in the exceptions (I might get a NotFoundException with no
>>>> message
>>>>> for instance). That's understandable, since how in the heck would CXF
>>>> know
>>>>> how to convert my JSON into something readable? Anyway, I would like
>> to
>>>>> help CXF along here and get the right error message to it (maybe "foo,
>>>> bar"
>>>>> in the above example) so that it can include it in the constructor for
>>>>> NotFoundException. I'm thinking ClientResponseFilter might be the way
>> to
>>>>> go, but thought I'd check in with you guys before I go too far down the
>>>>> rabbit hole. I've tried throwing an exception from my "filter" method
>>>> and
>>>>> CXF doesn't appear to really like that idea. Any thoughts/guidance?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> James
>>>>>
>>>>
>>>>
>>>> --
>>>> Sergey Beryozkin
>>>>
>>>> Talend Community Coders
>>>> http://coders.talend.com/
>>>>
>>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> Talend Community Coders
>> http://coders.talend.com/
>>
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Re: ClientResponseFilter and Customized Error Messages...
Posted by James Carman <ja...@carmanconsulting.com>.
No "standard" way to do it, though :(.
On Sun, Sep 20, 2015 at 7:37 AM Sergey Beryozkin <sb...@gmail.com>
wrote:
> If you using proxies: register ResponseExceptionMapper as a provider
> when creating proxies
>
> Sergey
> On 18/09/15 23:39, James Carman wrote:
> > Is there nothing I can do to just have the exception message in the
> > exception itself without having to do the extraction? I don't want to put
> > this burden on my clients. The clients are generating proxy is using the
> > rest interface
> > On Fri, Sep 18, 2015 at 5:11 PM Sergey Beryozkin <sb...@gmail.com>
> > wrote:
> >
> >> Hi
> >>
> >> I think you can catch NotFoundException, and then do
> >> ex.getResponse().readEntity(String.class) or may be
> >>
> >> ex.getResponse().readEntity(ErrorResponses.class)
> >>
> >> where a registered Jackson/etc provider will convert JSON to
> >> ErrorResponses bean - assuming the error response has Content-Type set.
> >>
> >> I know you can block a request on the client side from
> >> ClientRequestFilter and return Response thus emulating various server
> >> responses.
> >>
> >> I believe the exceptions thrown from ClientResponseFilter are wrapped
> >> into ResponseProcessingException which points to a client side response
> >> processing issue
> >>
> >> Cheers, Sergey
> >>
> >> On 18/09/15 18:09, James Carman wrote:
> >>> I've got a REST service that returns error messages as JSON like this:
> >>>
> >>> {
> >>> "errorMessages": ["foo", "bar"]
> >>> }
> >>>
> >>> When I create a client proxy and call that service, I don't see any
> error
> >>> message in the exceptions (I might get a NotFoundException with no
> >> message
> >>> for instance). That's understandable, since how in the heck would CXF
> >> know
> >>> how to convert my JSON into something readable? Anyway, I would like
> to
> >>> help CXF along here and get the right error message to it (maybe "foo,
> >> bar"
> >>> in the above example) so that it can include it in the constructor for
> >>> NotFoundException. I'm thinking ClientResponseFilter might be the way
> to
> >>> go, but thought I'd check in with you guys before I go too far down the
> >>> rabbit hole. I've tried throwing an exception from my "filter" method
> >> and
> >>> CXF doesn't appear to really like that idea. Any thoughts/guidance?
> >>>
> >>> Thanks,
> >>>
> >>> James
> >>>
> >>
> >>
> >> --
> >> Sergey Beryozkin
> >>
> >> Talend Community Coders
> >> http://coders.talend.com/
> >>
> >
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
Re: ClientResponseFilter and Customized Error Messages...
Posted by Sergey Beryozkin <sb...@gmail.com>.
If you using proxies: register ResponseExceptionMapper as a provider
when creating proxies
Sergey
On 18/09/15 23:39, James Carman wrote:
> Is there nothing I can do to just have the exception message in the
> exception itself without having to do the extraction? I don't want to put
> this burden on my clients. The clients are generating proxy is using the
> rest interface
> On Fri, Sep 18, 2015 at 5:11 PM Sergey Beryozkin <sb...@gmail.com>
> wrote:
>
>> Hi
>>
>> I think you can catch NotFoundException, and then do
>> ex.getResponse().readEntity(String.class) or may be
>>
>> ex.getResponse().readEntity(ErrorResponses.class)
>>
>> where a registered Jackson/etc provider will convert JSON to
>> ErrorResponses bean - assuming the error response has Content-Type set.
>>
>> I know you can block a request on the client side from
>> ClientRequestFilter and return Response thus emulating various server
>> responses.
>>
>> I believe the exceptions thrown from ClientResponseFilter are wrapped
>> into ResponseProcessingException which points to a client side response
>> processing issue
>>
>> Cheers, Sergey
>>
>> On 18/09/15 18:09, James Carman wrote:
>>> I've got a REST service that returns error messages as JSON like this:
>>>
>>> {
>>> "errorMessages": ["foo", "bar"]
>>> }
>>>
>>> When I create a client proxy and call that service, I don't see any error
>>> message in the exceptions (I might get a NotFoundException with no
>> message
>>> for instance). That's understandable, since how in the heck would CXF
>> know
>>> how to convert my JSON into something readable? Anyway, I would like to
>>> help CXF along here and get the right error message to it (maybe "foo,
>> bar"
>>> in the above example) so that it can include it in the constructor for
>>> NotFoundException. I'm thinking ClientResponseFilter might be the way to
>>> go, but thought I'd check in with you guys before I go too far down the
>>> rabbit hole. I've tried throwing an exception from my "filter" method
>> and
>>> CXF doesn't appear to really like that idea. Any thoughts/guidance?
>>>
>>> Thanks,
>>>
>>> James
>>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> Talend Community Coders
>> http://coders.talend.com/
>>
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Re: ClientResponseFilter and Customized Error Messages...
Posted by James Carman <ja...@carmanconsulting.com>.
Is there nothing I can do to just have the exception message in the
exception itself without having to do the extraction? I don't want to put
this burden on my clients. The clients are generating proxy is using the
rest interface
On Fri, Sep 18, 2015 at 5:11 PM Sergey Beryozkin <sb...@gmail.com>
wrote:
> Hi
>
> I think you can catch NotFoundException, and then do
> ex.getResponse().readEntity(String.class) or may be
>
> ex.getResponse().readEntity(ErrorResponses.class)
>
> where a registered Jackson/etc provider will convert JSON to
> ErrorResponses bean - assuming the error response has Content-Type set.
>
> I know you can block a request on the client side from
> ClientRequestFilter and return Response thus emulating various server
> responses.
>
> I believe the exceptions thrown from ClientResponseFilter are wrapped
> into ResponseProcessingException which points to a client side response
> processing issue
>
> Cheers, Sergey
>
> On 18/09/15 18:09, James Carman wrote:
> > I've got a REST service that returns error messages as JSON like this:
> >
> > {
> > "errorMessages": ["foo", "bar"]
> > }
> >
> > When I create a client proxy and call that service, I don't see any error
> > message in the exceptions (I might get a NotFoundException with no
> message
> > for instance). That's understandable, since how in the heck would CXF
> know
> > how to convert my JSON into something readable? Anyway, I would like to
> > help CXF along here and get the right error message to it (maybe "foo,
> bar"
> > in the above example) so that it can include it in the constructor for
> > NotFoundException. I'm thinking ClientResponseFilter might be the way to
> > go, but thought I'd check in with you guys before I go too far down the
> > rabbit hole. I've tried throwing an exception from my "filter" method
> and
> > CXF doesn't appear to really like that idea. Any thoughts/guidance?
> >
> > Thanks,
> >
> > James
> >
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
Re: ClientResponseFilter and Customized Error Messages...
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
I think you can catch NotFoundException, and then do
ex.getResponse().readEntity(String.class) or may be
ex.getResponse().readEntity(ErrorResponses.class)
where a registered Jackson/etc provider will convert JSON to
ErrorResponses bean - assuming the error response has Content-Type set.
I know you can block a request on the client side from
ClientRequestFilter and return Response thus emulating various server
responses.
I believe the exceptions thrown from ClientResponseFilter are wrapped
into ResponseProcessingException which points to a client side response
processing issue
Cheers, Sergey
On 18/09/15 18:09, James Carman wrote:
> I've got a REST service that returns error messages as JSON like this:
>
> {
> "errorMessages": ["foo", "bar"]
> }
>
> When I create a client proxy and call that service, I don't see any error
> message in the exceptions (I might get a NotFoundException with no message
> for instance). That's understandable, since how in the heck would CXF know
> how to convert my JSON into something readable? Anyway, I would like to
> help CXF along here and get the right error message to it (maybe "foo, bar"
> in the above example) so that it can include it in the constructor for
> NotFoundException. I'm thinking ClientResponseFilter might be the way to
> go, but thought I'd check in with you guys before I go too far down the
> rabbit hole. I've tried throwing an exception from my "filter" method and
> CXF doesn't appear to really like that idea. Any thoughts/guidance?
>
> Thanks,
>
> James
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/