6 Replies Latest reply on Jan 25, 2011 10:42 AM by cash1981

    Seam custom filter called 8 times

    seamworker

      Hello there,


      I have noticed my custom Seam filter extends from AbstractFilter(seam)  called 8 times which is equivalent to number of built-in Filters in SeamFilter implementation.


      Please let me know how to avoid this. I just want to execute my filter within one of the built in seam filters. Thank you in advance.


      Regards,
      Srinivasan

        • 1. Re: Seam custom filter called 8 times
          seamworker

          Anybody there?

          • 2. Re: Seam custom filter called 8 times
            jeanluc

            I suspect something is wrong with the declaration. Post your filter source (you can remove any specific functionality, I'm primarily interested in the declarations and the flow).

            • 3. Re: Seam custom filter called 8 times
              seamworker

              Here is the Custom Filter code:


              import org.jboss.seam.web.AbstractFilter;
              
              @Filter(within = "org.jboss.seam.web.exceptionFilter")
              @Name("ivUserAuthenticationFilter")
              @Scope(ScopeType.APPLICATION)
              @Startup
              @BypassInterceptors
              public class UserAuthenticationFilter extends AbstractFilter{
              
                  
                  public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
                          throws IOException, ServletException
                  {
                       
                             //business logic  
              
                             chain.doFilter(request, response); //chain.doFilter(..) repeatedly calls the same method for 8 times
                  }
              }



              Nothing else is written supporting this.
              in Web.xml SeamFilter is configured to run for each request


               <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>



              Please let me know if more information required. Thank you.





              • 4. Re: Seam custom filter called 8 times
                jeanluc

                What happens if you change the within declaration to




                @Filter(within = {"org.jboss.seam.web.authenticationFilter"})





                ?


                That's what I use for several filters and they are only executed once per request.


                • 5. Re: Seam custom filter called 8 times
                  antibrumm.mfrey0.bluewin.ch

                  Hi
                  i was just wondering if you have some pictures and other referenced objects in your html? Because i had a similar issue and in the end i found out that the filter was called on each request, which also includes images, js, css, etc. :)


                  Probalby its enough to restrict the filter with this ?



                       public String getRegexUrlPattern() {
                            return "(^/.*.seam)|(^/[0-9a-zA-Z]+$)";
                       }



                  • 6. Re: Seam custom filter called 8 times
                    cash1981

                    Try adding in the doFilter method, at the beginning.




                    if (!(req instanceof HttpServletRequest)) {
                                chain.doFilter(req, res);
                                return;
                    }
                    



                    or




                    if (HttpServletRequest.class.isAssignableFrom(request.getClass())) {
                    //your code here
                    }