users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: ContainerResponseFilter question

From: Jan Algermissen <jan.algermissen_at_nordsc.com>
Date: Mon, 24 Sep 2012 13:19:21 +0200

On Sep 24, 2012, at 1:10 PM, Jan Algermissen wrote:

>
> On Sep 24, 2012, at 1:03 PM, Sergey Beryozkin wrote:
>
>> Hi
>> On 24/09/12 11:38, Jan Algermissen wrote:
>>> Hi,
>>>
>>> playing with ContainerResponseContext I wonder whether there is a way to determin in a ContainerResponseFilter which resource method has handled the request and led to the invocation of the given filter.
>>>
>>> What I'd like to do is to access the annotations of that resource method.
>>>
>>> For example, in order to do sth like this:
>>>
>>> @Provider
>>> @Cacheable
>>> public class AddCacheControlFilter implements ContainerResponseFilter {
>>>
>>> @Override
>>> public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
>>> throws IOException {
>>>
>>> String cc = .... determine cache control info from use of @Cacheable on resource method
>>> if(cc != null&& !cc.equals("") {
>>> responseContext.getHeaders().add("Cache-Control", cc);
>>> }
>>> }
>>> }
>>>
>>> and on the resource method:
>>>
>>>
>>> @GET
>>> @Cacheable(cacheControl="maxAge=60")
>>> @Produces(MediaType.TEXT_PLAIN)
>>> public String getIt() {
>>> return "This won't change the next 60 seconds...";
>>> }
>>>
>>>
>>> So far, I cannot see a way to access information about what method handled the request... or am I mistaken?
>>
>> perhaps ContainerResponseContext.getEntityAnnotations() is what you are looking for...
>
> I sawe those, but do they inlcude annotations on the handling resource methode??

Checked it: in Jersey they do.

Question: what documentation am I missing?

"Get the annotations attached to the entity"[1] apparently gave me the wrong impression.

Thanks anyhow.


Jan

[1] <http://jax-rs-spec.java.net/nonav/2.0-SNAPSHOT/apidocs/javax/ws/rs/container/ContainerResponseContext.html#getEntityAnnotations()>


>
> Jan
>
>>
>>
>> Cheers, Sergey
>>
>>>
>>> Jan
>>>
>>>
>>>
>>
>>
>