users@glassfish.java.net

Re: CDI Bean Injection not happening..(Only Service Injection)

From: <forums_at_java.net>
Date: Tue, 12 Mar 2013 22:16:22 -0500 (CDT)

Now, I have re-produced the issue on current GFv4 SNAPSHOT, needing to say:
before deploying CDI bundle, you need to deploy guava bundle[1]. [1]:
http://repo1.maven.org/maven2/com/google/guava/guava/14.0-rc2/guava-14.0-rc2.jar
Then, after deploying the wab, once accessing
http://localhost:8080/CDI/message, a NPE happened in server.log as following:
[2013-03-13T18:58:30.656+0900] [glassfish 4.0] [WARNING] []
[javax.enterprise.web] [tid: _ThreadID=29 _ThreadName=http-listener-1(1)]
[timeMillis: 1363168710656] [levelValue: 900] [[
StandardWrapperValve[com.amitinside.amit.servlet.ItemServlet]:
Servlet.service() for servlet com.amitinside.amit.servlet.ItemServlet threw
exception java.lang.NullPointerException at
com.amitinside.beans.impl.ItemProcessor.execute(ItemProcessor.java:50) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601) at
org.glassfish.osgicdi.impl.OSGiServiceFactory$DynamicInvocationHandler.invoke(OSGiServiceFactory.java:240)
at $Proxy221.execute(Unknown Source) at
com.amitinside.amit.servlet.ItemServlet.doGet(ItemServlet.java:32) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:687) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:176)
at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at
org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at
org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at
org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at
org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at
org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at
org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:722) ]] [2013-03-13T18:58:30.656+0900]
[glassfish 4.0] [INFO] [] [] [tid: _ThreadID=29 _ThreadName=Thread-3]
[timeMillis: 1363168710656] [levelValue: 800] [[
--------------------!!!!null------------------]] [Analyse] From the
stacktrace, although ItemProcessor has been injected into itemBean
successfully and ItemProcessor has been registered into OSGi ServiceRegistry,
but the sample uses Declare Service to register ItemProcessor as OSGi Service
and you wish Declare Service container can combine with CDI container in
order to make ItemProcessor can also live in CDI context to inject ItemDao.
To be very pity, Declare Service container does not combine with CDI
container to register OSGi service by obtaining a CDI bean
instance(ItemProcessor). So, NPE is right! Please contact with felix scr team
and submit a request and I think that this is a good feature! In addition,
OSGi/CDI integration will has the feature you require and currently, a RFC
193 draft can be available and you can see it. In the future, I think that
glassfish should implement the feature. Thanks --Tang Yong

--
[Message sent by forum member 'codeprince']
View Post: http://forums.java.net/node/895558