users@jersey.java.net

Re: [Fwd: Re: Comment: Integrating Jersey and Spring: Take 2]

From: Martin Grotzke <martin.grotzke_at_javakaffee.de>
Date: Wed, 19 Mar 2008 00:56:50 +0100

Hi Paul,

I think there was (is?) an issue with PerRequest scoped (spring)
beans/resources having a constructor with arguments. Because of that
(constructor) the PerRequestProvider invokes cp.getInstance(Scope,
Constructor, Object[]) which returned null in the prior implementation
of SpringComponentProvider, instead of getting the bean from spring.
Therefore the bean was not correctly initialized (IIRC).

Cheers,
Martin


On Tue, 2008-03-18 at 11:27 +0100, Paul Sandoz wrote:
> Hi Martin,
>
> I am replying to your comment on the users, easier to track :-)
>
> You wrote:
> > Just one improvement could be made to support PerRequest scoped
> > resources that have constructor arguments: the getInstance(Scope,
> > Constructor, Object[]) method (which returns null in your example)
> > should be changed to return getInstance( scope,
> > constructor.getDeclaringClass() ).
>
> The intended design was that if the ComponentProvider implementation
> returned null Jersey would instantiate.
>
> The WebAppicationImpl provides two implements of ComponentProvider, an
> adapting and default (see end of email). If a ComponentProvider is
> supplied by the application then it is adapted using
> AdaptingComponentProvider implementation, otherwise the
> DefaultComponentProvider is used.
>
> The WebApplicationImpl.initiate method does this:
>
> public void initiate(ResourceConfig resourceConfig,
> ComponentProvider provider) {
> ...
> // Set up the component provider
> this.provider = (provider == null)
> ? new DefaultComponentProvider()
> : new AdaptingComponentProvider(provider);
>
> Sort of a keep on trucking approach...
>
> Paul.
>
> private final class AdaptingComponentProvider implements
> ComponentProvider {
> private final ComponentProvider cp;
>
> AdaptingComponentProvider(ComponentProvider cp) {
> this.cp = cp;
> }
>
> public <T> T getInstance(Scope scope, Class<T> c)
> throws InstantiationException, IllegalAccessException {
> T o = cp.getInstance(scope,c);
> if (o == null)
> o = c.newInstance();
> injectResources(o);
> return o;
> }
>
> public <T> T getInstance(Scope scope, Constructor<T>
> contructor, Object[] parameters)
> throws InstantiationException, IllegalArgumentException,
> IllegalAccessException, InvocationTargetException {
> T o = cp.getInstance(scope, contructor, parameters);
> if (o == null)
> o = contructor.newInstance(parameters);
> injectResources(o);
> return o;
> }
>
> public void inject(Object instance) {
> cp.inject(instance);
> injectResources(instance);
> }
> }
>
> private final class DefaultComponentProvider implements
> ComponentProvider {
> public <T> T getInstance(Scope scope, Class<T> c)
> throws InstantiationException, IllegalAccessException {
> final T o = c.newInstance();
> injectResources(o);
> return o;
> }
>
> public <T> T getInstance(Scope scope, Constructor<T>
> contructor, Object[] parameters)
> throws InstantiationException, IllegalArgumentException,
> IllegalAccessException, InvocationTargetException {
> final T o = contructor.newInstance(parameters);
> injectResources(o);
> return o;
> }
>
> public void inject(Object instance) {
> injectResources(instance);
> }
> }
>
> email message attachment (Re: Comment: Integrating Jersey and Spring:
> Take 2.eml)
> > -------- Forwarded Message --------
> > From: Paul.Sandoz_at_Sun.COM
> > To: Paul.Sandoz_at_Sun.COM
> > Subject: RE: Comment: Integrating Jersey and Spring: Take 2
> > Date: Thu, 06 Mar 2008 11:44:27 -0800 (PST)
> >
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net