You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by peter lin <pe...@labs.gte.com> on 2002/07/29 14:48:38 UTC

ServletContextListener bug #11043

I've posted this question last week and talked to Remmy, but Remmy is
busy with moving.  I spent some time this weekend trying to track down
the bug, but couldn't figure it out.  I'm hoping if I describe the bug
more clearly, someone can point me in the right direction.

The bug is the following:

If I have server.xml set with all the defaults and I have a
ServletContextListener defined in web.xml, Tomcat correctly creates an
instance of my listener and starts my test application. If I add a
webapp, it also correctly creates an instance of my listener and starts
the test application.


If on the otherhand I change server.xml to point to a different
directory for the default root path from "ROOT" to say "myapp", Tomcat
ends up creating two separate instances of the listener. Both listeners
get contextInitialized() event and create one instance of my test
application per listener.  The correct behavior should be the same as
leaving the root directory to the default "ROOT".

If I use 4.1.8 and load up the manager, I see webapp "/" and "/myapp".
This explains why two separate instances of my listener are created. I
only want 1 instance of my test application to startup with tomcat,
since it loads global configuration values into memory.

I looked in catalina.core.StandardContext, but I don't see which class
is responsible for creating the listener listed in web.xml.  Is the
behavior of creating two instances of my listener according to
specification?  Is there something special about changing the default
root path from "ROOT" to some other "myapp" path?


peter lin

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ServletContextListener bug #11043

Posted by peter lin <pe...@labs.gte.com>.

Simon Oldeboershuis wrote:
> 
> Hi Peter,
> 
> as far as I know, tomcat does the following:
> - starting a webapp for each webapp in tomcat/webapps
> - starting a webapp for each extra configured webapp from server.xml
> 
> My solution was to map the path
>         /myApp to the ROOT webapp
> and the Path
>         / to the myApp webapp

yeah, I've tried that on unxi with a symlink and it works fine. Like I
said in previous posts, it's not critical, since I can just change the
directory name from "myapp" to "ROOT".  It's only an inconvienance for
deployment testing where the source repository uses a name other than
"ROOT". It adds the extra step of renaming the directory.

> 
> Therefore the default path for /myApp was overridden.
> I did not test this with tomcat 4.1.x, but you could give it a try.
> 
> The other solution is, not to put your webapp in the tomcat/webapps
> directory and configure the path in server.xml.
> 
> Greetings!
> Simon
> 
>

the bug appears in 4.0.3, 4.0.4 and 4.1.8.  Perhaps someone with better
knowledge of how tomcat loads the webapps could chime in.  I am willing
to dedicate my own time to patching this.

peter lin

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ServletContextListener bug #11043

Posted by Simon Oldeboershuis <so...@outermedia.de>.
Hi Peter,

as far as I know, tomcat does the following:
- starting a webapp for each webapp in tomcat/webapps
- starting a webapp for each extra configured webapp from server.xml

My solution was to map the path 
	/myApp to the ROOT webapp
and the Path 
	/ to the myApp webapp

Therefore the default path for /myApp was overridden. 
I did not test this with tomcat 4.1.x, but you could give it a try.

The other solution is, not to put your webapp in the tomcat/webapps
directory and configure the path in server.xml.

Greetings!
Simon

peter lin schrieb:
> 
> I've posted this question last week and talked to Remmy, but Remmy is
> busy with moving.  I spent some time this weekend trying to track down
> the bug, but couldn't figure it out.  I'm hoping if I describe the bug
> more clearly, someone can point me in the right direction.
> 
> The bug is the following:
> 
> If I have server.xml set with all the defaults and I have a
> ServletContextListener defined in web.xml, Tomcat correctly creates an
> instance of my listener and starts my test application. If I add a
> webapp, it also correctly creates an instance of my listener and starts
> the test application.
> 
> If on the otherhand I change server.xml to point to a different
> directory for the default root path from "ROOT" to say "myapp", Tomcat
> ends up creating two separate instances of the listener. Both listeners
> get contextInitialized() event and create one instance of my test
> application per listener.  The correct behavior should be the same as
> leaving the root directory to the default "ROOT".
> 
> If I use 4.1.8 and load up the manager, I see webapp "/" and "/myapp".
> This explains why two separate instances of my listener are created. I
> only want 1 instance of my test application to startup with tomcat,
> since it loads global configuration values into memory.
> 
> I looked in catalina.core.StandardContext, but I don't see which class
> is responsible for creating the listener listed in web.xml.  Is the
> behavior of creating two instances of my listener according to
> specification?  Is there something special about changing the default
> root path from "ROOT" to some other "myapp" path?
> 
> peter lin
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ServletContextListener bug #11043

Posted by peter lin <pe...@labs.gte.com>.
thanks craig for clarifying that.  I'll stick with using symlinks, since
a fix would be a big task.

peter lin


