Re: Rewrite every *.jsf

Splash Forums PrettyFaces Users Rewrite every *.jsf Re: Rewrite every *.jsf

#20602

enigmasse
Participant

I was hoping to not create a url-mapping for every page just to remove the extension! From your statement above, I thought there might be a new feature to suppress extensions on a global scale.

I went ahead and prepared a Processor but I can’t get that to work either!

Here is my pretty-config.xml:

<rewrite match="^(.*)$" processor="com.example.URLProcessor" redirect="chain" />

Here is my processor:

public class URLProcessor implements Processor {
protected static final String EXTENSION = ".html";

/**
* Example: http://localhost/login is actually http://localhost/login.html
* Example: http://localhost/login?test=1 is actually http://localhost/login.html?test=1
*/

@Override
public String processInbound(HttpServletRequest request, HttpServletResponse response, RewriteRule rewrite, String url) {
StringBuilder newURL = new StringBuilder(url);

if (!url.contains(".")) {
if (url.contains("?")) {
newURL.insert(url.indexOf("?"), EXTENSION);
} else {
newURL.append(EXTENSION);
}
}

return newURL.toString();
}

/**
* Example: http://localhost/login.html is masked to http://localhost/login
* Example: http://localhost/login.html?test=1 is masked http://localhost/login?test=1
*/
@Override
public String processOutbound(HttpServletRequest request, HttpServletResponse response, RewriteRule rewrite, String url) {
StringBuilder newURL = new StringBuilder(url);

if (url.contains(EXTENSION)) {
newURL.delete(url.indexOf(EXTENSION), url.indexOf(EXTENSION) + EXTENSION.length());
}

return newURL.toString();
}
}

The URL string manipulation looks correct. If I use /login.html, the page renders as expected. If I use /login, the page doesn’t render, even though I see the inbound process add the “.html” at the end. When I do use /login.html, the output links render without the extension as expected. So what am I missing on the inbound??