users@jersey.java.net

Re: Dependency injection jersey + grizzly

From: spudtm <geeth.demel_at_gmail.com>
Date: Tue, 12 Oct 2010 08:50:21 -0700 (PDT)

Hi Paul

First of all, apologies for the long silence; I have been away. I am
creating the complete jar in maven using the "maven assembly plugin"
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<archive>
<manifest>
<mainClass>MyServer</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>

If I run the target with jersey - 1.0.3 META-INF/services got a file named
"com.sun.jersey.spi.inject.InjectableProvider" with value
"com.sun.jersey.atom.abdera.impl.provider.injectable.ContentHelperProvider".
 However, if I upgrade to jersey 1.4 and run the same target the contents of
the "com.sun.jersey.spi.inject.InjectableProvider" are as follows:

com.sun.jersey.core.impl.provider.xml.SAXParserContextProvider
com.sun.jersey.core.impl.provider.xml.XMLStreamReaderContextProvider
com.sun.jersey.core.impl.provider.xml.DocumentBuilderFactoryProvider
com.sun.jersey.core.impl.provider.xml.TransformerFactoryProvider

Now I can see that there is of-course nothing about the
"com.sun.jersey.atom.abdera.impl.provider.injectable.ContentHelperProvider"
in the "com.sun.jersey.spi.inject.InjectableProvider". Is it something to
do with the jersey configuration or wrong use of maven assembly build?

Any advice would be appreciated; I can still carry on with the jersey 1.0.3
but would like to use the newer version.

- Geeth

On Tue, Oct 5, 2010 at 3:48 PM, Paul Sandoz-2 [via Jersey] <
ml-node+5603716-1914360649-293298_at_n2.nabble.com<ml-node%2B5603716-1914360649-293298_at_n2.nabble.com>
> wrote:

> Hi,
>
> How are you creating the complete jar?
>
> You need to ensure that META-INF/services files from each jar are
> merged when making the complete jar.
>
> Paul.
>
> On Sep 27, 2010, at 9:07 PM, spudtm wrote:
>
> >
> > Hi guys
> >
> > I am trying out jersey for a set of REST services and having a similar
> > problem with regard to the dependency injection with jersey 1.4 (If
> > I use
> > 1.0.3 then, there are no errors).
> >
> > I want to use Abdera ContentHelper in my resources (i.e., '_at_Context
> > ContentHelper contentHelper' at the top level of the class
> > declaration) for
> > easy atom feed entity write. When I run my resources from eclipse,
> > the
> > dependencies are injected and if I run my mvn project from command
> > line as
> > 'mvn exec:java' it still works, but when I create a complete jar of
> > the
> > project (including all the dependencies) and execute the jar file
> > (i.e.,
> > java -jar <jar file>) it throws up an exception which says
> >
> > "
> > SEVERE: The following errors and warnings have been detected with
> > resource
> > and/or provider classes:
> > SEVERE: Missing dependency for field:
> > com.sun.jersey.atom.abdera.ContentHelper <MyClass>.contentHelper
> > Sep 23, 2010 7:55:53 PM com.sun.grizzly.http.servlet.ServletAdapter
> > doService
> > SEVERE: service exception:
> > Throwable occurred: com.sun.jersey.spi.inject.Errors
> > $ErrorMessagesException
> > ...
> > "
> >
> > This is of course jerser+grizzly not been able to get hold of an
> > instance of
> > ContentHelper.
> >
> > Following an example
> > (
> http://jersey.576304.n2.nabble.com/Simplest-Dependency-Injection-with-Jersey-td3393338.html#a5564545<http://jersey.576304.n2.nabble.com/Simplest-Dependency-Injection-with-Jersey-td3393338.html?by-user=t#a5564545>
>
> > ),
> > I have create an injector (See the bottom of the query) and load it
> > up with
> > my grizzly server as follows.
> > jsa.addInitParameter( "com.sun.jersey.config.property.packages",
> > "rs.csd.abdn.ac.uk.resources;" +
> > "rs.csd.abdn.ac.uk.providers");
> >
> > From the output of the jersey/grizzly I can see that the class is
> > picked.
> >
> > Can you shed any light on this? The dependencies I am using are
> >
> > 1) jersey-core
> > 2) jersey-server
> > 3) jsr311-api
> > 4) grizzly-servlet-webserver
> > 5) jersey-atom-abdera
> > 6) jaxb-api
> >
> > Thanks
> > - Geeth
> >
> > Injector class
> > ========
> > package rs.csd.abdn.ac.uk.resources.injector;
> >
> > import java.lang.reflect.Type;
> >
> > import javax.annotation.Resource;
> > import javax.naming.Context;
> > import javax.naming.InitialContext;
> > import javax.naming.NamingException;
> > import javax.ws.rs.ext.Provider;
> >
> > import com.sun.jersey.core.spi.component.ComponentContext;
> > import com.sun.jersey.core.spi.component.ComponentScope;
> > import com.sun.jersey.spi.inject.Injectable;
> > import com.sun.jersey.spi.inject.InjectableProvider;
> >
> > @Provider
> > public class ResourceInjector implements
> > InjectableProvider<Resource, Type>
> > {
> > public Injectable getInjectable(ComponentContext cc, Resource
> > r,Type t)
> > {
> > final Object value = get(r);
> >
> > return new Injectable()
> > {
> > public Object getValue()
> > {
> > return value;
> > }
> > };
> > }
> >
> > public ComponentScope getScope()
> > {
> > return ComponentScope.Singleton;
> > }
> >
> > private Object get(Resource r)
> > {
> > try
> > {
> > Context ctx = new InitialContext();
> > try
> > {
> > return ctx.lookup(r.name());
> > }
> > catch (NamingException ex)
> > {
> > return ctx.lookup("java:comp/env/" + r.name());
> > }
> > }
> > catch (Exception ex)
> > {
> > throw new RuntimeException(ex);
> > }
> > }
> > }
> > --
> > View this message in context:
> http://jersey.576304.n2.nabble.com/Dependency-injection-jersey-grizzly-tp5576514p5576514.html<http://jersey.576304.n2.nabble.com/Dependency-injection-jersey-grizzly-tp5576514p5576514.html?by-user=t>
> > Sent from the Jersey mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5603716&i=0>
> > For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5603716&i=1>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5603716&i=2>
> For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5603716&i=3>
>
>
>
> ------------------------------
> View message @
> http://jersey.576304.n2.nabble.com/Dependency-injection-jersey-grizzly-tp5576514p5603716.html
> To start a new topic under Jersey, email
> ml-node+576304-912394236-293298_at_n2.nabble.com<ml-node%2B576304-912394236-293298_at_n2.nabble.com>
> To unsubscribe from Jersey, click here<http://jersey.576304.n2.nabble.com/template/TplServlet.jtp?tpl=unsubscribe_by_code&node=576304&code=Z2VldGguZGVtZWxAZ21haWwuY29tfDU3NjMwNHwtMTcxOTI0ODY2MQ==>.
>
>
>


-- 
Geeth Ranmal de Mel
Research Assistant
Department of Computing Science
University of Aberdeen
Aberdeen AB24 3UE
Scotland (UK)
Tele : +44 - 1224 - 274174
Fax  : +44 - 1224 - 273422
Web : http://www.csd.abdn.ac.uk/~gdemel
-- 
View this message in context: http://jersey.576304.n2.nabble.com/Dependency-injection-jersey-grizzly-tp5576514p5627274.html
Sent from the Jersey mailing list archive at Nabble.com.