cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <>
Subject Re: (JAX-RS) Mapping params to custom types
Date Fri, 16 Dec 2011 10:00:18 GMT
Hi Brice
On 15/12/11 20:04, Brice wrote:
> Hi Sergey,
> I think I hit another issue. I think I got a workaround, yet I'm not sure it is the best
way to do this. But first I'll explain the faced problem :
> I would like to map some exception that might be raised during the message handling,
some raised by the invoker; so an ExceptionMapper could fit in with some elegance.
> However, in my Response I would like to get some "technical" data that will most probably
located on an annotation aside the other JAXRS annotations (@GET, @Path, etc.).
> But the signature is "Response toResponse(Exception)", so I don't have any information
on the targeted object.

You can get CXF-specific MessageContext injected in that mapper and use 
messageContext.getContextualProperty(OperationResourceInfo.class); and
OperationResourceInfo.getAnnotatedMethod will return Method with the 
annotations, you can get to the class-level annotations from there too 
if needed

> Also I don't have a Response for this exxcpetion when an exception occur in "JAXRSInInterceptor.handelMessage(Message)"
then I might loose all the proxies information (thread local is cleared).
JAXRSInInterceptor checks ExceptionMappers if the exception is thrown 
during handleMessage(Message)
> So the workaround would be to also have a RequestHandler :
>   - the "ExceptionMapper" will create a Response with an incomplete entity
>   - the "RequestHandler" in the "handleResponse(Message, OperationResourceInfo, Response)"
might be able create a new Response from the original and to "enhance" the entity with the
information from the annotations. The annotation will be accessed through : "message.getExchange().get(OperationResourceInfo.class).getMethodToInvoke().getAnnotation(SomeCustomAnnotation.class)".
> In my opinion this approach looks a wrong, but yet again it is a neophyte workaround.

This is possible, why not, but hope the above hint re 
OperationResourceInfo can make it a bit simpler

Cheers, Sergey

> What do you think ? Would it be possible to achieve a better and simpler solution than
having to split this logic ?
> Thanks again for your time and consideration :)
> --
> Brice

View raw message