users@jersey.java.net

Re: [Jersey] Custom inject provider

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 26 Jun 2009 11:32:32 +0200

On Jun 26, 2009, at 9:53 AM, testn wrote:

>
> Just theoretically :-) if I find Jersey is too slow and I would like
> to
> replace InjectableProvider, RequestDispatcher, etc with bytecode
> implementation instead of reflection. Is there a way I can do it
> easily?

First i would recommend if you find it too slow to understand why it
is slow by measuring and getting some performance data as the initial
assumptions as to why it might be slow could be wrong. Data is king!


The actual injection mechanism mechanism is not plugable. Jersey will
get the list of Injectable associated with the list of stuff it needs
to inject.

You can plug in your own RequestDispatcher by declaring that in the
META-INF/services/
com
.sun
.jersey.server.impl.model.method.dispatch.ResourceMethodDispatchProvider

See here for the implementation that processes standard JAX-RS
resource methods:

http://fisheye4.atlassian.com/browse/jersey/trunk/jersey/jersey-server/src/main/java/com/sun/jersey/server/impl/model/method/dispatch/EntityParamDispatchProvider.java?r=2101

But it is currently not exposed as a public supported interface.

Note that Jersey goes to great lengths to do a lot of reflection work
at initialization. It caches all the Injectable instances for
injection onto constructor, resource, sub-resource locator method
parameters and fields. For field injection of singletons it will
obtain the values so it does not have to call Injectable.getValue().

There is of course still some reflection calls to invoke the methods.

I believe such a general byte code generation approach for a resource
class would require a more holistic approach that also includes path
matching, because that can result in the invocation of sub-resource
locator methods.

Paul.