users@jersey.java.net

Passing my own non-static objects into jersey resources and providers ?

From: Morten <mortench2004_at_yahoo.dk>
Date: Sun, 2 May 2010 19:42:57 +0000 (GMT)

I am trying to escape from all the trouble that Jersey has with integration with 3rd party dependency managers. In order escape to this simpler life, I am looking for an simple, universal method (if it exist?) of passing my own self-managed object instances from my application into jersey managed resources and providers that works with Java SE, OSGI, Java EE, Glassifsh 3.0 out of the box (without using WELD/Guice/Spring or upgrading anything). The problem is that when Jersey creates the resources/providers I can't pass arguments to the constructor myself and all properties that I can define only accepts class names instead of pre-configured object instances which would solve the problem. Also, the build in @Context injection support in Jersey does unfortunately not allow me to inject my own objects which would also solve the problem. Finally, I did read somewhere that Jersey application objects can get injected but I don't always have such an object in use. F.x. does "GrizzlyServerFactory.create(uri, rc)" not have an overload that accepts a Jersey Application. And no, I can't setup a servlet context instead using ServletAdapter because then I will be affected by a bug in the Jersey-Weld-integration. The only solution I can currently see is to use global static variables to pass data between my application and jersey controllers. Not very nice or multi-thread safe? Other solutions?