users@jersey.java.net

Re: Injectable fields not set on target object for proxied resource (using cglib)

From: Duncan Eley <dunk_e_at_yahoo.co.uk>
Date: Fri, 7 Mar 2008 16:37:24 +0000 (GMT)

Hi, I've not had the opportunity to work with Jersey since 0.4 but when I integrated Jersey with Spring using cglib proxied resources, I got Jersey to inject dependencies on the resources as follows: .. import org.springframework.aop.framework.Advised; import org.springframework.aop.support.AopUtils; ... public Object getInstance(ResourceProviderContext context) { try { initSpringContext(context); initBeanName(); Object resource = springContext.getBean(beanName, resourceClass); if (AopUtils.isAopProxy(resource)) { Advised aopResource = (Advised) resource; context.injectDependencies(aopResource.getTargetSource().getTarget()); } else { context.injectDependencies(resource); } return resource; } catch (Exception ex) { throw new ContainerException("Unable to create resource", ex); } }The above example uses the SPI described here: http://weblogs.java.net/blog/mhadley/archive/2007/09/integrating_jer.html. This demonstrates how to get at the cglib proxied object using Spring. However, I'm aware that the Jersey SPI has changed quite a bit since I did this. It would be really nice, if at some point, Jersey had an optional library for users wanting to integrate with Spring. HTH, Duncan Eley ----- Original Message ---- From: Marc Hadley <Marc.Hadley@Sun.COM> To: users@jersey.dev.java.net Sent: Friday, 7 March, 2008 4:05:32 PM Subject: Re: Injectable fields not set on target object for proxied resource (using cglib) Hmm, this seems like a general problem with proxies. How is this usually handled, can the jersey component provider get access to the proxied object somehow or do we need support for injection via bean setters/getters as an alternative to fields ? Marc. On Mar 7, 2008, at 8:58 AM, Martin Grotzke wrote: > Hi, > > I'm using spring as container and (as I wrote in another posting) want > to use spring AOP for some authentication/authorization stuff. > > Unfortunately, if my resource is proxied (and that might happen > magically in spring ;)), injectable fields like UriInfo or > HttpServletRequest are only set on the proxy, but not on my object. > > Is this an issue for jersey (can jersey handle this) or is this an > issue > of the container in use / proxying mechanism? > > Thanx in advance, > cheers, > Martin > --- Marc Hadley <marc.hadley at sun.com> CTO Office, Sun Microsystems. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@jersey.dev.java.net For additional commands, e-mail: users-help@jersey.dev.java.net __________________________________________________________ Sent from Yahoo! Mail. The World's Favourite Email http://uk.docs.yahoo.com/nowyoucan.html