This idea is based on the implementation of WebAppContext , where you can use WebAppContext.getUnavailableException () to determine if the context has been successfully initialized.
Just replace the standard server and context implementation with your own:
public static class MyContext extends Context { private Exception _exception; @Override protected void doStart() throws Exception { try { super.doStart(); } catch (final Exception e) { _exception = e; } } @Override protected void doStop() throws Exception { try { super.doStop(); } finally { _exception = null; } } public Exception getException() { return _exception; } } public static class MyServer extends Server implements InitializingBean { public void afterPropertiesSet() throws Exception { start(); for (final Handler h : getHandlers()) { if (h instanceof MyContext) { final MyContext c = (MyContext) h; if (c.getException() != null) { throw new RuntimeException("failed to init context " + c.getDisplayName(), c.getException()); } } } } }
In beans.xml, just replace org.mortbay.jetty.Server (and remove init-method="start" ) and org.mortbay.jetty.servlet.Context with your own implementations.
This code is for Jetty 6, though (as in the example you are attached to), like what I have. However, I have not tested it, but it is almost the same as we successfully use in combination with WebAppContext. To extend this to RequestLogHandler, you can either do the same for any handler you use, or create a decorator to port any handler. You can look at org.mortbay.jetty.handler.HandlerWrapper for this purpose.
source share