|
From: Bill B. <bb...@re...> - 2008-07-09 22:51:34
|
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
|