Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetty: Detect if Webapp failed to start

Tags:

servlets

jetty

I am launching an embedded Jetty instance containing a single webapp. The webapp launches on start-up. I'd like to know how to detect if the Webapp's contextInitialized throws an exception.

When the webapp throws an exception, Server.start() doesn't and server.isRunning() returns true. Is there a way for me to listen for webapp exceptions from outside the container?

like image 403
Gili Avatar asked Dec 27 '11 14:12

Gili


2 Answers

Answering my own question.

Setting WebAppContext.setThrowUnavailableOnStartupException(true) causes the server to propagate any webapp exceptions to Server.start(). I'm guessing one could also invoke WebAppContext.isFailed() after server start-up to check individual contexts.

like image 134
Gili Avatar answered Nov 18 '22 19:11

Gili


I stumbled across this trying to make this work for a non-embedded solution. In case anyone is in a similar boat, the solution for that case is to create WEB-INF/jetty-env.xml with the following contents:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="throwUnavailableOnStartupException">true</Set>
</Configure>

The server will fail startup on an exception as expected.

like image 5
andrew b Avatar answered Nov 18 '22 18:11

andrew b