3 Replies Latest reply on Oct 23, 2007 5:53 PM by mickknutson

    No application context active

      I am in the process of trying to build a bridge between Flex and Seam. In my factory for creating the remote object I have it delegating to Seam for this.

      new Initialization(flex.messaging.FlexContext.getServletConfig().getServletContext()).init();
      
       try {
       return Component.getInstance(compName);
       } catch (Exception ex) {
       ex.printStackTrace();
       ServiceException e = new ServiceException();
       String msg = "Seam Component named '" + compName+ "' does not exist.";
       e.setMessage(msg);
       e.setRootCause(ex);
       e.setDetails(msg);
       e.setCode("Server.Processing");
       throw e;
       }
      
      


      When I call getInstance I am getting java.lang.IllegalStateException: No application context active from Seam. Any thoughts on how to get an active application context?

      13:37:40,693 ERROR [STDERR] java.lang.IllegalStateException: No application context active
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.Component.forName(Component.java:1577)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.Component.getInstance(Component.java:1627)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.Component.getInstance(Component.java:1610)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.Component.getInstance(Component.java:1604)
      13:37:40,693 ERROR [STDERR] at com.pscufs.flex.factories.SeamFactory$SeamFactoryInstance.lookup(SeamFactory.java:100)
      13:37:40,693 ERROR [STDERR] at flex.messaging.services.remoting.adapters.JavaAdapter.createInstance(JavaAdapter.java:237)
      13:37:40,693 ERROR [STDERR] at flex.messaging.services.remoting.adapters.JavaAdapter.invoke(JavaAdapter.java:157)
      13:37:40,693 ERROR [STDERR] at flex.messaging.services.RemotingService.serviceMessage(RemotingService.java:173)
      13:37:40,693 ERROR [STDERR] at flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:1165)
      13:37:40,693 ERROR [STDERR] at flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndpoint.java:727)
      13:37:40,693 ERROR [STDERR] at flex.messaging.endpoints.amf.MessageBrokerFilter.invoke(MessageBrokerFilter.java:99)
      13:37:40,693 ERROR [STDERR] at flex.messaging.endpoints.amf.LegacyFilter.invoke(LegacyFilter.java:158)
      13:37:40,693 ERROR [STDERR] at flex.messaging.endpoints.amf.SessionFilter.invoke(SessionFilter.java:48)
      13:37:40,693 ERROR [STDERR] at flex.messaging.endpoints.amf.BatchProcessFilter.invoke(BatchProcessFilter.java:67)
      13:37:40,693 ERROR [STDERR] at flex.messaging.endpoints.amf.SerializationFilter.invoke(SerializationFilter.java:124)
      13:37:40,693 ERROR [STDERR] at flex.messaging.endpoints.AMFEndpoint.service(AMFEndpoint.java:117)
      13:37:40,693 ERROR [STDERR] at flex.messaging.MessageBrokerServlet.service(MessageBrokerServlet.java:424)
      13:37:40,693 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      13:37:40,693 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      13:37:40,693 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:60)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      13:37:40,693 ERROR [STDERR] at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
      13:37:40,693 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      13:37:40,693 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      13:37:40,693 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      13:37:40,693 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      13:37:40,693 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      13:37:40,693 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      13:37:40,693 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      13:37:40,693 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      13:37:40,693 ERROR [STDERR] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
      13:37:40,693 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      13:37:40,693 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      13:37:40,771 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      13:37:40,771 ERROR [STDERR] at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      13:37:40,771 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      13:37:40,771 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      13:37:40,771 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      13:37:40,771 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      13:37:40,771 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      13:37:40,771 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      13:37:40,771 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
      



        • 1. Re: No application context active
          patrickmadden

          I'm not exactly sure if this will help but I noticed problems when I tried to do certain things to early in the component initialization phase. For example my session contexts would be null. My trick is not to do things that access contexts until the create method is called for my Seam components. For example, you can't do things in the constructor of the object. Use the @Create annotation and then try your initialization. Something like this:

          @Stateful
          @Name("search")
          @Scope(ScopeType.SESSION)
          public class SearchBean implements Search {
           /**
           * This method is called after this component has been successfully
           * instantiated by the Seam framework
           */
           @Create
           public void create()
           {
           // perform initialization here
           }
          ....
          


          Hope this helps,

          PVM

          • 2. Re: No application context active

            The solution to this answer is not to forget about the JSF lifecyle.


            new Initialization(flex.messaging.FlexContext.getServletConfig().getServletContext()).init();
             Lifecycle.setServletContext(flex.messaging.FlexContext.getServletConfig().getServletContext());
            Lifecycle.beginCall();
            
             Object obj = null;
             try {
             obj = Component.getInstance(compName);
             Lifecycle.endCall();
             } catch (Exception ex) {
             ex.printStackTrace();
             ServiceException e = new ServiceException();
             String msg = "Seam Component named '" + compName+ "'does not exist.";
             e.setMessage(msg);
             e.setRootCause(ex);
             e.setDetails(msg);
             e.setCode("Server.Processing");
             throw e;
             }
            


            • 3. Re: No application context active
              mickknutson

              I seemed to run across another way to get this same error.

              When I switched from:

              <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>


              <view-handler>org.jboss.seam.ui.facelet.SeamFaceletViewHandler</view-handler>

              I get the same error. When I switched back, the error goes away and all seems to be functioning.