8

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?

Gili
  • 86,244
  • 97
  • 390
  • 689

2 Answers2

7

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.

Gili
  • 86,244
  • 97
  • 390
  • 689
  • In Jetty 9 method `WebAppContext.setThrowUnavailableOnStartupException(true)`, but you can check if webapp is available with `webappContext.isAvailable()` and the possible error on startup with `webappContext.getUnavailableException()`. – reap Dec 19 '13 at 08:43
  • 1
    org.eclipse.jetty.deploy.DeploymentManager requestAppGoal method do not re-throw the exception it just logs the exception stack trace generated by org.eclipse.jetty.webappWebAppContext.java.doStart(). So, how can it propagate to Server.start()? – quintin Dec 06 '17 at 07:52
5

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.

andrew b
  • 205
  • 2
  • 6