users@jersey.java.net

Re: [Jersey] A custom ResourceMethodDispatchProvider ...

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 20 May 2008 12:22:24 +0200

Hi Thierry,

Well found!

The order of checking dispatch providers was changed after 0.7, so you
should be able to override that of EntityParamDispatchProvider, if you
get the latest 0.8 build (note that the package name space
"com.sun.ws.rest" has been renamed to "com.sun.jersey").

We have used this trick for experimenting with precondition support
using Scala partial functions [1] (or closures). And for experimenting
with Comet support.

The reason why it is not exposed out as an SPI yet is i think it needs
some more design work to make it easier to use. Any feedback on this
would be much appreciated.

Paul.

[1] http://blogs.sun.com/sandoz/entry/using_scala_s_closures_with

Thierry Granger wrote:
> 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
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109