Perhaps what you need is a Container or Resource filter. See here:
http://jersey.java.net/nonav/apidocs/1.13/jersey/com/sun/jersey/spi/container/ContainerRequestFilter.html
http://jersey.java.net/nonav/apidocs/1.13/jersey/com/sun/jersey/spi/container/ResourceFilter.html
HTH,
Marek
On Aug 1, 2012, at 8:45 AM, noam_at_10ne.org wrote:
> 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