users@jersey.java.net

[Jersey] Providing a DispatchingListener with UriRuleContext

From: <noam_at_10ne.org>
Date: Wed, 1 Aug 2012 06:45:17 +0000 (GMT)

Hi All,

I'm looking for a way to inspect the details of a request and the
requested resource method just before invocation (with an option to
abort the request if my inspection detects an invalidity).

For example, I've got a group of different resources on different paths
that all receive a parameter of type "foo" in one way or another (query
param, path param, etc); I would like to receive an event right before
each resource is invoked so that I can check whether it expects a "foo"
parameter, and if it does, to perform certain assertions in regard to
the value of "foo".

I've created an implementation of
com.sun.jersey.spi.monitoring.DispatchingListener because the
onResourceMethod seems to be a perfect fit for this situation.

My only problem is that the listener is not provided with the context
of the request; that is, onResourceMethod is provided with an
AbstractResourceMethod which gives me all the details I need about the
method to be invoked, but I've got no idea what has been sent by the
user.

I might be mistaken in this assumption, but since the listener must
exist as a singleton, it looks like I can't inject the request context
as I normally would with a resource.

Reviewing the code, I see that onResourceMethod is eventually called
from com.sun.jersey.server.impl.uri.rules.HttpMethodRule#accept, and
that the request context does in fact exist at this stage, but it isn't
being passed to the listener.

Is there any way to provide the listener with the request context?
Am I taking the right approach to this?

Thanks