9 Replies Latest reply on Apr 28, 2014 8:28 AM by Marek Novotny

    WebService: java.lang.IllegalStateException: No application context active

    Marco Santos Newbie

      Hello There.


      I'm having problems getting a SeamComponent from a WebService class. Im getting the follow exception:


      faultString: java.lang.IllegalStateException: No application context active



      when this line is executed trying to get a SeamComponent:


      PontonAdapter pontonAdapter=(PontonAdapter) Component.getInstance(PontonAdapter.class, true);



      The WebService


      @WebService
      public class DocumentReceiver {
           
           @WebMethod
           public boolean receiveDocument(String xmlFile, byte[] pdfFile) {
                String webcontentPath = FileUtils.getWebContentAppDirPath();
                
                String tmpPath = webcontentPath.concat("\\tmp\\");
                File tmpDir = new File(tmpPath);
                
                if(!tmpDir.exists()) {
                     tmpDir.mkdir();
                }
                
                System.out.println("PATH: " + tmpPath);
                
                String xmlFilePath = tmpPath + "web.xml";
                String pdfFileName = tmpPath + "pdfTest.pdf";
                
                System.out.println("XML FILE TEXT:\n" + xmlFile);
                 
                      //THE EXECPTION IS RAISED HERE
                PontonAdapter pontonAdapter = (PontonAdapter) Component.getInstance(PontonAdapter.class, true);
                
                //FileUtils.writeToFile(xmlFile, xmlFilePath);
                if(xmlFile != null) {
                     FileUtils.writeStringToFile(xmlFile, xmlFilePath);
                }
                
                if(pdfFile != null) {
                     FileUtils.writeBytesToFile(pdfFileName, pdfFile);
                }
                
                return true;
           }
      }
      



      How can i get the AplicationContext from a class that is not a SeamComponente so i can instanciate it?


      Thaks a lot for the help


      Best Regards / Os meus melhores cumprimentos


      Marco Santos

        • 1. Re: WebService: java.lang.IllegalStateException: No application context active
          Ondrej Sevce Newbie

          I have the same problem. Following the example from Seam reference, this is my code:



          @Stateless
          @WebService
          @SOAPBinding(style = Style.RPC)
          public class TextProcessor implements TextProcessorInterfaceWS
          {     
               
              @WebMethod
              public int process(@WebParam(name = "text") String text)
              {
                  
                   System.out.println("processing string: " + text);
                   
                   GateAction gateAction = (GateAction) Component.getInstance(GateAction.class, true);
                   
                   gateAction.isComponentOK();
                   
                  return 0;
              }
          }



          My gate component looks like this:




          @Stateless
          @Name("gateAction")
          public class GateAction  implements GateActionLocalInterface{
          
               //private SerialAnalyserController controller;
               @Logger
               Log logger;
               
               //@Create
               @org.jboss.seam.annotations.Factory
               public void initialize() {     
                      ...         
               }
               
               public boolean isComponentOK() {
                      return true;
               }
               
          }
          



          When calling the webservice, i get this exception:




          00:23:56,319 ERROR [SOAPFaultHelperJAXWS] SOAP request exception
          javax.ejb.EJBException: java.lang.IllegalStateException: No application context active
               at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
               at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
               at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
               at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.wsf.container.jboss42.InvocationHandlerEJB3.invoke(InvocationHandlerEJB3.java:103)
               at org.jboss.ws.core.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:220)
               at org.jboss.wsf.stack.jbws.RequestHandlerImpl.processRequest(RequestHandlerImpl.java:408)
               at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:272)
               at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl.java:189)
               at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:122)
               at org.jboss.wsf.stack.jbws.EndpointServlet.service(EndpointServlet.java:84)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
               at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
               at java.lang.Thread.run(Thread.java:619)
          Caused by: java.lang.IllegalStateException: No application context active
               at org.jboss.seam.Component.forName(Component.java:1912)
               at org.jboss.seam.Component.getInstance(Component.java:1972)
               at org.jboss.seam.Component.getInstance(Component.java:1950)
               at org.jboss.seam.Component.getInstance(Component.java:1944)
               at org.jboss.seam.Component.getInstance(Component.java:1924)
               at sk.stuba.fiit.marquess.session_beans.TextProcessor.process(TextProcessor.java:29)
               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 org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
               at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
               at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:101)
               at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
               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 org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
               at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
               ... 39 more
          00:23:56,329 ERROR [SOAPFaultHelperJAXWS] SOAP request exception
          javax.ejb.EJBException: java.lang.IllegalStateException: No application context active
               at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
               at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
               at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
               at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.wsf.container.jboss42.InvocationHandlerEJB3.invoke(InvocationHandlerEJB3.java:103)
               at org.jboss.ws.core.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:220)
               at org.jboss.wsf.stack.jbws.RequestHandlerImpl.processRequest(RequestHandlerImpl.java:408)
               at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:272)
               at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl.java:189)
               at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:122)
               at org.jboss.wsf.stack.jbws.EndpointServlet.service(EndpointServlet.java:84)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
               at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
               at java.lang.Thread.run(Thread.java:619)
          Caused by: java.lang.IllegalStateException: No application context active
               at org.jboss.seam.Component.forName(Component.java:1912)
               at org.jboss.seam.Component.getInstance(Component.java:1972)
               at org.jboss.seam.Component.getInstance(Component.java:1950)
               at org.jboss.seam.Component.getInstance(Component.java:1944)
               at org.jboss.seam.Component.getInstance(Component.java:1924)
               at sk.stuba.fiit.marquess.session_beans.TextProcessor.process(TextProcessor.java:29)
               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 org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
               at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
               at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:101)
               at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
               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 org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
               at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
               ... 39 more
          
          



          My conf: Win XP Pro, JBoss 4.2.2.GA, Seam 2.1.1.GA.


          I haven't found any solution yet. Thanks for help very much!


          Ondrej

          • 2. Re: WebService: java.lang.IllegalStateException: No application context active
            Ondrej Sevce Newbie

            Any ideas? I would appreciate any help. I cant move from a place.


            Ondrej

            • 3. Re: WebService: java.lang.IllegalStateException: No application context active
              Scott Basinger Newbie
              With POJO based services in a webapp (war deployment) I needed a servlet mapping section in web.xml per https://jira.jboss.org/jira/browse/JBWS-1762.


              web.xml ----------
                   <servlet>
                        <servlet-name>CatalogService</servlet-name>
                        <servlet-class>
                             com.longaberger.webservices.productcatalog.ProductCatalogService</servlet-class>
                   </servlet>
                   <servlet-mapping>
                        <servlet-name>CatalogService</servlet-name>
                        <url-pattern>/webservices/CatalogService</url-pattern>
                   </servlet-mapping>
              • 4. Re: WebService: java.lang.IllegalStateException: No application context active
                Ondrej Sevce Newbie

                Thank you for response. I am using EJB web service, and the solution in my case was using Lifecycle.beginCall() and Lifecycle.endCall() methods inside method annotated with @WebMethod. Also I found out, that this




                GateAction gateAction = (GateAction) Component.getInstance(GateAction.class, true);



                won't work if GateAction is an EJB. It must be POJO Seam component, otherwise there is ClassCastException thrown.


                Ondrej


                     

                • 5. Re: WebService: java.lang.IllegalStateException: No application context active
                  Marnix van Bochove Newbie

                  Hi, I had the same problem (No context active) with my stateless webservice and statefull seam components. I solved this by adding this annotation to my webservice:


                  @HandlerChain(file = "soap-handlers.xml")

                  I copied the soap-handlers.xml file from the seambay example.


                  I'm using JBoss 6.0.0.Final and Seam 2.2.1.Final


                  • 6. Re: WebService: java.lang.IllegalStateException: No application context active
                    Lokesh Paunikar Newbie

                    Hi Ondrej, I am also facing the same issues. To resolve "No application context activeI also have added Lifecycle.beginCall() and Lifecycle.endCall() methods. Now I am getting "ClassCastException"  but in my case "GateAction" is an Seam Component. Could you please help me why I am getting this exception? And Lets say If "GateAction" is EJB then is there any way to resolve this issue?

                     

                    Thanks,

                    Lokesh

                    • 8. Re: WebService: java.lang.IllegalStateException: No application context active
                      Lokesh Paunikar Newbie

                      Hi, I am not getting the reason behind the ClassCastException, though I am getting the instance of the same class but on attempt to instanceof check returning false. Could you please explain me why its happening?

                      • 9. Re: WebService: java.lang.IllegalStateException: No application context active
                        Marek Novotny Master

                        What don't you get? Ondrej's discovery in Re: WebService: java.lang.IllegalStateException: No application context active or you exception issue?

                        EJB instance can be a proxy instance while Seam POJO is the same instance gotten from a context.