5 Replies Latest reply on Dec 6, 2010 1:53 PM by mmulligan03

    Question: Injected Component Is Always Null

    Noah White Newbie

      Hi,


      I'm rather new at using SEAM. I have run into an issue where a SEAM component which I am trying to inject is always null.


      Basically I have a web service that looks like this:


      @MTOM
      @WebService
      @Stateless
      @Name("myUploadWS")
      public class UploadImpl {
      
          @In
          private JobManager jobManager;
      



      As you can see I am trying to inject a jobManager component. My JobManager looks like this:



      @Startup
      @Scope(ScopeType.APPLICATION)
      @Name("jobManager")
      public class JobManager {




      This was originally a singleton service like class so I unsingletoned the class and added the APPLICATION Scope and Startup annotations to try to get the same behavior under SEAM.


      One of the web methods in my WS tries to use the JobManager by jobManger is always null:



          @WebMethod
          public String getJobQueue() {
              return jobManager.getQueueToString() ;
          }




      The UploadImpl class is a JAX-WS web service which is being called by a WS client.  I am running under the assumption that myUploadWS will be managed as part of the SEAM lifecycle automagically since I annotated it with @Name and thus when a Web Service client makes a call to it the jobManager component will be injected. This doesn't seem to be happening so either my assumptions are wrong or I have misconfigured something.


      The other thought I had was that I might need to add @Startup to the UploadImpl class but in looking at the example web service in the seambay AuctionService class it does not do that.


      Any ideas as to why the jobManager component is not injecting properly?


      TIA.

        • 1. Re: Question: Injected Component Is Always Null
          Daniel Roth Apprentice

          You could try to do


          
          JobManager jobManager = (JobManager) Component.getInstance("jobManager");
          
          



          and look if it is non null. Also, are you sure the JobManager is created? Otherwise look in doc for @In(create=true) and/or @AutoCreate

          • 2. Re: Question: Injected Component Is Always Null
            Gabriel Goïc Newbie

            In UploadImpl do you have a getter/setter for jobManager? it seems this is a very common mistake that leads people to prefer Component.getInstance() (and also because injection does not allow injected beans to be used in the bean's constructor).

            • 3. Re: Question: Injected Component Is Always Null
              Noah White Newbie

              Hi, thanks for the feedback. I tried both suggestions. I've added getter/setters for jobManager and I also tried using Component.getInstance().  When running the debugger during application deployment I see that Component.getInstance() is returning with the following error:



              Caused by: java.lang.IllegalStateException: No application context active
                   at org.jboss.seam.Component.forName(Component.java:1810)
                   at org.jboss.seam.Component.getInstance(Component.java:1860)
                   at org.jboss.seam.Component.getInstance(Component.java:1843)
                   at org.jboss.seam.Component.getInstance(Component.java:1837)
                   at com.my.cm.ws.UploadImpl.<init>(UploadImpl.java:72)




              So there's not application context active. Any thoughts on why? In the debugger prior to this call to Component.getInstance() I see SEAM initializing my JobManager JavaBean in the Application context so I am not sure what the problem is.


              TIA.


              • 4. Re: Question: Injected Component Is Always Null
                Noah White Newbie

                FWIW here is the full stack trace that gets sent back to the client which shows the SeamFilter is being called -



                Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: No application context active
                     at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:188)
                     at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:130)
                     at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)
                     at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
                     at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
                     at $Proxy31.getQueueContent(Unknown Source)
                     at com.my.cm.ws.client.UploadClient.displayQueue(UploadClient.java:216)
                     at com.my.cm.ws.client.UploadClient.menu(UploadClient.java:132)
                     at com.my.cm.ws.client.UploadClient.main(UploadClient.java:71)
                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                     at java.lang.reflect.Method.invoke(Method.java:597)
                     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
                Caused by: java.lang.IllegalStateException: No application context active
                     at org.jboss.seam.Component.forName(Component.java:1810)
                     at org.jboss.seam.Component.getInstance(Component.java:1860)
                     at org.jboss.seam.Component.getInstance(Component.java:1843)
                     at org.jboss.seam.Component.getInstance(Component.java:1822)
                     at com.my.cm.ws.UploadImpl.getJobManager(UploadImpl.java:68)
                     at com.my.cm.ws.UploadImpl.getQueueContent(UploadImpl.java:78)
                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                     at java.lang.reflect.Method.invoke(Method.java:597)
                     at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:246)
                     at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
                     at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:258)
                     at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
                     at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)
                     at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)
                     at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)
                     at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)
                     at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:112)
                     at com.sun.xml.ws.tx.service.TxServerPipe.process(TxServerPipe.java:303)
                     at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
                     at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)
                     at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)
                     at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)
                     at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)
                     at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
                     at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
                     at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
                     at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
                     at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
                     at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)
                     at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75)
                     at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
                     at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
                     at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                     at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:80)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
                     at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
                     at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
                     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
                     at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
                     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
                     at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
                     at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
                     at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
                     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
                     at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
                     at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
                     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
                     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
                     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
                     at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
                     at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
                     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
                     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
                     at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
                     at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
                     at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
                     at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
                     at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
                     at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
                     at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
                     at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
                     at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
                     at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
                


                • 5. Re: Question: Injected Component Is Always Null
                  mmulligan03 Newbie

                  I am currently having the same problem has anyone found a solution to this problem?