You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Looijmans, Mike" <mi...@oce.com> on 2009/11/23 11:08:31 UTC
Redirecting a port to a webapp
Hello,
After hours of googling and browsing documentation, i came to the conclusion that what i want is either so trivial that everybody knows how to do it, or so complicated that no one ever tried it...
I want to accomplish the following in Tomcat 5.5:
http://myserver:80/xxx just does whatever it always does.
http://myserver:666/xxx is equivalent to http://myserver:80/myapp/xxx
So i want all requests targetted at a particular port (666) in this case to be forwarded to a particular servlet, which is also served under its own subdirectory on the regular HTTP port 80.
I can set up a connector at port 666 and have all its request go somewhere else, but then the application cannot be reached through the normal port (80), which is crucial for this thing to work. Installing two copies will accomplish that, but then the two copies live in different universes and cannot communicate - and setting up some IPC between them is overkill i'd say.
Mike Looijmans
Océ-technologies <http://www.oce.com/> | Topic automation <http://www.topic.nl/>
This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.
If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message.
Thank you for your co-operation.
Re: Redirecting a port to a webapp
Posted by Leon Rosenberg <ro...@gmail.com>.
On 23.11.2009, at 11:08, "Looijmans, Mike" <mi...@oce.com>
wrote:
> Hello,
>
> After hours of googling and browsing documentation, i came to the
> conclusion that what i want is either so trivial that everybody
> knows how to do it, or so complicated that no one ever tried it...
>
> I want to accomplish the following in Tomcat 5.5:
>
> http://myserver:80/xxx just does whatever it always does.
> http://myserver:666/xxx is equivalent to http://myserver:80/myapp/xxx
>
> So i want all requests targetted at a particular port (666) in this
> case to be forwarded to a particular servlet, which is also served
> under its own subdirectory on the regular HTTP port 80.
>
This sound like a simple reverse proxy running at 666 and forwarding
to 8080/myapp.
Unless I'm missing some critical details its 10 minute configuration
issue for tinyproxy (but i dont guarrantee the times).
Varnish and squid also come in mind as well as httpd with mod_proxy or
mod_jk
Regards
Leon
> I can set up a connector at port 666 and have all its request go
> somewhere else, but then the application cannot be reached through
> the normal port (80), which is crucial for this thing to work.
> Installing two copies will accomplish that, but then the two copies
> live in different universes and cannot communicate - and setting up
> some IPC between them is overkill i'd say.
>
>
>
> Mike Looijmans
> Océ-technologies <http://www.oce.com/> | Topic automation <http://www.topic.nl
> />
>
>
>
> This message and attachment(s) are intended solely for use by the
> addressee and may contain information that is privileged,
> confidential or otherwise exempt from disclosure under applicable law.
>
> If you are not the intended recipient or agent thereof responsible
> for delivering this message to the intended recipient, you are
> hereby notified that any dissemination, distribution or copying of
> this communication is strictly prohibited.
>
> If you have received this communication in error, please notify the
> sender immediately by telephone and with a 'reply' message.
>
> Thank you for your co-operation.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Redirecting a port to a webapp
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
André,
On 11/23/2009 10:57 AM, André Warnier wrote:
> 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.
Your best option is to use HttpServletRequestWrapper, which is a class
already defined in the Servlet API: it was built specifically for this
purpose.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAksL6+EACgkQ9CaO5/Lv0PAKywCcCiLREaA9oRQKqX8YPsI+9anw
2mYAn3P37vQqYe4uI1lRy/5IgdwPNNzv
=z27r
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Redirecting a port to a webapp
Posted by Pid <pi...@pidster.com>.
On 25/11/2009 07:24, Looijmans, Mike wrote:
>> I think so too. My personal doubt is still about how Tomcat
>> would try map a request that comes in as "/xxxx", "xxxx"
>> being variable and being NOT "myapp". Since it does not find
>> a match with "/myapp", and since obviously there cannot be an
>> infinity of "/webapps/xxxx" apps pre-configured, would it
>> then pass it to the "default app" (/ROOT) ?
>
> I tried this route, and the results are quite remarkable.
>
> When I deploy the webapp as ROOT.war, it gets to serve all requests that
> don't match anything else. So if the webapps dir looks like this:
>
> /ROOT.war
> /SomeApp/*
> /OtherApp.war
>
> When I send a request for /SomeApp/something, it goes to the webapp in
> that folder, likewise a request for /OtherApp/something ends up in the
> OtherApp servlet.
> A request for /foo or /bar, which does not match anything in the folder,
> gets sent to the ROOT.
>
> With this mechanism, I could program the ROOT as (in pseudocode):
>
> if port == 666:
> handle(pathinfo)
> else if pathinfo.startwith('/MyApp'):
> handle(pathinfo.split('/',2)[1])
Don't forget, if /MyApp actually exists the ROOT app won't see such a
request.
p
> else:
> error(404)
>
> This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.
>
> If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
>
> If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message.
>
> Thank you for your co-operation.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Redirecting a port to a webapp
Posted by "Looijmans, Mike" <mi...@oce.com>.
> I think so too. My personal doubt is still about how Tomcat
> would try map a request that comes in as "/xxxx", "xxxx"
> being variable and being NOT "myapp". Since it does not find
> a match with "/myapp", and since obviously there cannot be an
> infinity of "/webapps/xxxx" apps pre-configured, would it
> then pass it to the "default app" (/ROOT) ?
I tried this route, and the results are quite remarkable.
When I deploy the webapp as ROOT.war, it gets to serve all requests that
don't match anything else. So if the webapps dir looks like this:
/ROOT.war
/SomeApp/*
/OtherApp.war
When I send a request for /SomeApp/something, it goes to the webapp in
that folder, likewise a request for /OtherApp/something ends up in the
OtherApp servlet.
A request for /foo or /bar, which does not match anything in the folder,
gets sent to the ROOT.
With this mechanism, I could program the ROOT as (in pseudocode):
if port == 666:
handle(pathinfo)
else if pathinfo.startwith('/MyApp'):
handle(pathinfo.split('/',2)[1])
else:
error(404)
This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.
If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message.
Thank you for your co-operation.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Redirecting a port to a webapp
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: Redirecting a port to a webapp
>
> Or, since :666 should be treated specially, you could arrange for only
> the redirector webapp to be deployed on it, as ROOT.
I think you missed much of the discussion; this part is based on having just one <Service> element with multiple <Connector>s. Strictly speaking, the filter is necessary only in this case, where the port 666 <Connector> is part of that single <Service> along with the regular port 80 <Connector>. If a separate <Service> is configured just for port 666, no filter is necessary, although using UrlRewriteFilter would likely be the easiest way of implementing the dummy ROOT webapp, but marginally less efficient than coding a servlet to do the forwarding.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
Re: Redirecting a port to a webapp
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Chuck,
On 11/24/2009 9:21 AM, Caldarale, Charles R wrote:
>> From: André Warnier [mailto:aw@ice-sa.com] Subject: Re: Redirecting
>> a port to a webapp
>>
>> Since it does not find a match with "/myapp", and since obviously
>> there cannot be an infinity of "/webapps/xxxx" apps pre-configured,
>> would it then pass it to the "default app" (/ROOT) ? Because then,
>> that's where the filter would need to be configured, no ?
>
> The filter would have to be configured for *all* webapps, not just
> ROOT, since the word coming in over port 666 might just happen to
> match something already deployed. The config should go in the global
> conf/web.xml file.
Or, since :666 should be treated specially, you could arrange for only
the redirector webapp to be deployed on it, as ROOT.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAksL7HYACgkQ9CaO5/Lv0PBeegCfSFHceeaXJfn1RGLVJpIblJWV
8QsAn0d0TKHun+woUIRbJ8z99Jixt1VB
=mYCi
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Redirecting a port to a webapp
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: André Warnier [mailto:aw@ice-sa.com]
> Subject: Re: Redirecting a port to a webapp
>
> Since it does not find a match with "/myapp", and since
> obviously there cannot be an infinity of "/webapps/xxxx" apps
> pre-configured, would it then pass it to the "default app" (/ROOT) ?
> Because then, that's where the filter would need to be configured, no ?
The filter would have to be configured for *all* webapps, not just ROOT, since the word coming in over port 666 might just happen to match something already deployed. The config should go in the global conf/web.xml file.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Redirecting a port to a webapp
Posted by André Warnier <aw...@ice-sa.com>.
Peter Crowther wrote:
> 2009/11/24 Looijmans, Mike <mi...@oce.com>
>> Because the "xxxx" is a random word, not a
>> constant, nor the name of a servlet. Think wikipedia, the request might
>> be for /foo or /bar or whatever, and the servlet uses that word for its
>> own purposes (it will look it up in the database and return something
>> interesting).
>>
> Aha! New information - thank you! I don't think you'd previously
> mentioned that the xxxx was dynamic, not static.
Thanks for pointing that out. ;-)
>
> I'd expect urlrewrite should be able to handle this situation - as
> would writing your own Filter if you want to learn about the
> technology. Urlrewrite's manual is remarkably clear; I suspect it
> would save time overall.
>
> If you install urlrewrite, I'd expect a urlrewrite rule similar to the
> following to work (note: untested!)
>
> <rule>
> <note>Redirect :666/anything to :80/myapp/anything</note>
> <condition name="port">666</condition>
> <from>^\(.*\)$</from>
> <to>/myapp/$1</to>
> </rule>
>
> That plus two connectors for the two ports should do it, I think.
>
I think so too. My personal doubt is still about how Tomcat would try
map a request that comes in as "/xxxx", "xxxx" being variable and being
NOT "myapp". Since it does not find a match with "/myapp", and since
obviously there cannot be an infinity of "/webapps/xxxx" apps
pre-configured, would it then pass it to the "default app" (/ROOT) ?
Because then, that's where the filter would need to be configured, no ?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Redirecting a port to a webapp
Posted by Peter Crowther <pe...@melandra.com>.
2009/11/24 Looijmans, Mike <mi...@oce.com>
> Because the "xxxx" is a random word, not a
> constant, nor the name of a servlet. Think wikipedia, the request might
> be for /foo or /bar or whatever, and the servlet uses that word for its
> own purposes (it will look it up in the database and return something
> interesting).
>
Aha! New information - thank you! I don't think you'd previously
mentioned that the xxxx was dynamic, not static.
I'd expect urlrewrite should be able to handle this situation - as
would writing your own Filter if you want to learn about the
technology. Urlrewrite's manual is remarkably clear; I suspect it
would save time overall.
If you install urlrewrite, I'd expect a urlrewrite rule similar to the
following to work (note: untested!)
<rule>
<note>Redirect :666/anything to :80/myapp/anything</note>
<condition name="port">666</condition>
<from>^\(.*\)$</from>
<to>/myapp/$1</to>
</rule>
That plus two connectors for the two ports should do it, I think.
- Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Redirecting a port to a webapp
Posted by "Looijmans, Mike" <mi...@oce.com>.
> 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".
No: If it comes in at port 80, nothing "different" is supposed to
happen. So /xxxx should do whatever /xxxx would always do.
Yes: If it comes in on 666, I want it to behave as if it called for
/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.
That will NOT work then. Because the "xxxx" is a random word, not a
constant, nor the name of a servlet. Think wikipedia, the request might
be for /foo or /bar or whatever, and the servlet uses that word for its
own purposes (it will look it up in the database and return something
interesting).
M.
This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.
If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message.
Thank you for your co-operation.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Redirecting a port to a webapp
Posted by André Warnier <aw...@ice-sa.com>.
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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Redirecting a port to a webapp
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Mike,
On 11/23/2009 7:17 AM, Looijmans, Mike wrote:
> ...
>> Note that you'll end up with two independent copies of the servlet
>> in your two webapp directories, and they won't share things like
>> Sessions between them.
>
> And, as I mentioned, I don't want that to happen.
You basically have the following choices:
1) Deploy your webapp multiple times (not necessarily in separate
Tomcat instances)
2) Use a filter to re-write requests on the fly and forward internally
3) Use a filter to redirect users to the proper URL
If you really want to accept connections /only/ on port 666/xxx destined
for myapp/xxx then you will necessarily need two <Service>s, two
<Connectors>, and two deployments of the same webapp.
If you can tolerate requests coming in on either 80 or 666 and only
redirecting or forwarding, then you can get away with a single
deployment of your webapp.
>> You might, however, be able to get what you want using a
>> combination of http://tuckey.org/urlrewrite/ and two Connectors
>> defined on the same Service.
>
> Instead of introducing a third party component, it seems possible to
> write a custom Filter to do this.
Yes, you can write your own custom filter, but why not use one that's
already been built specifically for this purpose?
> All it needs to do is look at the incoming port and if that equals
> 666 insert the "/myapp" into the url?
More or less.
> The documentation on Filters is large but provides - again - little
> examples (like how to explain to Tomcat that I want to use this
> filter...).
The documentation for a Filter is light because a Filter itself only has
two jobs: a) whatever you want to do and b) optionally, send the request
along the chain to the next filter
See section SRV 6 of the Servlet 2.5 Specification. It's really quite
readable.
> Anyway, I prefer any solution that stays within Tomcat.
All of the solutions we will present will stay within Tomcat.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAksL61wACgkQ9CaO5/Lv0PB5WACfcvLKWHVPVF5S9ZsbfeP0crbE
VxYAoIfTat00c7572WPo/bBlY0M3cYp6
=BzJp
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Redirecting a port to a webapp
Posted by "Looijmans, Mike" <mi...@oce.com>.
...
> Note that you'll end up with two independent copies of the
> servlet in your two webapp directories, and they won't share
> things like Sessions between them.
And, as I mentioned, I don't want that to happen.
> You might, however, be able to get what you want using a
> combination of http://tuckey.org/urlrewrite/ and two
> Connectors defined on the same Service.
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.
Mike.
This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.
If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message.
Thank you for your co-operation.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Redirecting a port to a webapp
Posted by "Looijmans, Mike" <mi...@oce.com>.
Some additional information: The "blank page" is actually a "400 Bad
Request" response.
A 404 I could understand - especially when the directoy does not exist -
but why it returns 400 is a total mystery. There's nothing in the log
files, the access log just mentions the 400 response. There is also
nothing in the response or its headers to further explain what's wrong
with the request.
Mike.
> -----Original Message-----
> From: Looijmans, Mike
> Sent: maandag 23 november 2009 14:06
> To: Tomcat Users List
> Subject: RE: Redirecting a port to a webapp
>
> > Because you want different sets of webapps served on your different
> > connectors, I *think* you'll need two different Services in your
> > server.xml:
> >
> > <Server>
> > <Service> for port 80
> > <Connector> for port 80
> > <Engine> for port 80
> > <Host> for port 80, specifying base directory for
> your port 80
> > webapps
> > </Engine> for port 80
> > </Service> for port 80
> >
> > <Service> for port 666
> > <Connector> for port 666
> > <Engine> for port 666
> > <Host> for port 666, specifying base directory for
> your port 666
> > webapps
> > </Engine> for port 666
> > </Service> for port 666
> > </Server>
> >
> > The fastest way to make such a configuration will be to edit your
> > existing server.xml, copy+paste the <Service>...</Service> section
> > (which is most of the file) and hack at the copy as necessary.
>
> I tried this, just to be able to make some progress on the
> actual project, but it does not work as expected. I copied
> the <server> part and replaced:
>
> <Host name="localhost" appBase="webapps" />
>
> with
>
> <Host name="localhost" appBase="webapps/myapp" />
>
> And changed the connector to use port 666. The result is that
> when I browse to http://localhost:666/ I get a blank page. No
> error message, just "nothing". If I change the Host thing to read:
>
> <Host name="localhost"
> appBase="webapps/aDirThatDoesNotExistAtAll"
> />
>
> I get the same result: Silently nothing.
>
> If I revert the Host part by removing the subdir, I can acess
> http://localhost:666/myapp just fine.
>
> Duh?
This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.
If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message.
Thank you for your co-operation.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Redirecting a port to a webapp
Posted by Peter Crowther <pe...@melandra.com>.
2009/11/23 Looijmans, Mike <mi...@oce.com>
> > No. You want webapps/myapp to be treated as the ROOT context
> > for a host.
> > appBase="webapps/myapp" means look in the webapps/myapp
> > directory to find contexts for this host. The ROOT context in
> > that case would be webapps/myapp/ROOT
> >
> > As a general rule any configuration that boils down to docBase==""
> > (which is the same as appBase==docBase) is not going to
> > behave they way you want it to.
>
>
> Since I don't understand a bit of this reply, I'll interpret it as
> "please go read the manual"...
>
The servlet spec requires a little bit of "magic". Whatever war file you
want to deploy as the top-level one needs to be called ROOT.war, or the
files placed in a directory called ROOT.
>
>
> > > I want http://localhost/myapp/ and http://localhost:666/ to
> > mean the
> > > same, so just moving the webapps root a level deeper seems
> > the logical
> > > thing to do.
> >
> > That would be logical if the file system mapped directly to
> > the web URL space but it doesn't.
>
> Probably the word "apache" has lead me into believing that tomcat would
> behave like other webservers: Just point it to some root location and
> then it will follow the filesystem.
>
> Yeah. Unfortunately the servlet spec has other ideas, and Tomcat follows
the spec. Much of the reason Tomcat's own documentation seems to have bits
missing is that it doesn't duplicate the bits from the spec. If you haven't
at least skim-read the spec, I'd suggest doing so - it makes a lot of
Tomcat's "odd" behaviour much clearer.
- Peter
RE: Redirecting a port to a webapp
Posted by "Looijmans, Mike" <mi...@oce.com>.
> No. You want webapps/myapp to be treated as the ROOT context
> for a host.
> appBase="webapps/myapp" means look in the webapps/myapp
> directory to find contexts for this host. The ROOT context in
> that case would be webapps/myapp/ROOT
>
> As a general rule any configuration that boils down to docBase==""
> (which is the same as appBase==docBase) is not going to
> behave they way you want it to.
Since I don't understand a bit of this reply, I'll interpret it as
"please go read the manual"...
> > I want http://localhost/myapp/ and http://localhost:666/ to
> mean the
> > same, so just moving the webapps root a level deeper seems
> the logical
> > thing to do.
>
> That would be logical if the file system mapped directly to
> the web URL space but it doesn't.
Probably the word "apache" has lead me into believing that tomcat would
behave like other webservers: Just point it to some root location and
then it will follow the filesystem.
...
> If you follow that route yes. Another option would be to put
> the webapp somewhere outside of any host's appBase and then
> you can use context.xml files under CATALINA_BASE/<engine
> name>/<host name> to add the webapp to as many hosts as you like.
Needless to say, I again have no idea what you're talking about... back
to reading the documentation again...
Mike.
This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.
If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message.
Thank you for your co-operation.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Redirecting a port to a webapp
Posted by Mark Thomas <ma...@apache.org>.
Looijmans, Mike wrote:
>
>>> I tried this, just to be able to make some progress on the actual
>>> project, but it does not work as expected. I copied
>> the<server> part
>>> and replaced:
>>>
>>> <Host name="localhost" appBase="webapps" />
>>>
>>> with
>>>
>>> <Host name="localhost" appBase="webapps/myapp" />
>> You're telling the Host to look for war files or exploded app
>> directories in "webapps/myapp".
>
> Yes I do. Isn't that what I want then?
No. You want webapps/myapp to be treated as the ROOT context for a host.
appBase="webapps/myapp" means look in the webapps/myapp directory to
find contexts for this host. The ROOT context in that case would be
webapps/myapp/ROOT
As a general rule any configuration that boils down to docBase==""
(which is the same as appBase==docBase) is not going to behave they way
you want it to.
> I want http://localhost/myapp/ and http://localhost:666/ to mean the
> same, so just moving the webapps root a level deeper seems the logical
> thing to do.
That would be logical if the file system mapped directly to the web URL
space but it doesn't.
>> Instead, set it to "webapps2" or a similar existing directory
>> and place the web app inside that directory.
>>
>> /path/to/tomcat/webapps
>> /path/to/tomcat/webapps/ROOT
>> /path/to/tomcat/webapps/myapp
>>
>> /path/to/tomcat/webapps2/ROOT
>> /path/to/tomcat/webapps2/otherapp
>
>
> If I understand your suggestion correctly, that would make
> http://localhost/myapp/ and http://localhost:666/otherapp/ equivalent -
> not what I want - and it requires me to install two copies of the
> servlet in different locations?
If you follow that route yes. Another option would be to put the webapp
somewhere outside of any host's appBase and then you can use context.xml
files under CATALINA_BASE/<engine name>/<host name> to add the webapp to
as many hosts as you like.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Redirecting a port to a webapp
Posted by "Looijmans, Mike" <mi...@oce.com>.
> > I tried this, just to be able to make some progress on the actual
> > project, but it does not work as expected. I copied
> the<server> part
> > and replaced:
> >
> > <Host name="localhost" appBase="webapps" />
> >
> > with
> >
> > <Host name="localhost" appBase="webapps/myapp" />
>
> You're telling the Host to look for war files or exploded app
> directories in "webapps/myapp".
Yes I do. Isn't that what I want then?
I want http://localhost/myapp/ and http://localhost:666/ to mean the
same, so just moving the webapps root a level deeper seems the logical
thing to do.
> Instead, set it to "webapps2" or a similar existing directory
> and place the web app inside that directory.
>
> /path/to/tomcat/webapps
> /path/to/tomcat/webapps/ROOT
> /path/to/tomcat/webapps/myapp
>
> /path/to/tomcat/webapps2/ROOT
> /path/to/tomcat/webapps2/otherapp
If I understand your suggestion correctly, that would make
http://localhost/myapp/ and http://localhost:666/otherapp/ equivalent -
not what I want - and it requires me to install two copies of the
servlet in different locations?
Mike.
This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.
If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message.
Thank you for your co-operation.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Redirecting a port to a webapp
Posted by Pid <pi...@pidster.com>.
On 23/11/2009 13:06, Looijmans, Mike wrote:
>> Because you want different sets of webapps served on your
>> different connectors, I *think* you'll need two different
>> Services in your server.xml:
>>
>> <Server>
>> <Service> for port 80
>> <Connector> for port 80
>> <Engine> for port 80
>> <Host> for port 80, specifying base directory for your
>> port 80 webapps
>> </Engine> for port 80
>> </Service> for port 80
>>
>> <Service> for port 666
>> <Connector> for port 666
>> <Engine> for port 666
>> <Host> for port 666, specifying base directory for your
>> port 666 webapps
>> </Engine> for port 666
>> </Service> for port 666
>> </Server>
>>
>> The fastest way to make such a configuration will be to edit
>> your existing server.xml, copy+paste the
>> <Service>...</Service> section (which is most of the file)
>> and hack at the copy as necessary.
>
> I tried this, just to be able to make some progress on the actual
> project, but it does not work as expected. I copied the<server> part
> and replaced:
>
> <Host name="localhost" appBase="webapps" />
>
> with
>
> <Host name="localhost" appBase="webapps/myapp" />
You're telling the Host to look for war files or exploded app
directories in "webapps/myapp".
Instead, set it to "webapps2" or a similar existing directory and place
the web app inside that directory.
/path/to/tomcat/webapps
/path/to/tomcat/webapps/ROOT
/path/to/tomcat/webapps/myapp
/path/to/tomcat/webapps2/ROOT
/path/to/tomcat/webapps2/otherapp
p
> And changed the connector to use port 666. The result is that when I
> browse to http://localhost:666/ I get a blank page. No error message,
> just "nothing". If I change the Host thing to read:
>
> <Host name="localhost" appBase="webapps/aDirThatDoesNotExistAtAll"
> />
>
> I get the same result: Silently nothing.
>
> If I revert the Host part by removing the subdir, I can acess
> http://localhost:666/myapp just fine.
>
> Duh?
>
> Mike.
>
> This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.
>
> If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
>
> If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message.
>
> Thank you for your co-operation.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Redirecting a port to a webapp
Posted by "Looijmans, Mike" <mi...@oce.com>.
> Because you want different sets of webapps served on your
> different connectors, I *think* you'll need two different
> Services in your server.xml:
>
> <Server>
> <Service> for port 80
> <Connector> for port 80
> <Engine> for port 80
> <Host> for port 80, specifying base directory for your
> port 80 webapps
> </Engine> for port 80
> </Service> for port 80
>
> <Service> for port 666
> <Connector> for port 666
> <Engine> for port 666
> <Host> for port 666, specifying base directory for your
> port 666 webapps
> </Engine> for port 666
> </Service> for port 666
> </Server>
>
> The fastest way to make such a configuration will be to edit
> your existing server.xml, copy+paste the
> <Service>...</Service> section (which is most of the file)
> and hack at the copy as necessary.
I tried this, just to be able to make some progress on the actual
project, but it does not work as expected. I copied the <server> part
and replaced:
<Host name="localhost" appBase="webapps" />
with
<Host name="localhost" appBase="webapps/myapp" />
And changed the connector to use port 666. The result is that when I
browse to http://localhost:666/ I get a blank page. No error message,
just "nothing". If I change the Host thing to read:
<Host name="localhost" appBase="webapps/aDirThatDoesNotExistAtAll"
/>
I get the same result: Silently nothing.
If I revert the Host part by removing the subdir, I can acess
http://localhost:666/myapp just fine.
Duh?
Mike.
This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.
If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message.
Thank you for your co-operation.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Redirecting a port to a webapp
Posted by André Warnier <aw...@ice-sa.com>.
Peter Crowther wrote:
...
> You might, however, be able to get what you want using a combination of
> http://tuckey.org/urlrewrite/ and two Connectors defined on the same
> Service.
>
That indeed looks to me like a way, if you want to stay entirely within
Tomcat. It would have the benefit that there is only one Tomcat and that
webapps can communicate.
But is a bit tricky to set up, since the URLs you want to redirect are
"/xxx", so you will need a dummy "/xxx" webapp, to set the urlrewrite
filter into, and re-direct the calls to "/myapp/xxx".
Otherwise, I would say to use an Apache front-end, with mod_proxy or
mod_proxy_ajp or mod_jk, and possibly mod_rewrite to rewrite the URLs.
It is relatively trivial if you know Apache httpd.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Redirecting a port to a webapp
Posted by Peter Crowther <pe...@melandra.com>.
2009/11/23 Looijmans, Mike <mi...@oce.com>
> Hello,
>
> After hours of googling and browsing documentation, i came to the
> conclusion that what i want is either so trivial that everybody knows how to
> do it, or so complicated that no one ever tried it...
>
> I want to accomplish the following in Tomcat 5.5:
>
> http://myserver:80/xxx just does whatever it always does.
> http://myserver:666/xxx is equivalent to http://myserver:80/myapp/xxx
>
> So i want all requests targetted at a particular port (666) in this case to
> be forwarded to a particular servlet, which is also served under its own
> subdirectory on the regular HTTP port 80.
>
> I can set up a connector at port 666 and have all its request go somewhere
> else, but then the application cannot be reached through the normal port
> (80), which is crucial for this thing to work. Installing two copies will
> accomplish that, but then the two copies live in different universes and
> cannot communicate - and setting up some IPC between them is overkill i'd
> say.
>
> It's not at all obvious :-). You can sort-of pick the bones out of
http://tomcat.apache.org/tomcat-5.5-doc/index.html , but unfortunately I've
always found the official Tomcat docs to be very short of worked examples.
Because you want different sets of webapps served on your different
connectors, I *think* you'll need two different Services in your server.xml:
<Server>
<Service> for port 80
<Connector> for port 80
<Engine> for port 80
<Host> for port 80, specifying base directory for your port 80 webapps
</Engine> for port 80
</Service> for port 80
<Service> for port 666
<Connector> for port 666
<Engine> for port 666
<Host> for port 666, specifying base directory for your port 666
webapps
</Engine> for port 666
</Service> for port 666
</Server>
The fastest way to make such a configuration will be to edit your existing
server.xml, copy+paste the <Service>...</Service> section (which is most of
the file) and hack at the copy as necessary.
Note that you'll end up with two independent copies of the servlet in your
two webapp directories, and they won't share things like Sessions between
them. I can't think of a way of doing that using just Tomcat's features.
You might, however, be able to get what you want using a combination of
http://tuckey.org/urlrewrite/ and two Connectors defined on the same
Service.
Good luck!
- Peter