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

    Advanced URL rewriting and @Filter

    scheintod

      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.

        • 1. Re: Advanced URL rewriting and @Filter
          scheintod

          Just to mention it: I changed
          @Name(org.jboss.seam.web.multipartFilter) to @Name(MyFilter) and Component.forName( org.jboss.seam.web.multipartFilter ); to Component.forName( MyFilter ) but that didn't solve the problem (Stacktrace stays nearly the same).


          If noone has a solution, perhaps a tip how to debug this?


          As I understand the documentation special SeamFilters are only necessary if I'm writing a Filter for a no-seam app? Or do I have to include additional stuff even for a seam app?

          • 2. Re: Advanced URL rewriting and @Filter
            pmuir

            Florian Bantner wrote on Apr 02, 2008 08:30 PM:


            Whats the best way to get this done? Only thing I need is a hint where to look at and what to look for.



            Look at URLRewrite e.g. in the seambay example

            • 3. Re: Advanced URL rewriting and @Filter
              meetoblivion

              Is it really necessary for the URL to look like /page.seam?web=mypage&lang=en&aid=12345 ?


              If it could instead look like /page.seam?web=mypage&lang=en&aid=this-is-an-article, then you could have your actual app (rather than the filter) that parses the this-is-an-article into the ID and retrieve it.


              Just wondering, but is the component that you tied this to annotated AutoCreate ?

              • 4. Re: Advanced URL rewriting and @Filter
                scheintod

                Hi Pete, John


                Thanks for the hints. But static rewrite wouldn't solve my problem since there is some more stuff I have to do before the page to display is chosen. This stuff definively includes accessing some backing beans in order to build up a context.


                Regards,

                • 5. Re: Advanced URL rewriting and @Filter
                  rajeshj.rajesh.oflows.com

                  Florian,


                  I have the exact same requirement. Did you find a solution for this problem? Could you share the approach you took?


                  regards
                  Rajesh

                  • 6. Re: Advanced URL rewriting and @Filter
                    meetoblivion

                    I think you guys are over complicating the situation.


                    So given that the title of an article is This is my Article the clean url for it would be something like http://mydomain.com/this-is-my-article.html right?


                    if that's the case, then you can convert the article title using a method like this:



                    public static String toCleanUrl(String input) {
                    return input.toLowerCase().replace(" ","-");
                    }




                    In your pages.xml (or viewname.page.xml) you define something like:



                    <page view-id="/path/to/yourview.xhtml">
                    <param name="cleanArticleName" value="#{mycomponent.cleanArticleName}" />
                    <rewrite pattern="/{cleanArticleName}.html" />
                    </page>




                    Then in your component:



                    @In String cleanArticleName;
                    public Article getArticle() {
                    //actual implementation using cleanArticleName
                    }




                    does that help any?