So this seems most easily solved without binding myself to Jetty too much by <error-page> in web.xml
<servlet>
<servlet-name>ErrorHandler</servlet-name>
<servlet-class>device.webapp.ErrorHandler</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ErrorHandler</servlet-name>
<url-pattern>/ErrorHandler</url-pattern>
</servlet-mapping>
<error-page>
<exception-type>java.lang.Throwable</exception-type >
<location>/ErrorHandler</location>
</error-page>
Implementing ErrorHandler like
package device.webapp;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.httpclient.*;
import org.slf4j.*;
/**
* The ErrorHandler is intended to catch all unhandled Throwables (as configured in the web.xml)
* before they get out to Jetty's verbose ErrorHandler.
*
*/
public class ErrorHandler extends HttpServlet {
private static final long serialVersionUID = 1L;
private Logger log = LoggerFactory.getLogger( ErrorHandler.class );
@Override
protected void service( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
// Analyze the servlet exception
Throwable throwable = (Throwable) req.getAttribute( "javax.servlet.error.exception" );
String message = String.format(
"Responding 500 - Server Error on URI %s",
req.getAttribute( "javax.servlet.error.request_uri" ) );
if ( throwable != null ) {
log.error( message, throwable );
} else {
log.warn( "Throwable should not be null!" );
log.error( message );
}
/*
* Interestingly enough, you can't resp.sendError( 500, "Server Error" ) without triggering
* Jetty's DefaultErrorHandler which is the core of the problem we are trying to solve!
*/
resp.setStatus( HttpStatus.SC_INTERNAL_SERVER_ERROR );
}
}
It isn't pretty, but it works.