|
From: Martin A. <sp...@ma...> - 2008-07-10 15:36:58
|
Why is the interception done on a (for a lack of better word)
"global" level rather than for the resource method. When I first read
your description I envisaged something like what I'm describing below
- or am I getting it all wrong?
public class MyResource
{
@GET
@Path("{myId}")
@BeforeMarshalling(MyInterceptor.class)
@AfterMarshalling(MyInterceptor.class)
public SomeObject loadSomethingCool( @PathParam("myId") int myId )
{
}
}
Could also envisage putting the interceptor annotations on the class
to work for all methods in the class.
public class MyInterceptor implements BeforeMarshallingInterecptor,
AfterMarshallingInterceptor
{
public void onBeforeMarshalling( Method method, Map<String,Object>
arguments )
{
}
public void onAfterMarshalling( Method method, Map<String,Object>
arguments )
{
}
}
M
On 10 Jul 2008, at 15:05, Bill Burke wrote:
> Not along at all... Wanted to ping here first. The injection is
> easy.
> Already have utilities for that.
>
> Ryan J. McDonough wrote:
>> I like it! And I see where you're going with it. I think this will
>> provide a ton of flexibility in the app. I can see a lot of
>> opportunities for this kind of feature. How far along are with it?
>>
>> Ryan-
>>
>>
>> On Jul 9, 2008, at 6:53 PM, Bill Burke wrote:
>>
>>> I'm currently prototyping some asynchronous jax-rs based on some
>>> of the
>>> asynchronous talk in the Restful Web Services book. At first I
>>> implemented it in a non-abstract fashion. Just brute force as I
>>> wanted
>>> to see what patterns came up. After this I realized that I
>>> needed some
>>> form of interception to implement it. (Mainly because of security).
>>>
>>> So, for interception here's some ideas:
>>>
>>> * Interceptors will be internal and not supported. (I want us to
>>> write
>>> a few before we even allow users to try them out).
>>>
>>> * interception would happen based on what additional annotation you
>>> provided: @BeforeUnmarshalling, @AfterUnmarshalling,
>>> @BeforeMarshalling,
>>> and @Aftermarshalling.
>>>
>>> * Interceptors will not be called for any subresource locator
>>> methods.
>>>
>>> * You would be able to use any JAX-RS annotation within the
>>> intercept
>>> method.
>>>
>>> * It is an "around" pattern (like EJB's @AroundInvoke
>>>
>>> interface RequestContext
>>> {
>>> void invokeNext();
>>> }
>>>
>>> * You must inject and call invokeNext() on a RequestContext or no
>>> other
>>> interceptors will be called, and the request will not be dispatched.
>>>
>>> * You will be able to inject the ResourceMethod object so you can
>>> get
>>> preprocessed information about the method you are invoking on
>>> (annotations, etc...)
>>>
>>>
>>> So here's an example:
>>>
>>> @Provider
>>> @Interceptor
>>> public class CacheControlInterceptor
>>> {
>>> @BeforeUnmarshalling(@Context HttpRequest request,
>>> @Context HttpResponse response,
>>> @Context RequestContext ctx)
>>> {
>>> if (isCached(request)) {
>>> writeCachedResponse(request, response);
>>> return; // don't continue with dispatching
>>> }
>>> return invokeNext();
>>> }
>>>
>>>
>>> @BeforeMarshalling
>>> public void writeCacheControlHeaders(@Context HttpResponse
>>> response
>>> @Context RequestContext ctx)
>>> {
>>> ... write some cache control headers...
>>> }
>>>
>>> @AfterMarshalling
>>> public void grabBytesToMarshall(@Context HttpResponse response
>>> @Context RequestContext) {
>>> }
>>> }
>>>
>>>
>>>
>>> --
>>> Bill Burke
>>> JBoss, a division of Red Hat
>>> http://bill.burkecentral.com
>>>
>>> --------------------------------------------------------------------
>>> -----
>>> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
>>> Studies have shown that voting for your favorite open source
>>> project,
>>> along with a healthy diet, reduces your potential for chronic
>>> lameness
>>> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
>>> _______________________________________________
>>> Resteasy-developers mailing list
>>> Res...@li...
>>> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
>>
>
> --
> Bill Burke
> JBoss, a division of Red Hat
> http://bill.burkecentral.com
>
> ----------------------------------------------------------------------
> ---
> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
> Studies have shown that voting for your favorite open source project,
> along with a healthy diet, reduces your potential for chronic lameness
> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
> _______________________________________________
> Resteasy-developers mailing list
> Res...@li...
> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
|