1 Reply Latest reply on Aug 15, 2012 10:44 AM by deri dzen

    Seam Filter can't instantiate Component?

    deri dzen Newbie

      Hi guys,

       

      I'm having some trouble with Seam Filters. Here's my code:

       

       

      @Startup
      @Scope(ScopeType.APPLICATION)
      @Name("blacklistFilter")
      @BypassInterceptors
      @Filter(around ="org.jboss.seam.web.ajax4jsfFilter")
      public class IPBlacklistFilter extends AbstractFilter {
      
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
                throws IOException, ServletException {
      
            if (!(req instanceof HttpServletRequest)) {
                chain.doFilter(req, res);
                return;
            }
      
            HttpServletRequest request = (HttpServletRequest) req;
            String ipAddress= request.getRemoteAddr();
            IPBlacklist blacklist= null;
            try {
                blacklist= (IPBlacklist) Component.getInstance("IPBlacklist", ScopeType.APPLICATION);
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
            if (blacklist != null && blacklist.isBlackListed(ipAddress)) {
                Set<SecurityViolation> set = new HashSet<SecurityViolation>();
                set.add(new SecurityViolation() {
                    
                  private static final long serialVersionUID = 1L;
      
                  @Override
                  public String getReason() {
                      return "Black listed";
                  }
              });
                throw new AccessDeniedException(set);
            }
            
            chain.doFilter(req, res);
      
          }
      }
      

       

      As you can conclude from my code and the try-catch block, I am having trouble with instantiating a component.

      This is my stack trace:

       

      15:37:17,839 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) java.lang.IllegalStateException: No application context active
      15:37:17,841 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jboss.seam.ScopeType.getContext(ScopeType.java:145)
      15:37:17,842 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jboss.seam.Component.getInstance(Component.java:1999)
      15:37:17,845 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jboss.seam.Component.getInstance(Component.java:1994)
      15:37:17,848 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jboss.seam.Component.getInstance(Component.java:1989)
      15:37:17,850 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at ch.mobility.mono.accesscontrol.core.IPBlacklistFilter.doFilter(IPBlacklistFilter.java:45)
      15:37:17,852 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
      15:37:17,856 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
      15:37:17,858 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
      15:37:17,860 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
      15:37:17,862 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
      15:37:17,865 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
      15:37:17,869 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
      15:37:17,871 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      15:37:17,873 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      15:37:17,876 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
      15:37:17,878 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
      15:37:17,880 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
      15:37:17,882 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
      15:37:17,887 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at java.lang.Thread.run(Unknown Source)
      

       

      This is my web.xml:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app id="WebApp_ID" version="2.5"
           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">
           <display-name>ACN2</display-name>
           <filter>
                <filter-name>Blacklist Filter</filter-name>
                <filter-class>xxx.yyy.IPBlacklistFilter</filter-class>
           </filter>
           <filter-mapping>
                <filter-name>Blacklist Filter</filter-name>
                <url-pattern>/*</url-pattern>
           </filter-mapping>
      </web-app>
      

       

      So, what am I doing wrong?