6 Replies Latest reply on May 9, 2009 7:54 PM by John Ament

    Advanced URL rewriting and @Filter

    Florian Bantner Newbie

      Hello Forum,


      here come two questions.


      What I'd like to do: process one url like


      http://mypage.com/this-is-an-article.html
      or: http://mypage.de/this-is-a-category/


      or other similar url. From these urls I extract the domain-part (mypage.com/mypage.de) and deside which virtual web to launch. The path part I lookup in the database and decide which category or page to view. (and more)


      e.g.
      http://mypage.com/this-is-an-article.html


      would translate to /page.seam?web=mypage&lang=en&aid=12345
      and
      http://mypage.de/this-is-a-category/
      would translate to /category.seam?web=mypage&lang=de&cid=54321


      Ok. Here is my first question: Whats the best way to get this done? Only thing I need is a hint where to look at and what to look for.


      ---


      Second question: Currently I'm trying if I could do it with a custom ServletFilter. To try I created an empty seamgen project and added following class:



      @Startup
      @Scope(ScopeType.APPLICATION)
      @Name("org.jboss.seam.web.multipartFilter")
      @BypassInterceptors
      @Filter(within="org.jboss.seam.web.ajax4jsfFilter")
      public class DefaultFilter extends org.jboss.seam.web.AbstractFilter {
      
           @Override
           public void doFilter( ServletRequest request, ServletResponse response,
                     FilterChain arg2 ) throws IOException, ServletException {
                
                System.err.println( Contexts.getApplicationContext() );
                
                Component.forName( "org.jboss.seam.web.multipartFilter" );
                
           }
      
      }
      
      



      but this result only in:


      20:28:16,718 ERROR [STDERR] null
      
      20:28:16,718 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
      java.lang.IllegalStateException: No application context active
           at org.jboss.seam.Component.forName(Component.java:1807)
           at de.axone.emogul.DefaultFilter.doFilter(DefaultFilter.java:32)
           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.java: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(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.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           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:262)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
           at java.lang.Thread.run(Unknown Source)
      
      



      What am I doing wrong?



      Thanks very much.


      ---


      x) Thats not what I'am actually doing but seems to be the closes functional match to describe my problem.