views:

49

answers:

1

I am planning a URL rewriter/encoder (maybe rewriter is a better term). The main purpose is to hide the exact URL from the client, since if he is smart enough, he can figure out how to mess up the application.

The URL encoder would be an injective function f(x) = y. The decoder would be the inverse function of f, say g such that g(y) = x. This way I can encode and decode my URLs.

A URL like:

http://www.myapp.com/servlet/myapp/template/MyScreen.vm/action/MyAction would be encoded to something like:

http://www.myapp.com/uyatsd6787asv6dyuasgbdxuasydgb876876v

It does not matter what is in the encoded URL as far as it is not understandable.

The problem is that I do not know how to manipulate the URL that the browser displays. I am using JBoss as a servlet container and Turbine servlet as the web application framework. I would need a module that receives the encoded URL, decodes it, passes it to Turbine, then it modifies the response's URL to show the encoded URL again.

Previous attempts to solve the problem: I have created a servlet filter, but I can not access the URL since the filter receives a ServletRequest that is a JBoss implementation. As far as I have read it seems that a servlet filter is not a good choice for manipulating the URL.

+1  A: 

Maybe you could do something like write a servlet that accepts the initial request, decodes the URL, and then internally forwards to your existing servlet.

For example, have a servlet that will accept:

www.myapp.com/enc/uyatsd6787asv6dyuasgbdxuasydgb876876v

This servlet could be set to handle requests that begin with /enc/ or some other marker to indicate that the URL needs to go to the decoder servlet. It would decode to the URL to:

/servlet/myapp/template/MyScreen.vm/action/MyAction

and then internally forward to this URL on your existing servlet using something like:

getServletContext().getRequestDispatcher(decoded_url).forward(req, res);
worpet
If I internally forward to the decoded URL would the URL in the browser still remain the original (encoded) one ?
Atticus
The browser's URL should remain the same since your serlvet is internally forwarding rather than sending a redirect back to the user.
worpet
This seems to be a good solution however you have to create a new request since after the first request the Turbine servlet will know its url pattern and all the links will point to the Turbine servlet. Therefore you have to create a new wrapped request that overrides the getServletPath() method to return the url pattern of your new let's say filter servlet that is forwarding the requests to the correct destination.
Atticus