2 Replies Latest reply on Jul 30, 2007 8:16 AM by Hiroyuki Wada

    Access Seam Component from Servlet Filter in JSF Request

    Hiroyuki Wada Newbie

      Hi,

      I'd like to access Seam Component from Custom Servlet Filter
      that is provided by Seam.
      But in JSF request, the Seam Contexts is not active yet in Servlet Filter
      because SeamPhaseListener(called after ServletfileterChains) activate
      the Contexts. So I can't access.

      Please advise me.

      Thanks,
      wadahiro

        • 1. Re: Access Seam Component from Servlet Filter in JSF Request
          Shane Bryzak Master

          Your custom filter needs to be called inside the Seam context filter. If you set up SeamFilter as described in the docs, make sure your filter is called later in the chain than SeamFilter.

          • 2. Re: Access Seam Component from Servlet Filter in JSF Request
            Hiroyuki Wada Newbie

            Thank you for your advice.

            I made a custom filter that is called inside the Seam context filter.
            Although Contexts access that is called before doFilter method of
            next filter is successful, the access that is called after doFilter method
            cause IllegalStateException because of No active Contexts.

            It seems that SeamPhaseListener already destroy Contexts after render response,
            so my custom filter can't access the Contexts.

            How do I access to Contexts after doFilter method?


            My sample code is as follows.

            custom filter code is:

            @Startup
            @Scope(ScopeType.APPLICATION)
            @Name("filtertest")
            @BypassInterceptors
            @Filter(within = "org.jboss.seam.web.contextFilter")
            public class FileterTest extends AbstractFilter {
            
             public void doFilter(ServletRequest arg0, ServletResponse arg1,
             FilterChain arg2) throws IOException, ServletException {
             String s = Interpolator.instance().interpolate("#{cookie}");
             System.out.println(s);
             arg2.doFilter(arg0, arg1);
             }
            
            }
            


            and WEB-INF/components.xml is:

             <web:context-filter />
            


            and console log is:

            17:13:14,218 INFO [STDOUT] [Ljavax.servlet.http.Cookie;@7baddd
            17:13:14,250 ERROR [ContextualHttpServletRequest] ended request due to exception
            java.lang.IllegalStateException: No active event context
             at org.jboss.seam.core.Manager.instance(Manager.java:235)
             at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:48)
             at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:39)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:87)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:63)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:46)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:140)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
             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:128)
             at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
             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:241)
             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
             at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
             at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
             at java.lang.Thread.run(Thread.java:595)
            17:13:14,250 ERROR [ExceptionFilter] handling uncaught exception
            javax.servlet.ServletException: java.lang.IllegalStateException: No active event context
             at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:67)
             at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:39)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:87)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:63)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:46)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:140)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
             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:128)
             at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
             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:241)
             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
             at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
             at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
             at java.lang.Thread.run(Thread.java:595)
            Caused by: java.lang.IllegalStateException: No active event context
             at org.jboss.seam.core.Manager.instance(Manager.java:235)
             at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:48)
             ... 27 more