@Override protected void initialize() throws ServletException { // ... define your resource providers here ... // Now register the interceptor ExceptionHandlingInterceptor interceptor = new ExceptionHandlingInterceptor(); registerInterceptor(interceptor); // Return the stack trace to the client for the following exception types interceptor.setReturnStackTracesForExceptionTypes(InternalErrorException.class, NullPointerException.class); }
/** * This method convert an exception to a JaxRsResponseException * @param theServer the provider * @param theException the exception to convert * @return JaxRsResponseException */ public JaxRsResponseException convertException(final AbstractJaxRsProvider theServer, final Throwable theException) { if (theServer.withStackTrace()) { exceptionHandler.setReturnStackTracesForExceptionTypes(Throwable.class); } final JaxRsRequest requestDetails = theServer.getRequest(null, null).build(); final BaseServerResponseException convertedException = preprocessException(theException, requestDetails); return new JaxRsResponseException(convertedException); }