You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jerry Malcolm <te...@malcolms.com> on 2021/07/09 05:58:33 UTC
Mixing Root Context webapp with other webapps
I have one webapp that processes REST-style url paths and therefore
needs to run in the ROOT context. Is it possible to run other webapps
in the same host with other non-root contexts? In other words, when
resolving a URL to a web app, does it try to map the url to the defined
context strings first, and then to ROOT if there are no matches? Or
does ROOT override everything, and all URLs go to ROOT if it's defined?
Thanks.
Jerry
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Mixing Root Context webapp with other webapps
Posted by Mark Thomas <ma...@apache.org>.
On 09/07/2021 08:23, Olaf Kock wrote:
>
> On 09.07.21 07:58, Jerry Malcolm wrote:
>> I have one webapp that processes REST-style url paths and therefore
>> needs to run in the ROOT context. Is it possible to run other webapps
>> in the same host with other non-root contexts? In other words, when
>> resolving a URL to a web app, does it try to map the url to the
>> defined context strings first, and then to ROOT if there are no
>> matches? Or does ROOT override everything, and all URLs go to ROOT if
>> it's defined?
>>
> If memory serves me well and this behavior didn't change in the past
> decade, then all other web applications have precedence over root. That
> is, if you deploy ROOT.war and json.war (and assume the context-path to
> be /json), then your root application's /json path would never be reached.
>
> It's easy to visualize this way around, because it's an absolutely
> static mapping with the size being "number of webapps", while the other
> way around, ROOT could also map /* to one of its servlets and then
> determine what to do it. The spec has to means to explicitly hand a
> request back to the appserver and every app would rather generate 404
> than check if somebody else might be there to handle it.
To put it another way, when mapping a request to a web application Tomcat:
- normalises the request URL
- routes the request to the web application with the longest matching
context path
The exact wording is in section 12 of the Servlet specification.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Mixing Root Context webapp with other webapps
Posted by Jerry Malcolm <te...@malcolms.com>.
On 7/9/2021 2:23 AM, Olaf Kock wrote:
> On 09.07.21 07:58, Jerry Malcolm wrote:
>> I have one webapp that processes REST-style url paths and therefore
>> needs to run in the ROOT context. Is it possible to run other webapps
>> in the same host with other non-root contexts? In other words, when
>> resolving a URL to a web app, does it try to map the url to the
>> defined context strings first, and then to ROOT if there are no
>> matches? Or does ROOT override everything, and all URLs go to ROOT if
>> it's defined?
>>
> If memory serves me well and this behavior didn't change in the past
> decade, then all other web applications have precedence over root. That
> is, if you deploy ROOT.war and json.war (and assume the context-path to
> be /json), then your root application's /json path would never be reached.
>
> It's easy to visualize this way around, because it's an absolutely
> static mapping with the size being "number of webapps", while the other
> way around, ROOT could also map /* to one of its servlets and then
> determine what to do it. The spec has to means to explicitly hand a
> request back to the appserver and every app would rather generate 404
> than check if somebody else might be there to handle it.
>
> Olaf
>
>
Thanks for the quick response, Olaf. That's the way I was hoping it
worked... :-)
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Mixing Root Context webapp with other webapps
Posted by Olaf Kock <to...@olafkock.de>.
On 09.07.21 07:58, Jerry Malcolm wrote:
> I have one webapp that processes REST-style url paths and therefore
> needs to run in the ROOT context. Is it possible to run other webapps
> in the same host with other non-root contexts? In other words, when
> resolving a URL to a web app, does it try to map the url to the
> defined context strings first, and then to ROOT if there are no
> matches? Or does ROOT override everything, and all URLs go to ROOT if
> it's defined?
>
If memory serves me well and this behavior didn't change in the past
decade, then all other web applications have precedence over root. That
is, if you deploy ROOT.war and json.war (and assume the context-path to
be /json), then your root application's /json path would never be reached.
It's easy to visualize this way around, because it's an absolutely
static mapping with the size being "number of webapps", while the other
way around, ROOT could also map /* to one of its servlets and then
determine what to do it. The spec has to means to explicitly hand a
request back to the appserver and every app would rather generate 404
than check if somebody else might be there to handle it.
Olaf
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Mixing Root Context webapp with other webapps
Posted by Christopher Schultz <ch...@christopherschultz.net>.
Jerry,
On 7/9/21 01:58, Jerry Malcolm wrote:
> I have one webapp that processes REST-style url paths and therefore
> needs to run in the ROOT context.
I'm not sure the conclusion follows from the premise, here. You can
certainly use REST-style URL paths and not have a context at the top-level.
> Is it possible to run other webapps
> in the same host with other non-root contexts?
It is, but I wouldn't recommend it. Well... I would definitely recommend
/against/ it in some situations. Specifically, when both the root and
other web applications both need to use cookie-based sessions. If you
have two applications fighting over whose JSESSIONID cookie is the one
to use for login, Bad Things can happen.
If your root context and/or none of the non-root contexts will be using
cookie-based session-tracking, then you will probably be fine.
> In other words, when resolving a URL to a web app, does it try to map
> the url to the defined context strings first, and then to ROOT if
> there are no matches? Or does ROOT override everything, and all URLs
> go to ROOT if it's defined?
It's the latter, otherwise it would be pretty much impossible to deploy
anything when a ROOT context was present.
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org