Skip to main content

@Resource TimerService injection fails in Servlet

2 replies [Last post]
bouteill
Offline
Joined: 2004-07-02

Hello, according to http://www.diotalevi.com/weblog/2006/10/30/java-ee-in-the-trenches-how-t..., I tried to inject @Resource private TimerService timerService; in one of my servlet running in v1b14, but I'm getting the injection error below @ deployment time.
Is this not working in glassfish or am I doing something wrong?

[#|2006-12-01T14:10:06.844-0800|INFO|sun-appserver-pe9.0|javax.enterprise.resource.webcontainer.jsf.config|_ThreadID=12;_ThreadName=httpWorkerThread-4848-1;/admin;|ConfigureListener.contextInitialized: jsf.config.listener.version.complete|#]

[#|2006-12-01T14:10:13.032-0800|SEVERE|sun-appserver-pe9.0|javax.enterprise.system.container.web|_ThreadID=20;_ThreadName=httpWorkerThread-8080-1;_RequestID=4b8c218e-efbb-468b-b1f2-c9461c47c306;|ApplicationContext.log: WebModule[]StandardWrapper.Throwable
java.lang.RuntimeException: WEB5002: Exception in handleBeforeEvent.
at com.sun.web.server.J2EEInstanceListener.handleBeforeEvent(J2EEInstanceListener.java:260)
at com.sun.web.server.J2EEInstanceListener.instanceEvent(J2EEInstanceListener.java:97)
at org.apache.catalina.util.InstanceSupport.fireInstanceEvent(InstanceSupport.java:318)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1118)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:787)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:183)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
Caused by: com.sun.enterprise.InjectionException: Exception attempting to inject Env-Prop: peerflix.jsf.servlet.StatusServlet/timerService@Field-Injectable Resource. Class name = peerflix.jsf.servlet.StatusServlet Field name=timerService@java.lang.String@peerflix.jsf.servlet.StatusServlet/timerService@@ into class peerflix.jsf.servlet.StatusServlet
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:373)
at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:193)
at com.sun.enterprise.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:104)
at com.sun.web.server.J2EEInstanceListener.handleBeforeEvent(J2EEInstanceListener.java:255)
... 27 more
Caused by: javax.naming.NameNotFoundException: No object bound for java:comp/env/peerflix.jsf.servlet.StatusServlet/timerService [Root exception is java.lang.IllegalStateException: Illegal invocation type for EJB Context : 0]
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:196)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:307)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:274)
... 30 more
Caused by: java.lang.IllegalStateException: Illegal invocation type for EJB Context : 0
at com.sun.ejb.containers.ContainerFactoryImpl.getEJBContextObject(ContainerFactoryImpl.java:427)
at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:875)
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:156)
... 33 more
|#]

[#|2006-12-01T14:10:13.034-0800|SEVERE|sun-appserver-pe9.0|javax.enterprise.system.container.web|_ThreadID=20;_ThreadName=httpWorkerThread-8080-1;_RequestID=4b8c218e-efbb-468b-b1f2-c9461c47c306;|StandardWrapperValve.log: StandardWrapperValve[StatusServlet]: Allocate exception for servlet StatusServlet
java.lang.RuntimeException: WEB5002: Exception in handleBeforeEvent.
at com.sun.web.server.J2EEInstanceListener.handleBeforeEvent(J2EEInstanceListener.java:260)
at com.sun.web.server.J2EEInstanceListener.instanceEvent(J2EEInstanceListener.java:97)
at org.apache.catalina.util.InstanceSupport.fireInstanceEvent(InstanceSupport.java:318)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1118)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:787)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:183)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
Caused by: com.sun.enterprise.InjectionException: Exception attempting to inject Env-Prop: peerflix.jsf.servlet.StatusServlet/timerService@Field-Injectable Resource. Class name = peerflix.jsf.servlet.StatusServlet Field name=timerService@java.lang.String@peerflix.jsf.servlet.StatusServlet/timerService@@ into class peerflix.jsf.servlet.StatusServlet
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:373)
at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:193)
at com.sun.enterprise.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:104)
at com.sun.web.server.J2EEInstanceListener.handleBeforeEvent(J2EEInstanceListener.java:255)
... 27 more
Caused by: javax.naming.NameNotFoundException: No object bound for java:comp/env/peerflix.jsf.servlet.StatusServlet/timerService [Root exception is java.lang.IllegalStateException: Illegal invocation type for EJB Context : 0]
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:196)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:307)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:274)
... 30 more
Caused by: java.lang.IllegalStateException: Illegal invocation type for EJB Context : 0
at com.sun.ejb.containers.ContainerFactoryImpl.getEJBContextObject(ContainerFactoryImpl.java:427)
at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:875)
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:156)
... 33 more
|#]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cf126330
Offline
Joined: 2005-03-29

TimerService is provided by the ejb container so is not available within a servlet.

-cheng

bouteill
Offline
Joined: 2004-07-02

Hum, http://www.diotalevi.com/weblog/2006/10/30/java-ee-in-the-trenches-how-t... states that it's accessible by any Java EE managed object (a servlet, an ejb, etc.), so I guess that's inaccurate then...
Ok. Thanks for clarifying.