private void notifyExceptionToCallbacks( HttpServletRequest request, HttpServletResponse response, Exception ex) { List<DispatcherCallback> callbacks = GeoServerExtensions.extensions(DispatcherCallback.class); for (DispatcherCallback callback : callbacks) { callback.exception(request, response, ex); } }
@Override public void afterCompletion( HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { List<DispatcherCallback> callbacks = getCallbacks(); if (ex != null) { for (DispatcherCallback callback : callbacks) { callback.exception(request, response, ex); } } // ensure that finish is always called for all requests for (DispatcherCallback callback : callbacks) { try { callback.finished(request, response); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Callback threw exception on finish", e); } } } }
@Override public void handle(Request request, Response response) { try { super.handle(request, response); } catch(Exception e) { //execute the exception callback for (DispatcherCallback callback : callbacks) { callback.exception(request, response, e); } if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RuntimeException(e); } finally { //execute the finished callback for (DispatcherCallback callback : callbacks) { callback.finished(request, response); } } }; };
@Test public void testCallbackException() throws Exception { callback.init(anyObject(), anyObject()); expectLastCall(); callback.dispatched(anyObject(), anyObject(), anyObject()); expectLastCall(); callback.exception(anyObject(), anyObject(), anyObject()); expectLastCall(); callback.finished(anyObject(), anyObject()); expectLastCall(); replay(callback); getAsServletResponse(RestBaseController.ROOT_PATH + "/exception?code=400&message=error"); verify(callback); } }