You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by JanAa <ja...@norse-solutions.com> on 2011/05/12 12:28:04 UTC

Multiple context paths for single deployment

Hi,

I want to have more than one context path for a single deployment in Tomcat
5.5.28. Whatever I do I seem to get multiple deployments.
In server.xml I have:
      <Host name="localhost" appBase="webapps"
       unpackWARs="true" autoDeploy="false" deployIgnore="alternative"
       xmlValidation="false" xmlNamespaceAware="false">

In conf/Catalina/localhost I have two .xml files ("primary.xml" and
"alternative.xml") both containing:
<Context docBase="/opt/tomcat/multiapps/primary">
</Context>

In /opt/tomcat/multiapps/primary the web app resides.

In the web app I want to be able to use getContextPath() and get response
based on what URL used to access (either "www.mydomain.com/primary" or
"www.mydomain.com/alternative")

Can anyone help?

-Jan
-- 
View this message in context: http://old.nabble.com/Multiple-context-paths-for-single-deployment-tp31601866p31601866.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


RE: Multiple context paths for single deployment

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Jess Holle [mailto:jessh@ptc.com] 
> Subject: Re: Multiple context paths for single deployment

> In Tomcat versions up through 6.0, I have cases where I have 1 expanded 
> WAR directory (outside Tomcat's webapps, etc) and then numerous 
> disparate Context XML files under Tomcat/conf, each with their own 
> overrides to the original web.xml (e.g. each getting their own data 
> sources, JNDI env values, context name, etc).

Yes, that still works fine - but it's not what the OP is asking for.  He specifically requested *one* application deployment, with multiple URL paths for the *same* application.  If what he really wants is multiple deployments using a single copy of the .war file, then keeping the .war outside of the <Host> appBase and pointing multiple <Context> elements at it from conf/Catalina/[host] would do nicely.  But these are still multiple deployments, and would not be the same application, even though they originate from the same location.

 - 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: Multiple context paths for single deployment

Posted by Jess Holle <je...@ptc.com>.
Hmm....

In Tomcat versions up through 6.0, I have cases where I have 1 expanded 
WAR directory (outside Tomcat's webapps, etc) and then numerous 
disparate Context XML files under Tomcat/conf, each with their own 
overrides to the original web.xml (e.g. each getting their own data 
sources, JNDI env values, context name, etc).

It was my understanding that the web.xml override capability of Context 
was broken in Tomcat 7 (and/or the most recent Tomcat 6??) -- at least 
for a while, hopefully this has been fixed.

Otherwise, however, this seems to work nicely -- 1 deployment, 'n' URLs 
with 'n' disparate context paths.  It does, of course, load 'n' copies 
of all the JSPs, etc, etc -- so there's definitely some downside in 
terms of overhead.  It is a quick and dirty way to deploy numerous 
instances of a web app which has unfortunate singletons, e.g. data 
sources, where you belatedly discover you want a cardinality of 'n' 
rather than 1.

--
Jess Holle

On 5/13/2011 8:56 AM, Caldarale, Charles R wrote:
>> From: JanAa [mailto:jan.aagedal@norse-solutions.com]
>> Subject: Re: Multiple context paths for single deployment
>> What I want is an alias for the context so that more than
>> one url can be used for the same application and that the
>> url used is reflected in HttpServletRequest.getContextPath().
> Those are conflicting requirements.  Pick one or the other - you can't have both.
>
> (Actually, you can, but it would be a major pain.  If you wrote a filter that wrapped every HttpServletRequest object and implemented your own getContextPath() method, you could choose to return whatever you want for the result.)
>
>   - 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

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


RE: Multiple context paths for single deployment

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
> Subject: Re: Multiple context paths for single deployment

> Now, one might still be able to use this technique if 
> you deploy to ROOT and alias /both/ URI prefixes you 
> want to use, like this:

> path="ROOT" aliases="/foo=path/to/war, /bar=path/to/war"

Yes, that's what I was thinking (other than the invalid path of "ROOT" that you've specified).

> I would also suspect that request.getContextPath would 
> return "" in all uses.

That's the part that's unknown without experimentation.

 - 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: Multiple context paths for single deployment

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

On 5/13/2011 10:36 AM, Caldarale, Charles R wrote:
> "
> This attribute provides a list of external locations from which to
> load resources for this context. The list of aliases should be of the
> form "/aliasPath1=docBase1,/aliasPath2=docBase2" where aliasPathN
> must include a leading '/' and docBaseN must be an absolute path to
> either a .war file or a directory.
> 
> A resource will be searched for in the first docBaseN for which
> aliasPathN is a leading path segment of the resource. If there is no
> such alias, then the resource will be searched in the usual way.
> "
> 
> If you set each /aliasPath to the same .war file or directory, this
> may achieve your goal.

A dirty little trick that might actually work.

However.

I would expect that the /aliasPathN would be rooted in the webapp's
context path URI space, so if you had a webapp deployed as, say "/foo"
and then aliased "/bar" to foo.war, you'd end up with the /foo webapp
being available on both /foo and /foo/bar.

This feature was designed to allow URI spaces to be mapped to a physical
directory outside of the deployed webapp, say, for static content stored
elsewhere. That's why I suspect that the context path will be required.

Now, one might still be able to use this technique if you deploy to ROOT
and alias /both/ URI prefixes you want to use, like this:

path="ROOT" aliases="/foo=path/to/war, /bar=path/to/war"

In this case, the webapp is available on all of these virtual context paths:

  /
  /foo
  /bar

I would also suspect that request.getContextPath would return "" in all
uses.

It may be better for the OP to just use UrlRewrite.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3NTMQACgkQ9CaO5/Lv0PB81QCfXa74u/5auaLNdEjmF0aBXvHB
23MAnjmiQcqPLzJ4xmN8L4SnXV6TDP+r
=jrah
-----END PGP SIGNATURE-----

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


RE: Multiple context paths for single deployment

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: JanAa [mailto:jan.aagedal@norse-solutions.com] 
> Subject: RE: Multiple context paths for single deployment

> What I want is an alias for the context so that more than 
> one url can be used for the same application and that the
> url used is reflected in HttpServletRequest.getContextPath().

I just realized that Tomcat 7 does have an alias capability that might be configured for what you want, but I haven't tried it.  Here's some of the description from:

http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Standard_Implementation


aliases	

This attribute provides a list of external locations from which to load resources for this context. The list of aliases should be of the form "/aliasPath1=docBase1,/aliasPath2=docBase2" where aliasPathN must include a leading '/' and docBaseN must be an absolute path to either a .war file or a directory.

A resource will be searched for in the first docBaseN for which aliasPathN is a leading path segment of the resource. If there is no such alias, then the resource will be searched in the usual way.


If you set each /aliasPath to the same .war file or directory, this may achieve your goal.

 - 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: Multiple context paths for single deployment

Posted by André Warnier <aw...@ice-sa.com>.
JanAa wrote:
> Thanks for replying.
> 
> I was under the impression that the difference between
> HttpServletRequest.getContextPath and ServletContext.getContextPath() was
> exactly that the first returned the context path used in the request while
> the second returned the context path used when processing
> (http://download.oracle.com/javaee/5/api/javax/servlet/ServletContext.html#getContextPath()).
> 
> I realise I have to find another route, I still need multiple urls to one
> application, and I have to identify these in the code. I am thinking about
> an urlrewritefilter that sets a request-attribute, and then use an
> outbound-rule to not show this to the users. Any other/better proposal?
> 
How about this :
- deploy your application as the ROOT (default) application
- create a Servlet Filter, which wraps the request in a HttpServletRequestWrapper
- the HttpServletRequestWrapper redefines the getContextPah method
- your getContextPath returns whatever you want, in function of the original request URL
That would be independent of the servlet engine version.
I'd still have a look at the above solution with urlrewritefilter though, because it can 
do many other things in addition to what you mention above, and you do not need to write it.


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


RE: Multiple context paths for single deployment

Posted by JanAa <ja...@norse-solutions.com>.
Thanks for replying.

I was under the impression that the difference between
HttpServletRequest.getContextPath and ServletContext.getContextPath() was
exactly that the first returned the context path used in the request while
the second returned the context path used when processing
(http://download.oracle.com/javaee/5/api/javax/servlet/ServletContext.html#getContextPath()).

I realise I have to find another route, I still need multiple urls to one
application, and I have to identify these in the code. I am thinking about
an urlrewritefilter that sets a request-attribute, and then use an
outbound-rule to not show this to the users. Any other/better proposal?

-Jan 


n828cl wrote:
> 
>> From: JanAa [mailto:jan.aagedal@norse-solutions.com] 
>> Subject: Re: Multiple context paths for single deployment
> 
>> What I want is an alias for the context so that more than 
>> one url can be used for the same application and that the
>> url used is reflected in HttpServletRequest.getContextPath(). 
> 
> Those are conflicting requirements.  Pick one or the other - you can't
> have both.
> 
> (Actually, you can, but it would be a major pain.  If you wrote a filter
> that wrapped every HttpServletRequest object and implemented your own
> getContextPath() method, you could choose to return whatever you want for
> the result.)
> 
> 

-- 
View this message in context: http://old.nabble.com/Multiple-context-paths-for-single-deployment-tp31601866p31611838.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


RE: Multiple context paths for single deployment

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: JanAa [mailto:jan.aagedal@norse-solutions.com] 
> Subject: Re: Multiple context paths for single deployment

> What I want is an alias for the context so that more than 
> one url can be used for the same application and that the
> url used is reflected in HttpServletRequest.getContextPath(). 

Those are conflicting requirements.  Pick one or the other - you can't have both.

(Actually, you can, but it would be a major pain.  If you wrote a filter that wrapped every HttpServletRequest object and implemented your own getContextPath() method, you could choose to return whatever you want for the result.)

 - 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: Multiple context paths for single deployment

Posted by JanAa <ja...@norse-solutions.com>.
Hi,

thanks for replying.

What I want is an alias for the context so that more than one url can be
used for the same application and that the url used is reflected in
HttpServletRequest.getContextPath(). 

Currently I get two deployments, then getContextPath() returns those two
values as expected. I want to get rid of the double deployment but still get
the proper context path.

-Jan 


Pid * wrote:
> 
> On 12/05/2011 11:28, JanAa wrote:
>> 
>> Hi,
>> 
>> I want to have more than one context path for a single deployment in
>> Tomcat
>> 5.5.28. Whatever I do I seem to get multiple deployments.
>> In server.xml I have:
>>       <Host name="localhost" appBase="webapps"
>>        unpackWARs="true" autoDeploy="false" deployIgnore="alternative"
>>        xmlValidation="false" xmlNamespaceAware="false">
>> 
>> In conf/Catalina/localhost I have two .xml files ("primary.xml" and
>> "alternative.xml") both containing:
>> <Context docBase="/opt/tomcat/multiapps/primary">
>> </Context>
>> 
>> In /opt/tomcat/multiapps/primary the web app resides.
> 
> By defining multiple contexts, you are getting exactly that.
> 
> 
>> In the web app I want to be able to use getContextPath() and get response
>> based on what URL used to access (either "www.mydomain.com/primary" or
>> "www.mydomain.com/alternative")
> 
> What are you getting now?
> 
> 
> p
> 
>> Can anyone help?
> 
> 
> 
>  
> 

-- 
View this message in context: http://old.nabble.com/Multiple-context-paths-for-single-deployment-tp31601866p31610033.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


Re: Multiple context paths for single deployment

Posted by Pid <pi...@pidster.com>.
On 12/05/2011 11:28, JanAa wrote:
> 
> Hi,
> 
> I want to have more than one context path for a single deployment in Tomcat
> 5.5.28. Whatever I do I seem to get multiple deployments.
> In server.xml I have:
>       <Host name="localhost" appBase="webapps"
>        unpackWARs="true" autoDeploy="false" deployIgnore="alternative"
>        xmlValidation="false" xmlNamespaceAware="false">
> 
> In conf/Catalina/localhost I have two .xml files ("primary.xml" and
> "alternative.xml") both containing:
> <Context docBase="/opt/tomcat/multiapps/primary">
> </Context>
> 
> In /opt/tomcat/multiapps/primary the web app resides.

By defining multiple contexts, you are getting exactly that.


> In the web app I want to be able to use getContextPath() and get response
> based on what URL used to access (either "www.mydomain.com/primary" or
> "www.mydomain.com/alternative")

What are you getting now?


p

> Can anyone help?