multiple context paths pointing to the same doc base?

2001-08-22 Thread Vladimir Grishchenko

Hi there,

May be somebody can give me a quick answer with regards to T3.2.2.

I need to have multiple context paths to point to the same doc base,
say my server.xml has the following entries:

 Context path=/somectx
  docBase=d:/foo/bar
  debug=0
  reloadable=false 
 /Context


 Context path=/somectx1
  docBase=d:/foo/bar
  debug=0
  reloadable=false 
 /Context

Will the above config cause my webapp classes/servlets to be loaded
twice through different classloaders, or TC is smart enough to realize
it's the same webapp?

Thanks,
--V.



Re: multiple context paths pointing to the same doc base?

2001-08-22 Thread Craig R. McClanahan



On Wed, 22 Aug 2001, Vladimir Grishchenko wrote:

 Hi there,

 May be somebody can give me a quick answer with regards to T3.2.2.

 I need to have multiple context paths to point to the same doc base,
 say my server.xml has the following entries:

  Context path=/somectx
   docBase=d:/foo/bar
   debug=0
   reloadable=false 
  /Context


  Context path=/somectx1
   docBase=d:/foo/bar
   debug=0
   reloadable=false 
  /Context

 Will the above config cause my webapp classes/servlets to be loaded
 twice through different classloaders,

Yes.

 or TC is smart enough to realize
 it's the same webapp?


It is *not* the same webapp.

Every webapp must have a unique context path, and you have just defined
two different context paths here.  The fact that the document base is the
same is just a coincidence.

 Thanks,
 --V.


Craig





Re: multiple context paths pointing to the same doc base?

2001-08-22 Thread Vladimir Grishchenko

Thanks for the clarification, it makes sense.
Is it according to the spec or just a peculiarity of Tomcat?

Actually, I need just the opposite, is there any way to do this? Meaning
different context paths - one webapp and one class loader...

Thanks,
--V.

