I have a Jersey (2.14) application, which works all right. I have some services running there. Now I'd like to configure the ServletContainer so, that any not catched Exceptions should be intercepted and logged or emailed somewhere.
I have already an implementation of ApplicationEventListener and a test endpoint for generating an exception.
This is the method, which should generate an exception (this is working :-) :
@GET
@Path(TEST_EXCEPTION)
public String testException(@Context final ServletContext context) {
    String s = null;
    int size = 0;
    if (System.nanoTime() % 10 != 0) {
        s = null;
    } else {
        s = "No exception will occur";
    }
    size = s.length();
    return Integer.toString(size) + ":" + s;
}
And this is the implementation if my ApplicationEventListener:
public class MyApplicationEventListener implements ApplicationEventListener {
    private transient volatile int count = 0;
    private int exceptions = 0;
    @Override
    public void onEvent(final ApplicationEvent applicationEvent) {
        ApplicationEvent.Type type = applicationEvent.getType();
    }
    @Override
    public RequestEventListener onRequest(final RequestEvent requestEvent) {
        RequestEvent.Type type = requestEvent.getType();
        if (type == RequestEvent.Type.ON_EXCEPTION) {
            exceptions++;
        }
        count++;
        return null;
    }
}
And this the configuration in my web.xml:
<servlet>
    <servlet-name>jersey-servlet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com....rest</param-value>
    </init-param>
    <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>
            com....filter.MyApplicationEventListener
        </param-value>
    </init-param>
    <init-param>
        <param-name>jersey.config.server.tracing</param-name>
        <param-value>ALL</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
onEvent() and onRequest() are both been called, but when an Exception happens, I don't get a ON_EXCEPTION, but a START.
What am I doing wrong? Or how can I get all exceptions resulting from the methods of my Jersey service?
I'd like to have/make something like Spring's HandlerExceptionResolver.
 
     
     
     
    