Jetty: detect if Webapp failed to start

I am running an embedded Jetty instance containing one webapp. Webapp starts at startup. I would like to know how to determine if the WebappInitialized context throws an exception.

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

+6
source share
2 answers

Answering my own question.

Setting WebAppContext.setThrowUnavailableOnStartupException(true) causes the server to propagate any webapp exceptions to Server.start() . I assume that when starting the server, one could call WebAppContext.isFailed() to check individual contexts.

+5
source

I stumbled upon this while trying to make this work for a non-embedded solution. If someone is in a similar boat, the solution for this 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 not start if an exception occurs.

+4
source

Source: https://habr.com/ru/post/904539/


All Articles