Reputation: 5994
I'm using embedded Jetty to launch a standard Java webapp. My launcher is something like this:
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.component.LifeCycle.Listener;
import org.eclipse.jetty.webapp.WebAppContext;
...
Listener listener = ...;
Server server = new Server(8080);
WebAppContext webapp = new WebAppContext();
...
webapp.addLifeCycleListener(listener);
server.setHandler(webapp);
server.start();
...
This all works fine in that I can start my app and browse to it and everything appears to be working.
But now I'm trying to add error reporting to my launcher. I've temporarily set my webapp to throw an exception in the contextInitialized()
method of a ServletContextListener
. The exception is thrown, and I get a log message of
ERROR org.eclipse.jetty.util.log Failed startup of context WebAppContext@...
but my LifeCycleListener does not receieve any failure event. In fact, it receives a started event, and the WebAddContext
passed to the listener returns false for LifeCycle#isFailed()
and true for LifeCycle#isRunning()
.
Browsing to my webapp results in 503 Service Unavailable errors.
This happens in Jetty versions 7.0.1.v20091125 and 7.2.1.v20101111. See Jetty 7 api docs.
Upvotes: 1
Views: 3619
Reputation: 5994
As per my comments to Heri's answer, WebAppContext swallows exceptions. They would otherwise be caught by AbstractLifeCycle and failure events sent out. This gets me most of the way there:
public class ThrowyWebAppContext extends WebAppContext {
@Override
protected void doStart() throws Exception {
super.doStart();
if (getUnavailableException() != null) {
throw (Exception) getUnavailableException();
}
}
}
Upvotes: 2
Reputation: 2124
If I remember correctly failed life cycles of context elements are not propagated to the life cycle of the context itself (like failed contexts are not propagated to the life cycle of the server itself). Check the life cycle of the SecurityHandler
, ServletHandler
and SessionHandler
of the context, too.
Upvotes: 1