You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Si'mon <si...@purpleblade.net> on 2007/04/28 00:07:30 UTC

How to exit tomcat if web app throws exception?

For development boxes, I want tomcat to exit if an exception is thrown in a
specific .war (web application).  After exiting it will print the exception
and not go any further.

Is there any way to do this (configuration) or any way to incorporate this
into the web application?

thanks


Si'mon
-- 
View this message in context: http://www.nabble.com/How-to-exit-tomcat-if-web-app-throws-exception--tf3660087.html#a10227191
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
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: How to exit tomcat if web app throws exception?

Posted by Bill Barker <wb...@wilshire.com>.
"Rashmi Rubdi" <ra...@gmail.com> wrote in message 
news:3ef28230704271642k3d6e0bbbpb3df12bcbaccec4a@mail.gmail.com...
> On 4/27/07, Si'mon <si...@purpleblade.net> wrote:
>>
>> For development boxes, I want tomcat to exit if an exception is thrown in 
>> a
>> specific .war (web application).  After exiting it will print the 
>> exception
>> and not go any further.
>>
>> Is there any way to do this (configuration) or any way to incorporate 
>> this
>> into the web application?
>

If you are running with a SecurityManager, then you are SoL.  Otherwise, if 
you don't care about a clean shutdown, then a simple
    System.exit(0);
will do the trick.

> I haven't written code to shutdown Tomcat from a program.
>
> One thing that comes to mind is calling shutdown.bat / shutdown.sh
> from the location of the catch for that exception.
>
> Also, there may be other better ways to accomplish this.
>

If you are not running from 'jsvc' or embedded, and using the default 
configuration, then (copied from Catalina.java):
            Socket socket = new Socket("127.0.0.1", 8005);
            OutputStream stream = socket.getOutputStream();
            String shutdown = "SHUTDOWN";
            for (int i = 0; i < shutdown.length(); i++)
                stream.write(shutdown.charAt(i));
            stream.flush();
            stream.close();
            socket.close();



> I think it's a bad idea to shutdown tomcat every time an exception
> occurs. Some of the exceptions do get logged in the logs folder under
> Tomcat's folder whether Tomcat is shutdown or not, additionally you
> can use tools like Log4J to log your own exceptions.
>
>>
>> thanks
>>
>>
>> Si'mon
>> --
>
> -Regards
> Rashmi
>
> ---------------------------------------------------------------------
> 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: How to exit tomcat if web app throws exception?

Posted by Rashmi Rubdi <ra...@gmail.com>.
On 4/27/07, Si'mon <si...@purpleblade.net> wrote:
>
> For development boxes, I want tomcat to exit if an exception is thrown in a
> specific .war (web application).  After exiting it will print the exception
> and not go any further.
>
> Is there any way to do this (configuration) or any way to incorporate this
> into the web application?

I haven't written code to shutdown Tomcat from a program.

One thing that comes to mind is calling shutdown.bat / shutdown.sh
from the location of the catch for that exception.

Also, there may be other better ways to accomplish this.

I think it's a bad idea to shutdown tomcat every time an exception
occurs. Some of the exceptions do get logged in the logs folder under
Tomcat's folder whether Tomcat is shutdown or not, additionally you
can use tools like Log4J to log your own exceptions.

>
> thanks
>
>
> Si'mon
> --

-Regards
Rashmi

---------------------------------------------------------------------
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