7 Replies Latest reply on Dec 12, 2007 7:07 AM by bmc

    Problems with contexts not being active

    akwatters

      I'm trying to invoke a SSB from a servlet filter using Seam 1.2.1 deployed on JBoss 4.2.1.

      From the filter I'm calling the SSB using Component.getInstance("myService", true). At first this failed on calling Component.getInstance throwing a IllegalStateException with the message "No application context active". I 'discovered' org.jboss.seam.web.ContextFilter and added it to my web.xml. The SSB is now called without problems. However, when the request returns to the ContextFilter it fails with another IllegalStateException with the message "No active event context".

      java.lang.IllegalStateException: No active event context
      at org.jboss.seam.core.Manager.instance(Manager.java:267)
      at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:58)

      Help please!

        • 1. Re: Problems with contexts not being active
          pmuir

          Post your web.xml and components.xml

          • 2. Re: Problems with contexts not being active
            garypinkham

             

            "pete.muir@jboss.org" wrote:
            Post your web.xml and components.xml


            Sorry to steal the thread but I'm having the same issue so I'll post mine! :-)

            First a bit of background.. I did a quick app using the generate-entities and put a web service in front of some of the entityHome's. After some hair pulling it worked great. Now I moved the app to an integration machine. Same version of jboss and seam (4.2.0GA and 2.0.0GA) and now I'm getting the IllegalStateException regarding the lack of an active context when I call the webservice. Its really weird since I didn't change anything (I actually zipped up the deployed app from my desktop and unzipped on the server to make sure it was the same..) Anyways.. Here's my web.xml and component.xml... Any help would be greatly appreciated...

            <?xml version="1.0" encoding="UTF-8"?>
            <components xmlns="http://jboss.com/products/seam/components"
             xmlns:core="http://jboss.com/products/seam/core"
             xmlns:persistence="http://jboss.com/products/seam/persistence"
             xmlns:drools="http://jboss.com/products/seam/drools"
             xmlns:bpm="http://jboss.com/products/seam/bpm"
             xmlns:security="http://jboss.com/products/seam/security"
             xmlns:mail="http://jboss.com/products/seam/mail"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation=
             "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
             http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
             http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
             http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
             http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
             http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
             http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
            
             <core:init debug="true" jndi-pattern="@jndiPattern@"/>
            
             <core:manager concurrent-request-timeout="500"
             conversation-timeout="120000"
             conversation-id-parameter="cid"/>
            
             <persistence:filter name="companyFilter"
             enabled="#{identity.loggedIn}">
             <persistence:name>companyFilter</persistence:name>
             <persistence:parameters>
             <key>companyId</key>
             <value>#{companyId}</value>
             </persistence:parameters>
             </persistence:filter>
            
            
             <persistence:managed-persistence-context name="entityManager"
             auto-create="true"
             entity-manager-factory="#{saasEntityManagerFactory}">
             <persistence:filters>
             <value>#{companyFilter}</value>
             </persistence:filters>
             </persistence:managed-persistence-context>
            
            
             <persistence:entity-manager-factory name="saasEntityManagerFactory"
             persistence-unit-name="saas"/>
            
             <drools:rule-base name="securityRules">
             <drools:rule-files><value>/security.drl</value></drools:rule-files>
             </drools:rule-base>
            
             <security:identity authenticate-method="#{authenticator.authenticate}"
             security-rules="#{securityRules}"
             remember-me="true"/>
            
             <event type="org.jboss.seam.notLoggedIn">
             <action execute="#{redirect.captureCurrentView}"/>
             </event>
             <event type="org.jboss.seam.postAuthenticate">
             <action execute="#{redirect.returnToCapturedView}"/>
             </event>
            
             <mail:mail-session host="localhost" port="2525" username="test" password="test" />
            
             <!-- For use with jBPM pageflow or process management -->
             <!--
             <bpm:jbpm>
             <bpm:process-definitions></bpm:process-definitions>
             <bpm:pageflow-definitions></bpm:pageflow-definitions>
             </bpm:jbpm>
             -->
            
            </components>
            


            <?xml version="1.0" ?>
            <web-app xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
             version="2.5">
            
             <!-- Ajax4jsf -->
            
             <context-param>
             <param-name>org.richfaces.SKIN</param-name>
             <param-value>blueSky</param-value>
             </context-param>
            
             <!-- Seam -->
            
             <listener>
             <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
             </listener>
            
             <filter>
             <filter-name>Seam Filter</filter-name>
             <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
             </filter>
            
             <filter-mapping>
             <filter-name>Seam Filter</filter-name>
             <url-pattern>/*</url-pattern>
             </filter-mapping>
            
             <servlet>
             <servlet-name>Seam Resource Servlet</servlet-name>
             <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
             </servlet>
            
             <servlet-mapping>
             <servlet-name>Seam Resource Servlet</servlet-name>
             <url-pattern>/seam/resource/*</url-pattern>
             </servlet-mapping>
            
             <!-- Facelets development mode (disable in production) -->
            
             <context-param>
             <param-name>facelets.DEVELOPMENT</param-name>
             <param-value>true</param-value>
             </context-param>
            
             <!-- JSF -->
            
             <context-param>
             <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
             <param-value>.xhtml</param-value>
             </context-param>
            
             <servlet>
             <servlet-name>Faces Servlet</servlet-name>
             <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
             </servlet>
            
             <servlet-mapping>
             <servlet-name>Faces Servlet</servlet-name>
             <url-pattern>*.seam</url-pattern>
             </servlet-mapping>
            
             <servlet>
             <servlet-name>TenantService</servlet-name>
             <servlet-class>com.foo.saas.tenant.wsdl.TenantPortTypeImpl</servlet-class>
             </servlet>
            
             <servlet-mapping>
             <servlet-name>TenantService</servlet-name>
             <url-pattern>/wsdl</url-pattern>
             </servlet-mapping>
            
             <servlet>
             <servlet-name>IdentityService</servlet-name>
             <servlet-class>com.foo.schemas.wsdl.IdentityPortTypeImpl</servlet-class>
             <load-on-startup>1</load-on-startup>
             </servlet>
            
             <servlet-mapping>
             <servlet-name>IdentityService</servlet-name>
             <url-pattern>/identity</url-pattern>
             </servlet-mapping>
            
             <security-constraint>
             <display-name>Restrict raw XHTML Documents</display-name>
             <web-resource-collection>
             <web-resource-name>XHTML</web-resource-name>
             <url-pattern>*.xhtml</url-pattern>
             </web-resource-collection>
             <auth-constraint/>
             </security-constraint>
            </web-app>
            


            • 3. Re: Problems with contexts not being active
              pmuir

              I don't see how its the same problem, you aren't using the context filter.

              • 4. Re: Problems with contexts not being active
                bmc

                I have just the same problem with ContextFilter as akwatters. I use seam 2.0.GA and Jboss 4.2.2.

                I want to get access to seam component from my servlet (catalogDispatcher), so I add org.jboss.seam.web.ContextFilter before my servlet and call

                Component.getInstance("myComponentName");
                


                Everything works fine, but when my servlet ends doGet function execution - error appears:

                18:23:16,588 ERROR [[catalogDispatcher]] Servlet.service() for servlet catalogDi
                spatcher threw exception
                java.lang.IllegalStateException: No active event context
                 at org.jboss.seam.core.Manager.instance(Manager.java:248)
                 at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHtt
                pServletRequest.java:55)
                 at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:37)
                 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.jav
                a: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(Appl
                icationFilterChain.java:235)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                ilterChain.java:206)
                 at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
                lter.java:96)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                icationFilterChain.java:235)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                ilterChain.java:206)
                 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
                alve.java:230)
                 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
                alve.java:175)
                 at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
                yAssociationValve.java:179)
                 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
                torBase.java:433)
                 at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
                e.java:84)
                 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
                ava:128)
                 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
                ava:104)
                 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
                543)
                 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
                ve.java:109)
                 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
                a:241)
                 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
                :844)
                 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
                ss(Http11Protocol.java:580)
                 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
                7)
                 at java.lang.Thread.run(Thread.java:619)
                



                Web.xml
                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
                <web-app>
                 <display-name>bestmemory</display-name>
                
                 <filter>
                 <filter-name>Seam Context Filter</filter-name>
                 <filter-class>org.jboss.seam.web.ContextFilter</filter-class>
                 </filter>
                
                 <context-param>
                 <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
                 <param-value>com.sun.facelets.FaceletViewHandler</param-value>
                 </context-param>
                
                 <listener>
                 <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
                 </listener>
                
                 <servlet>
                 <servlet-name>Seam Resource Servlet</servlet-name>
                 <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
                 </servlet>
                
                 <servlet-mapping>
                 <servlet-name>Seam Resource Servlet</servlet-name>
                 <url-pattern>/seam/resource/*</url-pattern>
                 </servlet-mapping>
                
                 <filter>
                 <filter-name>Seam Filter</filter-name>
                 <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
                 </filter>
                
                 <filter-mapping>
                 <filter-name>Seam Filter</filter-name>
                 <url-pattern>/*</url-pattern>
                 </filter-mapping>
                
                 <!-- JSF -->
                
                 <context-param>
                 <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
                 <param-value>.xhtml</param-value>
                 </context-param>
                
                 <context-param>
                 <param-name>facelets.DEVELOPMENT</param-name>
                 <param-value>true</param-value>
                 </context-param>
                
                 <context-param>
                 <param-name>facelets.BUFFER_SIZE</param-name>
                 <param-value>8192</param-value>
                 </context-param>
                
                 <servlet>
                 <servlet-name>Faces Servlet</servlet-name>
                 <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                 <load-on-startup>1</load-on-startup>
                 </servlet>
                
                 <servlet-mapping>
                 <servlet-name>Faces Servlet</servlet-name>
                 <url-pattern>*.seam</url-pattern>
                 </servlet-mapping>
                
                 <session-config>
                 <session-timeout>10</session-timeout>
                 </session-config>
                
                 <servlet>
                 <servlet-name>catalogDispatcher</servlet-name>
                 <servlet-class>akcent.application.request.CatalogDispatcher</servlet-class>
                 </servlet>
                
                 <servlet-mapping>
                 <servlet-name>catalogDispatcher</servlet-name>
                 <url-pattern>/catalog/*</url-pattern>
                 </servlet-mapping>
                 <filter-mapping>
                 <filter-name>Seam Context Filter</filter-name>
                 <url-pattern>/catalog/*</url-pattern>
                 </filter-mapping>
                 <servlet-mapping>
                 <servlet-name>catalogDispatcher</servlet-name>
                 <url-pattern>/goods/*</url-pattern>
                 </servlet-mapping>
                 <filter-mapping>
                 <filter-name>Seam Context Filter</filter-name>
                 <url-pattern>/goods/*</url-pattern>
                 </filter-mapping>
                </web-app>
                


                components.xml
                <?xml version="1.0" encoding="UTF-8"?>
                <components xmlns="http://jboss.com/products/seam/components"
                 xmlns:core="http://jboss.com/products/seam/core"
                 xmlns:web="http://jboss.com/products/seam/web"
                 xmlns:security="http://jboss.com/products/seam/security"
                 xmlns:persistence="http://jboss.com/products/seam/persistence"
                 xmlns:transaction="http://jboss.com/products/seam/transaction"
                 xmlns:async="http://jboss.com/products/seam/async"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation=
                 "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
                 http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd
                 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
                 http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd
                 http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.0.xsd
                 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
                
                 <core:init jndi-pattern="myapp/#{ejbName}/local" debug="true"/>
                
                 <core:manager conversation-timeout="120000"
                 concurrent-request-timeout="500"
                 conversation-id-parameter="cid"/>
                
                 <transaction:ejb-transaction/>
                
                 <async:quartz-dispatcher/>
                
                 <persistence:managed-persistence-context name="entityManager"
                 auto-create="true"
                 persistence-unit-jndi-name="java:/EntityManagerFactories/myapp"/>
                </components>
                




                • 5. Re: Problems with contexts not being active
                  pmuir

                  Please attach a runnable example with steps to reproduce to a new jira issue.

                  • 6. Re: Problems with contexts not being active
                    bmc

                    I actually localize the problem. Error is show if I try to redirect from my servlet to seam page. If I do redirect to simple (not seam) JSP page - everything is ok.

                    request.getRequestDispatcher("/seam/index.xhtml").forward(request, httpServletResponse);
                    



                    I don`t know how to attach a file in this forum, so I`ll describe my steps to create a example application.

                    I took a seam example Blog application (it comes as example application with JBoss Seam sources) add my test servlet (TestServlet.java)

                    package actions;
                    
                    import javax.servlet.http.HttpServlet;
                    import javax.servlet.http.HttpServletRequest;
                    import javax.servlet.http.HttpServletResponse;
                    import javax.servlet.ServletException;
                    import java.io.IOException;
                    import org.jboss.seam.Component;
                    
                    public class TestServlet extends HttpServlet {
                     protected void doGet(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServletException, IOException {
                     TestAction testAction = (TestAction) Component.getInstance("testAction");
                    
                     request.getRequestDispatcher("/seam/index.xhtml").forward(request, httpServletResponse);
                     }
                    }
                    


                    add TestAction.java

                    package actions;
                    
                    import org.jboss.seam.ScopeType;
                    import org.jboss.seam.annotations.Factory;
                    import org.jboss.seam.annotations.In;
                    import org.jboss.seam.annotations.Name;
                    import org.jboss.seam.annotations.Scope;
                    
                    @Scope(ScopeType.EVENT)
                    @Name("testAction")
                    public class TestAction {
                     public String sayHi() {
                     return "hallo, dude";
                     }
                    }
                    


                    and modify web.xml file:
                     <servlet>
                     <servlet-name>TestServlet</servlet-name>
                     <servlet-class>actions.TestServlet</servlet-class>
                     </servlet>
                    
                     <servlet-mapping>
                     <servlet-name>TestServlet</servlet-name>
                     <url-pattern>/testservlet/*</url-pattern>
                     </servlet-mapping>
                    
                     <filter>
                     <filter-name>ContextFilter</filter-name>
                     <filter-class>org.jboss.seam.web.ContextFilter</filter-class>
                     </filter>
                    
                     <filter-mapping>
                     <filter-name>ContextFilter</filter-name>
                     <url-pattern>/testservlet/*</url-pattern>
                     </filter-mapping>
                    





                    • 7. Re: Problems with contexts not being active
                      bmc

                      For next generations: in my case i found workaround - not use

                      Component.getInstance


                      but use JNDI lookup instead (in my case I create Stateless SB).