lundi 8 juin 2015

Setting response header using interceptor?

I'm writing jax-rs end points. For some set of end points (existing code), I want to set an extra response header which was actually generated in @AroundInvoke interceptor and set to HttpServletRequest attribute. In @AroundInvoke I'm able to access HttpServletRequest using @Inject. But it seems I cannot access HttpServletResponse in the same interceptor itself.

It seems I can do with PostProcessorInterceptor but again I'm confused with the following doc.

The org.jboss.resteasy.spi.interception.PostProcessInterceptor runs after the JAX-RS method was invoked but before MessageBodyWriters are invoked. They can only be used on the server side. Use them if you need to set a response header when there might not be any MessageBodyWriter invoked.

I'm using resteasy, jackson. If I use PostProcessorInterceptor can I inject HttpServletResponse? Or Can I set new http header there some how?

Any code example/direction would be appreciated.

Aucun commentaire:

Enregistrer un commentaire