users@jersey.java.net

[Jersey] Re: Method Dispatcher

From: Paul <nibin.cse_at_gmail.com>
Date: Tue, 14 Jun 2011 00:08:39 -0700 (PDT)

If you want to provide your own Method dispatcher, you have to implement
"com.sun.jersey.spi.container.ResourceMethodDispatchProvider".

By default, Jersey supports 5 implementations for this.

com.sun.jersey.server.impl.model.method.dispatch.VoidVoidDispatchProvider
com.sun.jersey.server.impl.model.method.dispatch.HttpReqResDispatchProvider
com.sun.jersey.server.impl.model.method.dispatch.MultipartFormDispatchProvider
com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider
com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider

You can implement your own ResourceMethodDispatchProvider and plugin to the
Jersey framework.

For doing that, you need to modify the
jersey-server-1.6.jar\META-INF\services\com.sun.jersey.spi.container.ResourceMethodDispatchProvider
file. Use your implementation classes instead using Jersey's default
implementation.

Or if you don't want to change the jersey-server.jar, you can mark your
dispatchProvider implementations with @Provider annotation, Jersey then
tries to use these implementations also for creating the RequestDispatcher.

And I think Provider classes have more precedence than the service classes.
So I guess your implementations should have more priority.

Another alternative solution
--------------------------
If you are going to implement RequestDispatcher, you might need to implement
atleast 7 implementations for "RequestDispatcher" and 5 implementations for
"ResourceMethodDispatchProvider" for getting all the funcationalities of
Jersey. And the authorization code will be the same in all
"RequestDispatcher" implementations. Even if you use decorator pattern for
providing authorization, you have to implement 5
"ResourceMethodDispatchProvider".

So I feel a better way to have custom authorization is to use Dynamic
proxies. So instead of Jersey directly invoking the methods on the resource
instance, it should invoke methods on a proxy instance. To achieve this you
have to inject the proxy instance, instead of the actual resource instance.

For that you have to implement your own "ResourceComponentProviderFactory"
and "ResourceComponentProvider". In the "ResourceComponentProvider"
implementation return the proxy instance. By default Jersey uses
"PerRequestFactory" and "PerRequest". Instead of these you might want to use
your implementations.

For plugging in your "ResourceComponentProviderFactory", you can annotate
your resource class with "ResourceComponentProviderFactoryClass" annotation.
So instead of the default, "PerRequestFactory" your implementation clas will
be used.

Regards,
Paul

--
View this message in context: http://jersey.576304.n2.nabble.com/Method-Dispatcher-tp6461710p6472988.html
Sent from the Jersey mailing list archive at Nabble.com.