Reply To: Change filter dispatcher

Splash Forums Rewrite Users Change filter dispatcher Reply To: Change filter dispatcher

#26309

fmb
Participant

As I said, I do use forwards internaly with a specific URL scheme. Its like:

“/site/user/page” which loads the mapped servlet and a jsp file inside “/jsp/site/user/page.jsp” in the filesystem

In this case I use rewrite to map requests from “/{site}/{user}/page” to proper “/site/user/page?site={site}&user={user}”, so the url is like site.com/somecity/someuser/

I am using a custom filter to include the JSPs and rewrite on top of it, rewrite is only being used to forward the original request and change the URL.
The problem with using all dispatchers is that if I create a rule like “/{page}” forwarded to “/{page}” it ends up recursive. Assigning rewrite filter only for requests, and my URL scheme for forwards, solves this issue.

You may be asking: “but why would you create such rule”?
Well, lets say you are accessing “/about/me” page and “/{site}/me” dynamically. “/{site}/me” should be redirected to “/site/me?site={site}”, but if my {site} is not registered in the application (its a specific entity that represents an internal application context), then I want to access “/about/me” instead (“about” directory with a “me” page).

The rule would be something like this:

.addRule()
.when( Path.matches( "/{dir}/{page}" ) )
.perform( Forward.to( "/{dir}/{page}" ) )
.where( "dir" ).constrainedBy( NOT_VALID_SITE )

and

.addRule()
.when( Path.matches( "/{site}/{page}" ) )
.perform( Forward.to( "/site/{page}?site={site}" ) )
.where( "site" ).constrainedBy( VALID_SITE );

Thats is the reason I want to change the rewrite filter’s dispatch type.

And by the way, I found a way to override the filter dispatcher by declaring it in the web.xml like this:

<filter-mapping>
	<filter-name>OCPsoft Rewrite Filter</filter-name>
	<url-pattern>/*</url-pattern>
	<dispatcher>REQUEST</dispatcher>
</filter-mapping>

It seems the filter-name thats is being declared in the web-fragment allows it to be overriden.

Does it make sense?

  • This reply was modified 7 years, 7 months ago by  fmb.
  • This reply was modified 7 years, 7 months ago by  fmb.
  • This reply was modified 7 years, 7 months ago by  fmb.