Redirecting a http request to another page is often application related but sometimes we just want to make a simple redirection. Two ways to do it generally: using a front redirection (mod rewrite ;)) or adding a filter to do so.
To make it easier in simple cases TomEE has its own router.
The configuration file is called tomee-router.conf. You put it under WEB-INF and the format is:
<url from> -> <url to>
/index.html -> /home/welcome.html
But that’s not all. The right expression is a java regex. This means you can capture groups to reuse it on the left expression. For instance:
/main/\(.*\) -> /internal/$1-page.html
which will redirect /main/foo to /internal/foo-page.html.
This configuration uses a simple forward on the request.
If you put the tomee-router.conf in <tomee>/conf it will use a standard redirect (http code 302). This difference is mainly due to the fact in conf/ you can configure redirections between webapps (in WEB-INF/ you redirect in a webapp context).
Example: you deployed a SOAP webservice which is by default at http://localhost:8080/my-webapp/webservices/MyWebServiceImpl and you want it to be at http://localhost:8080/my-webservice. Simply add in conf/tomee-router.conf the following line:
/my-webservice\(.*\) -> /my-webapp/webservices/MyWebServiceImpl$1
Don’t forget the last part since ?wsdl is appended to the url to get the WSDL.
Note on webservices: with this configuration the client needs to accept redirections. If you don’t want it you can configure your webservice address in the webapp context using openejb-jar.xml.