Looijmans, Mike wrote:
...

Instead of introducing a third party component, it seems possible to
write a custom Filter to do this. All it needs to do is look at  the
incoming port and if that equals 666 insert the "/myapp" into the url?
The documentation on Filters is large but provides - again - little
examples (like how to explain to Tomcat that I want to use this
filter...).

Anyway, I prefer any solution that stays within Tomcat.

You have just given some perfect reasons to try the urlrewrite filter.

> The documentation on Filters is large but provides - again - little
> examples (like how to explain to Tomcat that I want to use this
> filter...).

urlrewrite is very well documented, and it tells you exactly how to configure this (or any other) servlet filter. If you have not dealt with servlet filters before, it is hard to think of a better introduction.

> Instead of introducing a third party component, it seems possible to
> write a custom Filter to do this. All it needs to do is look at  the
> incoming port and if that equals 666 insert the "/myapp" into the url?

Well, yes and no. The first hurdle is that the HttpRequest is immutable, so you can't just change its URL and let the call through to the servlet(s). You have to subclass, or wrap, the original request, and then pass that wrapper to the servlets instead.
urlrewrite does that, and much more.
And it is debugged, which your filter would not be.
And it is free, too.
Why re-invent the world ?

(I have, by the way, no shares in urlrewrite).

Let's refresh the issue :

A request comes into Tomcat for a URL "/xxxx". It comes in either on port 80 or port 666. And you want it to be processed by the webapp at "/myapp/xxxx".

So you need 2 Connectors :
<Connector port="80"...>
<Connector port="666" ..>
Tomcat passes the request to the same <Host ..> anyway, which has a top location for webapps, probably (tomcat-dir)/webapps/.
Tomcat will try to match the "/xxxx" request to a webapp located at
(tomcat-dir)/webapps/xxxx.
So you would need a webapp there, even if it is a dummy, just so that you have a place to put your filter and its
(tomcat-dir)/webapps/xxxx/WEB-INF/web.xml
configuration file, and its classes or jars.
In that web.xml, you will tell Tomcat that "around" the dummy webapp, there is a filter, and that it should handle all request URLs starting with "/xxxx".
What the filter does then is up to you.
I think that urlrewrite would be able to re-direct this call to the webapp at "/myapp/xxxx", just by a couple of configuration lines.

So you don't need another Engine or another Tomcat or another front-end server, you just need another dummy webapp and the urlrewrite filter. The dummy webapp could just say "Hello World", since it should never be called. Maybe it is not even really necessary, but for that my Tomcat knowledge is too limited to say.

Anyway if this works, I would consider it much simpler than the other solutions suggested so far.

But you can of course write your own filter instead. You would probably learn a lot about filters in the process, which might be useful too.




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to