Keep the filter sequence after RewriteFilter Rule Match

Splash Forums Rewrite Users Keep the filter sequence after RewriteFilter Rule Match

This topic contains 7 replies, has 3 voices, and was last updated by  Christian Kaltepoth 2 years, 10 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #25078

    youngreymond
    Participant

    Hello,

    how I can do to keep the flow of the filters once a rule is matched, because the RewriteFilter is aborting the request and the others filter are not called, excepting when the Rule throws a Exception (like a FacesFileNotFoundException).

    this are the filters in my web.xml

    <filter>
    		<filter-name>OCPsoft Rewrite Filter</filter-name>
    		<filter-class>org.ocpsoft.rewrite.servlet.RewriteFilter</filter-class>
    		<async-supported>true</async-supported>
    	</filter>
    	<filter-mapping>
    		<filter-name>OCPsoft Rewrite Filter</filter-name>
    		<url-pattern>/*</url-pattern>
    		<dispatcher>FORWARD</dispatcher>
    		<dispatcher>REQUEST</dispatcher>
    		<dispatcher>INCLUDE</dispatcher>
    		<dispatcher>ASYNC</dispatcher>
    		<dispatcher>ERROR</dispatcher>
    	</filter-mapping>
    	<filter>
    		<filter-name>SessionFilter</filter-name>
    		<filter-class>org.test.portal.filters.SessionFilter</filter-class>
    	</filter>
    	<filter-mapping>
    		<filter-name>SessionFilter</filter-name>
    		<url-pattern>/web/*</url-pattern>
    	</filter-mapping>

    and this are my RewriteConfiguration

    .addRule()
    				.when(Direction.isInbound().and(Path.matches("/web/home/")))
    				.perform(Forward.to("/portal/home.xhtml"))
    				
    				.addRule()
    				.when(Direction.isInbound().and(Path.matches("/web/login/")))
    				.perform(Forward.to("/portal/login.xhtml"))
    
    				.addRule()
    				.when(Direction.isInbound().and(Path.matches("/web/{modulo}/")))
    				.perform(Forward.to("/portal/home.xhtml").and(PhaseOperation.enqueue(new IgnorePostbackOperation(Invoke.binding(El.retrievalMethod("sessionBean.processModuloSeleccionado")))).after(PhaseId.RESTORE_VIEW))).where("modulo")
    				.bindsTo(PhaseBinding.to(El.property("sessionBean.selectedModuloValue")).after(PhaseId.RESTORE_VIEW))
    
    				.addRule().when(Direction.isInbound().and(Path.matches("/web/{modulo}/{servicio}/"))).perform(Forward.to("/portal/{modulo}/{servicio}.xhtml").and(Log.message(Level.INFO, "Log from Configuration")))

    Thanks in advance!

    #25081

    Rewrite forwards requests if a rule matches. Filters are only applied to forwarded requests if you set <dispatcher>FORWARD</dispatcher> in the filter configuration. So either move the other filters in front of the rewrite filter (so they get executed before the request is forwarded) or change add <dispatcher>FORWARD</dispatcher> to the filter configuration.

    #25082

    Example:

    <filter>
    	<filter-name>SessionFilter</filter-name>
    	<filter-class>org.test.portal.filters.SessionFilter</filter-class>
    </filter>
    <filter-mapping>
    	<filter-name>SessionFilter</filter-name>
    	<url-pattern>/web/*</url-pattern>
    	<dispatcher>REQUEST</dispatcher>
    	<dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    
    #25083

    youngreymond
    Participant

    Hey Thanks, It’s Working now.

    one more questions if is possible, How I can forwards the (ex: Path.matches("/web/home/") ) url to the other filters instead of the original URL ?

    #25084

    This is exactly what the Forward.to(...) operation is for 🙂 It lets you change the URL internally. Is that not what you mean?

    #25085

    youngreymond
    Participant

    I am sorry but did not know how to explain.

    I need to get on my SessionFilter after the Rewrite Rule has run, the url specified with Path.matches in this case /web/home/, but I’m getting the original url CONTEXT_PATH/portal/home.xhtml when I get it with String url = req.getRequestURI(); on my SessionFilter.

    Thanks in advance!

    #25086

    Try this:

    request.getAttribute("javax.servlet.forward.request_uri")

    https://github.com/ocpsoft/rewrite/issues/100

    ~Lincoln

    #25087

    Another option would be to move the SessionFilter in front of the RewriteFilter. In this case your filter will only see the unmodified incoming URL.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

Comments are closed.