"Craig R. McClanahan" wrote:
> 
> What you describe isn't a bug -- it's a direct consequence of the way
> auto-mount works in the "appBase" directory of a Host (i.e. the "webapps"
> directory).
> 
> Normally, Tomcat examines all the contents of the "webapps" directory, and
> (if it's a WAR or a directory) tries to automatically mount a webapp with
> the corresponding name as the context path -- thus the "examples"
> directory is automatically mounted at context path "/examples", the
> "tomcat-docs" directory is automatically mounted at "/tomcat-docs", and so
> on.
> 
> The root directory is a case where we can't do this -- conforming to this
> pattern would require us to have a zero-length pathname, which most OSs
> are not too happy with.  Therefore, there is a special case that the
> directory name ROOT will be mounted as the root webapp.
> 
> If you don't want two instances of you webapp, it's really very simple:
> 
> * Don't change the docBase for the ROOT partition
> 
> * Use an absolute docBase that points to a directory not under webapps.
> 
> By the way, you can cause the same sort of problem with any other context
> that is explicitly configured in server.xml -- for example, add a new
> <Context> entry just before the one for "/examples" like this, and see
> what happens::
> 
>   <Context path="/foo" docBase="examples"/>
> 
> Craig
> 
> On Mon, 29 Jul 2002, peter lin wrote:
> 
> > Date: Mon, 29 Jul 2002 08:48:38 -0400
> > From: peter lin <pe...@labs.gte.com>
> > Reply-To: Tomcat Developers List <to...@jakarta.apache.org>
> > To: Tomcat Developers List <to...@jakarta.apache.org>
> > Subject: ServletContextListener bug #11043
> >
> >
> > I've posted this question last week and talked to Remmy, but Remmy is
> > busy with moving.  I spent some time this weekend trying to track down
> > the bug, but couldn't figure it out.  I'm hoping if I describe the bug
> > more clearly, someone can point me in the right direction.
> >
> > The bug is the following:
> >
> > If I have server.xml set with all the defaults and I have a
> > ServletContextListener defined in web.xml, Tomcat correctly creates an
> > instance of my listener and starts my test application. If I add a
> > webapp, it also correctly creates an instance of my listener and starts
> > the test application.
> >
> >
> > If on the otherhand I change server.xml to point to a different
> > directory for the default root path from "ROOT" to say "myapp", Tomcat
> > ends up creating two separate instances of the listener. Both listeners
> > get contextInitialized() event and create one instance of my test
> > application per listener.  The correct behavior should be the same as
> > leaving the root directory to the default "ROOT".
> >
> > If I use 4.1.8 and load up the manager, I see webapp "/" and "/myapp".
> > This explains why two separate instances of my listener are created. I
> > only want 1 instance of my test application to startup with tomcat,
> > since it loads global configuration values into memory.
> >
> > I looked in catalina.core.StandardContext, but I don't see which class
> > is responsible for creating the listener listed in web.xml.  Is the
> > behavior of creating two instances of my listener according to
> > specification?  Is there something special about changing the default
> > root path from "ROOT" to some other "myapp" path?
> >
> >
> > peter lin
> >
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
> >
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ServletContextListener bug #11043

Posted by "Craig R. McClanahan" <cr...@apache.org>.
What you describe isn't a bug -- it's a direct consequence of the way
auto-mount works in the "appBase" directory of a Host (i.e. the "webapps"
directory).

Normally, Tomcat examines all the contents of the "webapps" directory, and
(if it's a WAR or a directory) tries to automatically mount a webapp with
the corresponding name as the context path -- thus the "examples"
directory is automatically mounted at context path "/examples", the
"tomcat-docs" directory is automatically mounted at "/tomcat-docs", and so
on.

The root directory is a case where we can't do this -- conforming to this
pattern would require us to have a zero-length pathname, which most OSs
are not too happy with.  Therefore, there is a special case that the
directory name ROOT will be mounted as the root webapp.

If you don't want two instances of you webapp, it's really very simple:

* Don't change the docBase for the ROOT partition

* Use an absolute docBase that points to a directory not under webapps.

By the way, you can cause the same sort of problem with any other context
that is explicitly configured in server.xml -- for example, add a new
<Context> entry just before the one for "/examples" like this, and see
what happens::

  <Context path="/foo" docBase="examples"/>

Craig


On Mon, 29 Jul 2002, peter lin wrote:

> Date: Mon, 29 Jul 2002 08:48:38 -0400
> From: peter lin <pe...@labs.gte.com>
> Reply-To: Tomcat Developers List <to...@jakarta.apache.org>
> To: Tomcat Developers List <to...@jakarta.apache.org>
> Subject: ServletContextListener bug #11043
>
>
> I've posted this question last week and talked to Remmy, but Remmy is
> busy with moving.  I spent some time this weekend trying to track down
> the bug, but couldn't figure it out.  I'm hoping if I describe the bug
> more clearly, someone can point me in the right direction.
>
> The bug is the following:
>
> If I have server.xml set with all the defaults and I have a
> ServletContextListener defined in web.xml, Tomcat correctly creates an
> instance of my listener and starts my test application. If I add a
> webapp, it also correctly creates an instance of my listener and starts
> the test application.
>
>
> If on the otherhand I change server.xml to point to a different
> directory for the default root path from "ROOT" to say "myapp", Tomcat
> ends up creating two separate instances of the listener. Both listeners
> get contextInitialized() event and create one instance of my test
> application per listener.  The correct behavior should be the same as
> leaving the root directory to the default "ROOT".
>
> If I use 4.1.8 and load up the manager, I see webapp "/" and "/myapp".
> This explains why two separate instances of my listener are created. I
> only want 1 instance of my test application to startup with tomcat,
> since it loads global configuration values into memory.
>
> I looked in catalina.core.StandardContext, but I don't see which class
> is responsible for creating the listener listed in web.xml.  Is the
> behavior of creating two instances of my listener according to
> specification?  Is there something special about changing the default
> root path from "ROOT" to some other "myapp" path?
>
>
> peter lin
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>