Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL rewriting solution needed for JSF

Suppose the following application landscape:

+-----------------+
| App server      |
+-----------------+
|                 |                                   +-------+
| ear1            |                                   |       |
|  +-web1 (/ctx1) +--<-- http://localhost/ctx1/xxx/ --+       +--<-- http://www.example.com/xxx/
|                 |                                   |       |
|                 |                                   | proxy |
| ear2            |                                   |       |
|  +-web2 (/ctx2) +--<-- http://localhost/ctx2/yyy/ --+       +--<-- http://abc.example.com/yyy/
|                 |                                   |       |
+-----------------+                                   +-------+

As you can see, proxy (nginx in my case) is forwarding requests to to a single application server instance, which in turn has multiple web modules with different context paths. Of course I dont want my public server to expose internal context roots and proxy does it's job well, wraps and unwraps http requests, etc. But there is still one big problem: JSF-generated html code (links, css, js resources, form actions) contains context paths, /ctx1 and /ctx2 in my case. That's what I want to avoid.

I nave no solution at this moment of time except of using more and more different instances (domains) of application server, causing my hardware resources to fade away. As i understand it, I need to extend my JSF applications with some wrappers, potentially registered in faces-config.xml, which would remove context prefix in generated html. Any other solutions are also welcome.

Please point me in the right direction.

like image 566
andbi Avatar asked Mar 28 '12 10:03

andbi


People also ask

Which method is used in URL rewriting?

Url rewriting is a process of appending or modifying any url structure while loading a page. The request made by client is always a new request and the server can not identify whether the current request is send by a new client or the previous same client.

Why do we need URL rewriting?

URL rewriting allows URLs to be more easily remembered by the user. When the URL is entered into the Web server, the URL rewrite engine modifies the syntax behind the scenes to enable the appropriate Web page or database item to be retrieved.

Is URL rewriting safe?

URL link rewriting is an overly manual security control prone to human error.

What is URL Rewrite explain with example?

URL rewriting is the process of modifying Uniform Resource Locators (URLs) for various purposes. The URL as a “web address” is a string that, when entered into the browser bar field, directs the browser to move to a given site and page.


1 Answers

You can use OCPsoft Rewrite URLRewriteFilter for this (not PrettyFaces currently, but you can use them both at the same time until they formally join together after PrettyFaces 4 release - Rewrite is the core project for PrettyFaces 4)

Doing something like this should be fairly straightforward using a single configuration rule. You can obviously fiddle if this rule is either too strict or too general.

.defineRule()
.when(URL.matches("{prefix}" + context.getContextPath() + "{suffix}")
.perform(Substitute.with("{prefix}{suffix}"))

Check out the rewrite site. It's pretty easy to set up. http://ocpsoft.org/rewrite/

like image 195
Lincoln Avatar answered Oct 14 '22 14:10

Lincoln