users@jersey.java.net

Re: [Jersey] Intercepting resource invocations

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 09 Mar 2009 13:47:17 +0100

Hi Dan,

There is currently nothing in Jersey that supports the interception of
method invocation.

If i understand your use-case correctly the client only defines the
interface. It would seem that the use of java.lang.reflect.Proxy would
be ideal? or even a cglib proxy? where the proxy implementations are
generated by and defer to Mule infrastructure?

I would think that the best way to support this is to write your own
IoCComponentProviderFactory [1] that returns instances of
IoCInstantiatedComponentProvider [2] for interfaces. The latter
specifies that the IoC support instantiates the component but Jersey
manages life-cycle.

So your implementation of IoCComponentProviderFactory could set things
up so that proxies of interface are created as appropriately.

I think there may be some small issues with the registration of
interfaces. Currently they are removed with warnings, see the
ResourceConfig.validate method, but you can override this
functionality, and we can of course change this in the implementation
as you require (in addition to other changes as you require to support
your use-case).

Paul.

[1] https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/jersey/com/sun/jersey/core/spi/component/ioc/IoCComponentProviderFactory.html

[2] https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/jersey/com/sun/jersey/core/spi/component/ioc/IoCInstantiatedComponentProvider.html

On Mar 3, 2009, at 11:45 PM, Dan Diephouse wrote:

> We're looking for a way to intercept the invocation of the component
> inside Jersey.
>
> Let me explain my use case. In Mule, we create a Jersey based
> endpoint. However, sometimes our users only want to define the JAX-
> RS interface, then once appropriate databinding is done and a method
> to invoke is chosen, have it passed off to Mule. Then mule can route
> it around, transform it, provide rules for invocation, etc. And
> maybe eventually invoke the component.
>
> (Lots of users use this functionality in the JAX-WS world already.
> The JAX-WS endpoint inside may perform security and do some
> databinding, then it'll forward the POJO which was the soap body
> around to do other work. Think of Mule as a big component that may
> not necessarily implement the service interface)
>
> I see that you can create your own ComponentProvider, but I don't
> see a way to control the way the actual component is invoked.
> Ideally I would like a method like:
>
> Object invoke(ComponentProvider r, Method m, Object[] args);
>
> which I can then implement. Does jersey have anything like this?
>
> Dan
>
> --
> Dan Diephouse
> http://mulesource.com | http://netzooid.com/blog