users@jersey.java.net

A custom ResourceMethodDispatchProvider ...

From: Thierry Granger <grangert_at_yahoo-inc.com>
Date: Mon, 19 May 2008 18:55:14 +0200

Hi all,

I'm using the jersey 0.7-ea, and I would like to perform some specific
tasks using the computed parameters (ie: Object unmarshalled by JAXB, or
query string parameters) before calling the resource method.
For example,
   * I would like to check some credentials depending on the URI (for
HTTP GET method) or depending on the XML content (for HTTP PUT/POST
method).
   * I would like to dynamically modify some query string parameter, or
xml content.
   * ...

I was first thinking to use some ServletFilter, but in some case, that
would mean we would perform twice the JAXB unmarshalling ... So, I
investigate deeply into the jersey code, and I found the
EntityParamDispatchProvider.java
(https://jersey.dev.java.net/source/browse/jersey/tags/jersey-0.7/jersey/src/impl/com/sun/ws/rest/impl/model/method/dispatch/EntityParamDispatchProvider.java?rev=954&view=markup),
and I saw that there is some "_dispatch()" method that deals with the
parameters, the context, and the resource (in fact everything I need to
perform my specific task :) ).

So, here are my questions :
    * Am I looking to the good solution ? I mean, is there an easier way
to deal with the parameters, the context, and the resource before the
resource method call ?
    * Is there any way to inject a custom ResourceMethodDispatchProvider
in replacement of the EntityParamDispatchProvider, or add a custom
ResourceMethodDispatchProvider and manage the order of the lookup into
the ResourceMethodDispatcherFactory.create method ?

I added my class name into my own
META-INF/services/com.sun.ws.rest.impl.model.method.dispatch.ResourceMethodDispatchProvider
file, but my class is never use because the EntityParamDispatchProvider
instance is always returned by the ResourceMethodDispatcherFactory
before my custom ResourceMethodDispatchProvider. (I think that's because
of the "rmdps.addFirst(rmdp);' line.

I guess my questions are clear :) (it's not very easy to express my
needs in English)

Regards,

Thierry