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. 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). 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. 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 Le jeudi 15 décembre 2011 à 09:51, Brice a écrit : > Hi, > > OK, thx Sergey, it's more clearer now. And Imissed the .entity method > yesterday. > > Thank you for your support :) > > Regards, > > -- > Brice > > > Le mercredi 14 décembre 2011 à 18:22, Sergey Beryozkin a écrit : > > > On 14/12/11 16:51, Brice wrote: > > > Hi > > > > > > > > > Thanx for your answers :) > > > > > > I got some more question on the ResponseHandler. > > > > > > -- > > > Brice > > > > > > > > > Le mercredi 14 décembre 2011 à 12:41, Sergey Beryozkin a écrit : > > > > > > > Hi > > > > On 14/12/11 09:49, Brice Dutheil wrote: > > > > > Hi, > > > > > > > > > > I would like some advice or help in designing a new REST service. > > > > > > > > > > I'm using CXF to serve REST webservices. I already have a custom > > > > > interceptors, however I'm not sure how to deal with the following. > > > > > > > > > > > > > > > Is it possible to 'map' HeaderParams (or FormParam, QueryParam, > > > > > PathParam) > > > > > to custom Java types, instead of a simple string. > > > > > > > > > > > > > > > > > > > > > Have a look here please: > > > > http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-DealingwithParameters > > > > > > > > JAX-RS offers one option: if a type has one of the factory methods then > > > > it will be used; otherwise the CXF ParameterHandler extension will help > > > > > > > > > > Ok, thx, I missed that page when focusing on interceptors. > > > > > > > > > And eventually answer > > > > > something else if the value of the param is not valid. > > > > > > > > > > For example the HTTP Header "Accept-Language" can have several string > > > > > values, I would like to map those values to a List<Locale> in order to > > > > > write methods like the one below : > > > > > > > > > > @GET > > > > > @Path("/check/stuff/{id}") > > > > > public CustomAnswer > > > > > checkStuffAndAnswerInAcceptedLanguage(@PathParam("id") > > > > > int id, @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) List<Locale> > > > > > locales) { > > > > > // business stuff > > > > > } > > > > > > > > > > > > > > > > > > > > > I'd recommend injecting HttpHeaders and use its getAcceptableLanguages > > > > method which will a properly sorted List<Locale>; the above will also > > > > work but it's not guaranteed to be sorted AFAIK and a Locale constructor > > > > accepting a single String will be used which will miss on local values > > > > such as 'us' in 'en-us', etc > > > > > > > > > > Yes indeed, before your reply I was planning to use LocaleUtils from > > > commons-lang. The locale was also just an example we will have more > > > custom headers maybe. Anyway the page seems to explain this case. > > > > > > > > > > > > > > Also if the locales are incorrect then answer with a custom response > > > > > (in > > > > > JSON or XML), I'm not sure if I should use the JAXRS response builder > > > > > or > > > > > rely on a provider (we are using GSon in a provider). > > > > > > > > > > > > > > > > > Using custom Response, or out filter (ResponseHandler), ExceptionMapper > > > > and even custom MBW will work > > > > > > > > > > I'm not sure to follow you there, the JAX-RS Response class cannot > > > receive a body. > > > Does the ResponseHandler message parameter is the response payload/body ? > > > On which we can feed an JSon content? > > > > > > > > > This time it is my turn to be confused :-) > > Basically what I was saying you can use one of the options I listed in > > order to produce a custom response: do return > > Response.status(status).entity(customEntity).build() or get the filter > > overwrite it or throw an exception and get ExceptionMapper producing the > > response > > > > > Does the ExceptionMapper works if I throw something before the INVOKE > > > phase ? > > > > No, ExceptionMappers are checked only if exceptions got originated from > > the JAX-RS-managed (JAX-RS filters, invoker, the runtime itself, > > application code) but you can manage the exceptions at the level of CXF > > interceptors by registering a custom fault out interceptor > > > > Cheers, Sergey > > > > > > > > > > > > > HTH, Sergey > > > > > > > > > > > > > > Thanx in advance for your input. > > > > > > > > > > > > -- > > > > Sergey Beryozkin > > > > > > > > Talend Community Coders > > > > http://coders.talend.com/ > > > > > > > > Blog: http://sberyozkin.blogspot.com >