- Original Message - 
From: Craig R. McClanahan [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, August 22, 2001 9:41 AM
Subject: Re: multiple context paths pointing to the same doc base?


 
 
 On Wed, 22 Aug 2001, Vladimir Grishchenko wrote:
 
  Hi there,
 
  May be somebody can give me a quick answer with regards to T3.2.2.
 
  I need to have multiple context paths to point to the same doc base,
  say my server.xml has the following entries:
 
   Context path=/somectx
docBase=d:/foo/bar
debug=0
reloadable=false 
   /Context
 
 
   Context path=/somectx1
docBase=d:/foo/bar
debug=0
reloadable=false 
   /Context
 
  Will the above config cause my webapp classes/servlets to be loaded
  twice through different classloaders,
 
 Yes.
 
  or TC is smart enough to realize
  it's the same webapp?
 
 
 It is *not* the same webapp.
 
 Every webapp must have a unique context path, and you have just defined
 two different context paths here.  The fact that the document base is the
 same is just a coincidence.
 
  Thanks,
  --V.
 
 
 Craig
 
 
 



Re: multiple context paths pointing to the same doc base?

2001-08-22 Thread Craig R. McClanahan



On Wed, 22 Aug 2001, Vladimir Grishchenko wrote:

 Thanks for the clarification, it makes sense.
 Is it according to the spec or just a peculiarity of Tomcat?


Servlet 2.3 PFD2, Section 3.1 (emphasis added by **):

  A ServletContext is rooted at *a* known
  path within the web server.  For example,
  a servlet context could be located at
  http://www.mycorp.com/catalog.  All requests
  that begin with the /catalog request path,
  known as the context path, are routed to
  the web application associated with the
  servlet context.

 Actually, I need just the opposite, is there any way to do this? Meaning
 different context paths - one webapp and one class loader...


Not that I know of.

Of course, that begs the question of *why* you need this -- if everything
is identical (as it would be if you got your wish), then what's the point?

 Thanks,
 --V.


Craig


 - Original Message -
 From: Craig R. McClanahan [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Wednesday, August 22, 2001 9:41 AM
 Subject: Re: multiple context paths pointing to the same doc base?


 
 
  On Wed, 22 Aug 2001, Vladimir Grishchenko wrote:
 
   Hi there,
  
   May be somebody can give me a quick answer with regards to T3.2.2.
  
   I need to have multiple context paths to point to the same doc base,
   say my server.xml has the following entries:
  
Context path=/somectx
 docBase=d:/foo/bar
 debug=0
 reloadable=false 
/Context
  
  
Context path=/somectx1
 docBase=d:/foo/bar
 debug=0
 reloadable=false 
/Context
  
   Will the above config cause my webapp classes/servlets to be loaded
   twice through different classloaders,
 
  Yes.
 
   or TC is smart enough to realize
   it's the same webapp?
  
 
  It is *not* the same webapp.
 
  Every webapp must have a unique context path, and you have just defined
  two different context paths here.  The fact that the document base is the
  same is just a coincidence.
 
   Thanks,
   --V.
  
 
  Craig
 
 
 





Re: multiple context paths pointing to the same doc base?

2001-08-22 Thread Vladimir Grishchenko

  Thanks for the clarification, it makes sense.
  Is it according to the spec or just a peculiarity of Tomcat?
 

 Servlet 2.3 PFD2, Section 3.1 (emphasis added by **):

   A ServletContext is rooted at *a* known
   path within the web server.  For example,
   a servlet context could be located at
   http://www.mycorp.com/catalog.  All requests
   that begin with the /catalog request path,
   known as the context path, are routed to
   the web application associated with the
   servlet context.


Well, I don't want to be picky but this quote doesn't emphasize
that context is the same thing as web application, nor does it
say that a web application cannot be shared by multiple contexts , it merely
says that all requests are routed to the app associated with
a particular context. In my understanding (which might be wrong btw)
a webapp is something you package and distribute in a *.war file meaning
classes, servlets, jsps, static html, and a webapp can be shared by
different
contexts. Isn't it more correct to have a class loader per *.war file
(logically) than per contextpath? Or have it configurable since  the spec
is somewhat vague on this point?

  Actually, I need just the opposite, is there any way to do this? Meaning
  different context paths - one webapp and one class loader...
 

 Not that I know of.

 Of course, that begs the question of *why* you need this -- if everything
 is identical (as it would be if you got your wish), then what's the point?

Without going into much details my particular application is relying on
combination
of context path and path info values to perform an internal lookup of some
data.
The data is cached and there's a cache maintanence thread running. So, I end
up
with as many caches and threads as many contexts I have configured. Of
course
I can try to interpret request URI's to extract the data I need, but using
context path
is much easier. Well, I guess I have no choice now :-|

--V.


  Thanks,
  --V.
 

 Craig


  - Original Message -
  From: Craig R. McClanahan [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Wednesday, August 22, 2001 9:41 AM
  Subject: Re: multiple context paths pointing to the same doc base?
 
 
  
  
   On Wed, 22 Aug 2001, Vladimir Grishchenko wrote:
  
Hi there,
   
May be somebody can give me a quick answer with regards to T3.2.2.
   
I need to have multiple context paths to point to the same doc base,
say my server.xml has the following entries:
   
 Context path=/somectx
  docBase=d:/foo/bar
  debug=0
  reloadable=false 
 /Context
   
   
 Context path=/somectx1
  docBase=d:/foo/bar
  debug=0
  reloadable=false 
 /Context
   
Will the above config cause my webapp classes/servlets to be loaded
twice through different classloaders,
  
   Yes.
  
or TC is smart enough to realize
it's the same webapp?
   
  
   It is *not* the same webapp.
  
   Every webapp must have a unique context path, and you have just
defined
   two different context paths here.  The fact that the document base is
the
   same is just a coincidence.
  
Thanks,
--V.
   
  
   Craig
  
  
  
 





Re: multiple context paths pointing to the same doc base?

2001-08-22 Thread Craig R. McClanahan



On Wed, 22 Aug 2001, Vladimir Grishchenko wrote:

 Date: Wed, 22 Aug 2001 11:19:47 -0700
 From: Vladimir Grishchenko [EMAIL PROTECTED]
 Reply-To: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: Re: multiple context paths pointing to the same doc base?

   Thanks for the clarification, it makes sense.
   Is it according to the spec or just a peculiarity of Tomcat?
  
 
  Servlet 2.3 PFD2, Section 3.1 (emphasis added by **):
 
A ServletContext is rooted at *a* known
path within the web server.  For example,
a servlet context could be located at
http://www.mycorp.com/catalog.  All requests
that begin with the /catalog request path,
known as the context path, are routed to
the web application associated with the
servlet context.
 

 Well, I don't want to be picky but this quote doesn't emphasize
 that context is the same thing as web application, nor does it
 say that a web application cannot be shared by multiple contexts , it merely
 says that all requests are routed to the app associated with
 a particular context.

Spec language is like legal contracts ... you've got to be familiar with
the nuances :-).  In particular the a above means one and only one.

 In my understanding (which might be wrong btw)
 a webapp is something you package and distribute in a *.war file meaning
 classes, servlets, jsps, static html, and a webapp can be shared by
 different
 contexts.

From the perspective of the container, it is free (from a spec
perspective) to do whatever it wants to with a WAR file.  Some containers
automatically expand them into unpacked directories (like Tomcat does by
default), some run directly from a WAR (like Tomcat can), some store the
static resources as BLOBs in a database.  But the key point is this --
where the resources came from is irrelevant -- each web application is
operated independently.

 Isn't it more correct to have a class loader per *.war file
 (logically) than per contextpath? Or have it configurable since  the spec
 is somewhat vague on this point?

You'll have to find me a servlet container vendor that interprets this the
way you would like in order for me to think it is vague.


   Actually, I need just the opposite, is there any way to do this? Meaning
   different context paths - one webapp and one class loader...
  
 
  Not that I know of.
 
  Of course, that begs the question of *why* you need this -- if everything
  is identical (as it would be if you got your wish), then what's the point?

 Without going into much details my particular application is relying on
 combination
 of context path and path info values to perform an internal lookup of some
 data.
 The data is cached and there's a cache maintanence thread running. So, I end
 up
 with as many caches and threads as many contexts I have configured. Of
 course
 I can try to interpret request URI's to extract the data I need, but using
 context path
 is much easier. Well, I guess I have no choice now :-|


One option you have is to put the classes that actually cache things into
a common directory ($TOMCAT_HOME/lib or $CATALINA_HOME/lib).  Such classes
are shared across web apps, so this should accomplish your goal of having
a single cache.  They are loaded from a (common) parent class loader to
the one for each web app.

The only tricky part of this would be where the classes of the objects
being cached are found.  If your cache logic is in the parent class
loader, but you try to instantiate an object of a class in the web app
using the usual technique (Class.forName().newInstance()), you will get
ClassNotFoundException errors.  This can be worked around by noting that
the Thread context class loader (guaranteed at least for Servlet 2.3 based
containers) will always correspond to the webapp class loader, so your
cache code can do something like this:

  String applicationClassName = ... class name of the object to create ...
  ClassLoader ccl = Thread.currentThread().getContextClassLoader();
  Class clazz = ccl.loadClass(applicationClassName);
  Object instance = clazz.newInstance();

or something similar.

 --V.


Craig




Re: multiple context paths pointing to the same doc base?

2001-08-22 Thread Vladimir Grishchenko


 One option you have is to put the classes that actually cache things into
 a common directory ($TOMCAT_HOME/lib or $CATALINA_HOME/lib).  Such classes
 are shared across web apps, so this should accomplish your goal of having
 a single cache.  They are loaded from a (common) parent class loader to
 the one for each web app.


I'm not using the latest servlet spec (2.3). Anyway, the simplest solutuion
will be to put all my classes
on the system classpath, this should  work. I have no jsp's and don't need
dynamic class
reloading in production, so I beleive it's perfectly legal in my case.

Thanks and regards,

--V.




Re: multiple context paths pointing to the same doc base?

2001-08-22 Thread Dmitri Colebatch

On Wed, 22 Aug 2001, Vladimir Grishchenko wrote:

 
  One option you have is to put the classes that actually cache things into
  a common directory ($TOMCAT_HOME/lib or $CATALINA_HOME/lib).  Such classes
  are shared across web apps, so this should accomplish your goal of having
  a single cache.  They are loaded from a (common) parent class loader to
  the one for each web app.

Wont this still result in one init() call per servlet per context?  The
only think you'll gain is the use of static variables right?  Obviously
these could be used to achieve the desired outcome, but you wouldn't get
one context with two paths...?

 
 
 I'm not using the latest servlet spec (2.3). Anyway, the simplest solutuion
 will be to put all my classes
 on the system classpath, this should  work. I have no jsp's and don't need
 dynamic class
 reloading in production, so I beleive it's perfectly legal in my case.

you would be well advised to put it in a jar which you then place in
tomcat's lib dir... that way its relatively easy to move your app.

cheers
dim




Re: multiple context paths pointing to the same doc base?

2001-08-22 Thread Craig R. McClanahan



On Thu, 23 Aug 2001, Dmitri Colebatch wrote:

 Date: Thu, 23 Aug 2001 06:42:13 +1000
 From: Dmitri Colebatch [EMAIL PROTECTED]
 Reply-To: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: Re: multiple context paths pointing to the same doc base?

 On Wed, 22 Aug 2001, Vladimir Grishchenko wrote:

  
   One option you have is to put the classes that actually cache things into
   a common directory ($TOMCAT_HOME/lib or $CATALINA_HOME/lib).  Such classes
   are shared across web apps, so this should accomplish your goal of having
   a single cache.  They are loaded from a (common) parent class loader to
   the one for each web app.

 Wont this still result in one init() call per servlet per context?

Yes, but the second initialization can easily detect that the cache has
already been initialized.

  The
 only think you'll gain is the use of static variables right?  Obviously
 these could be used to achieve the desired outcome, but you wouldn't get
 one context with two paths...?


Since the original objective was to share the cache, it seems to me that
one versus two contexts is not a big deal, right?

  
 
  I'm not using the latest servlet spec (2.3). Anyway, the simplest solutuion
  will be to put all my classes
  on the system classpath, this should  work. I have no jsp's and don't need
  dynamic class
  reloading in production, so I beleive it's perfectly legal in my case.

 you would be well advised to put it in a jar which you then place in
 tomcat's lib dir... that way its relatively easy to move your app.


In fact, this is critical to the sharing solution.  Eerything in Tomcat's
lib directory is shared -- everything in /WEB-INF/classes or /WEB-INF/lib
is not shared.

 cheers
 dim



Craig





Re: multiple context paths pointing to the same doc base?

2001-08-22 Thread Dmitri Colebatch

On Wed, 22 Aug 2001, Craig R. McClanahan wrote:
 Since the original objective was to share the cache, it seems to me that
 one versus two contexts is not a big deal, right?

ahhh, sorry - missed the start of the thread... thought it was a more
general one webapp thing...

  you would be well advised to put it in a jar which you then place in
  tomcat's lib dir... that way its relatively easy to move your app.
 
 
 In fact, this is critical to the sharing solution.  Eerything in Tomcat's
 lib directory is shared -- everything in /WEB-INF/classes or /WEB-INF/lib
 is not shared.

My reading of the suggestion was that the classes would reside elsewhere
in the system but be in the startup classpath as startup - this would do
the same thing but be a little more spread out... thats all my point was
there (o:

cheesr
dim