You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Garret Wilson <ga...@globalmentor.com> on 2006/06/25 23:32:10 UTC
Tomcat multiple init(), no init param
Tomcat 5.5.16 seems to call a servlet's init() method several times, and
the specific init parameter is missing in all but the first.
I have a simple server.xml that includes:
<Host name="www.example.com" appBase="/var/web/apps"
unpackWARs="false" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>example.com</Alias>
<Context path="" docBase="www.example.com.war">
<Parameter name="dataDirectory"
value="/var/web/data/www.example.com/"/>
</Context>
</Host>
In www.example.com.war I have a web.xml file that includes two instances
of MyServlet, with servlet names of myServlet1 and myServlet2, mapped to
"/*" and "/example/*", respectively.
Tomcat does the following, which I find odd:
1. myServlet1.init() is called. The init parameter "dataDirectory" is
correctly set to "/var/web/data/www.example.com/".
2. catalina.out indicates "Jun 25, 2006 2:07:26 PM
org.apache.catalina.startup.HostConfig deployWAR".
3. myServlet.init is called(). The init parameter "dataDirectory"
returns null.
4. myServlet2.init is called(). The init parameter "dataDirectory"
returns null.
(Then steps 3 and 4 are repeated, presumably because steps 2 and 3 throw
NullPointerExceptions, which results from the missing init parameter.)
This confuses me:
* Why is myServlet1.init() called twice?
* Why isn't myServlet2.init() called before the second call to
myServlet1.init()?
* Why is the init parameter "dataDirectory" only available in the first
call to myServlet1.init()?
Thanks for any insight,
Garret
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat multiple init(), no init param
Posted by Garret Wilson <ga...@globalmentor.com>.
Garret Wilson wrote:
> It's as if two instances of Tomcat are being run in two separate JVMS:
> one using the server.xml configuration, and another attempting to
> deploy the .war files using some default configuration. The first set
> of initialized servlets continue to run and accept connections. What's
> wrong here?
I've found the problem. If you remember, my server.xml had this:
<Host name="www.example.com" appBase="/var/web/apps"
unpackWARs="false" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>example.com</Alias>
<Context path="" docBase="www.example.com.war">
<Parameter name="dataDirectory"
value="/var/web/data/www.example.com/"/>
</Context>
</Host>
Tomcat would deploy my .war file as specified, using the given init
parameter. But then, because my .war file was in the appBase directory
(here "/var/web/apps"), Tomcat would going through and deploying the
.war file a second time even though autoDeploy was set to "false". One
way to fix this it to change the appBase so that my .war file wasn't in
the application base directory:
<Host name="www.example.com" appBase="/var/web"
unpackWARs="false" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>example.com</Alias>
<Context path="" docBase="apps/www.example.com.war">
<Parameter name="dataDirectory"
value="/var/web/data/www.example.com/"/>
</Context>
</Host>
But the easier way is to add deployOnStartup="false" to the host
configuration, like this:
<Host name="www.example.com" appBase="/var/web/apps"
unpackWARs="false" autoDeploy="false" deployOnStartup="false"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>example.com</Alias>
<Context path="" docBase="www.example.com.war">
<Parameter name="dataDirectory"
value="/var/web/data/www.example.com/"/>
</Context>
</Host>
Sure enough, there is a small note on this at
http://tomcat.apache.org/tomcat-5.5-doc/config/host.html#Automatic%20Application%20Deployment
: "When using automatic deployment, the docBase defined by an XML
Context file should be outside of the appBase directory. If this is not
the case difficulties may be experienced deploying the web application
or the application may be deployed twice."
Well, that's why I turned off autoDeploy---but it seems I need to turn
off deployOnStartup as well.
Garret
>
> Thanks in advance,
>
> Garret
>
> Garret Wilson wrote:
>> Tomcat 5.5.16 seems to call a servlet's init() method several times,
>> and the specific init parameter is missing in all but the first.
>>
>> I have a simple server.xml that includes:
>>
>> <Host name="www.example.com" appBase="/var/web/apps"
>> unpackWARs="false" autoDeploy="false"
>> xmlValidation="false" xmlNamespaceAware="false">
>>
>> <Alias>example.com</Alias>
>>
>> <Context path="" docBase="www.example.com.war">
>> <Parameter name="dataDirectory"
>> value="/var/web/data/www.example.com/"/>
>> </Context>
>>
>> </Host>
>>
>> In www.example.com.war I have a web.xml file that includes two
>> instances of MyServlet, with servlet names of myServlet1 and
>> myServlet2, mapped to "/*" and "/example/*", respectively.
>>
>> Tomcat does the following, which I find odd:
>>
>> 1. myServlet1.init() is called. The init parameter "dataDirectory" is
>> correctly set to "/var/web/data/www.example.com/".
>>
>> 2. catalina.out indicates "Jun 25, 2006 2:07:26 PM
>> org.apache.catalina.startup.HostConfig deployWAR".
>>
>> 3. myServlet.init is called(). The init parameter "dataDirectory"
>> returns null.
>>
>> 4. myServlet2.init is called(). The init parameter "dataDirectory"
>> returns null.
>>
>> (Then steps 3 and 4 are repeated, presumably because steps 2 and 3
>> throw NullPointerExceptions, which results from the missing init
>> parameter.)
>>
>> This confuses me:
>>
>> * Why is myServlet1.init() called twice?
>> * Why isn't myServlet2.init() called before the second call to
>> myServlet1.init()?
>> * Why is the init parameter "dataDirectory" only available in the
>> first call to myServlet1.init()?
>>
>> Thanks for any insight,
>>
>> Garret
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat multiple init(), no init param
Posted by Garret Wilson <ga...@globalmentor.com>.
Everyone,
I found the answer to my second question, "Why isn't myServlet2.init()
called before the second call to myServlet1.init()?" It turns out it was
being called, but my debug trace statements had been redirected because
my init() method had successfully redirected debug output.
So the sequence now looks like this:
1. myServlet1.init() is called. The init parameter "dataDirectory" is
correctly set to "/var/web/data/www.example.com/", and debug output is
successfully redirected.
2. myServlet2.init() is called. The init parameter "dataDirectory" is
correctly set to "/var/web/data/www.example.com/", and debug output is
still successfully redirected.
3. catalina.out indicates "Jun 25, 2006 4:23:40 PM
org.apache.catalina.startup.HostConfig deployWAR" followed by "INFO:
Deploying web application archive www.example.com.war
4. myServlet1.init() is called. The init parameter "dataDirectory"
returns null, the static variable is no longer set, and output is no
longer redirected.
5. myServlet2.init() is called. The init parameter "dataDirectory"
returns null, the static variable is no longer set, and output is no
longer redirected..
Note that in step 1 I set a static variable in my servlet that is
verified in step 2. But by step 4 the static variable is gone!
Note that if I change unpackWARs="true", these errors still occur, even
if I restart Tomcat after the WARs have been unpacked! (The only
difference is that, in step 4, I have access to the real path of the
WEB-INF directory.)
It's as if two instances of Tomcat are being run in two separate JVMS:
one using the server.xml configuration, and another attempting to deploy
the .war files using some default configuration. The first set of
initialized servlets continue to run and accept connections. What's
wrong here?
Thanks in advance,
Garret
Garret Wilson wrote:
> Tomcat 5.5.16 seems to call a servlet's init() method several times,
> and the specific init parameter is missing in all but the first.
>
> I have a simple server.xml that includes:
>
> <Host name="www.example.com" appBase="/var/web/apps"
> unpackWARs="false" autoDeploy="false"
> xmlValidation="false" xmlNamespaceAware="false">
>
> <Alias>example.com</Alias>
>
> <Context path="" docBase="www.example.com.war">
> <Parameter name="dataDirectory"
> value="/var/web/data/www.example.com/"/>
> </Context>
>
> </Host>
>
> In www.example.com.war I have a web.xml file that includes two
> instances of MyServlet, with servlet names of myServlet1 and
> myServlet2, mapped to "/*" and "/example/*", respectively.
>
> Tomcat does the following, which I find odd:
>
> 1. myServlet1.init() is called. The init parameter "dataDirectory" is
> correctly set to "/var/web/data/www.example.com/".
>
> 2. catalina.out indicates "Jun 25, 2006 2:07:26 PM
> org.apache.catalina.startup.HostConfig deployWAR".
>
> 3. myServlet.init is called(). The init parameter "dataDirectory"
> returns null.
>
> 4. myServlet2.init is called(). The init parameter "dataDirectory"
> returns null.
>
> (Then steps 3 and 4 are repeated, presumably because steps 2 and 3
> throw NullPointerExceptions, which results from the missing init
> parameter.)
>
> This confuses me:
>
> * Why is myServlet1.init() called twice?
> * Why isn't myServlet2.init() called before the second call to
> myServlet1.init()?
> * Why is the init parameter "dataDirectory" only available in the
> first call to myServlet1.init()?
>
> Thanks for any insight,
>
> Garret
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org