Ticket #484 (closed Enhancement: fixed)
Web layer exception handling
Reported by: | jri | Owned by: | jri |
---|---|---|---|
Priority: | Major | Milestone: | Release 4.2 |
Component: | DeepaMehta Standard Distribution | Version: | 4.1 |
Keywords: | Cc: | dgf, Malte | |
Complexity: | 3 | Area: | Application Framework / API |
Module: | deepamehta-webservice |
Description
A plugin should be able to throw a WebApplicationException? to produce a specific HTTP error response. Currently this is not possible in every situation because the Webservice module catches all exceptions and wraps them in a generic WebApplicationException? (which always produce a 500 response).
So far this wrapping is there just to workaround a logging issue: exceptions which are not handled by Jersey are passed on to Jetty (the servlet container). Then both, Jersey and Jetty log the exception yielding to the exception logged twice. And because Jersey and Jetty execute in different threads the respective stack traces intersperse each other and renders the exception log nearly unreadable. The wrapping workaround fights that situation by avoiding exceptions to be passed to Jetty but at the same time it hinders plugins to produce specific HTTP error responses.
Subject of this ticket:
- Stop the Webservice module from wrapping all exceptions in generic WebApplicationExceptions?.
- Provide a JAX-RS exception mapper that re-throws WebApplicationExceptions? directly and wraps all other exceptions. Thus no exception reaches Jetty anymore.
This solves the problem of interspersed logging. At the same time this allows plugins to produce specific HTTP error responses.
Change History
comment:2 Changed 11 years ago by jri
Revise web layer exception handling (#484).
The proliferation of WebApplicationExceptions? is limited: resource methods and event handlers only throw a WebApplicationException? when a specific response status needs to be sent.
The problem of interspersed illegible stack traces is solved by introducing a JAX-RS exception mapper.
PLUGIN DEVELOPER NOTE:
To send a specific response status throw a WebApplicationException? from your resource methods or event handlers. The WebApplicationException?'s status code will be send back to the client. In the other cases throwing a RuntimeException? is sufficient. Wrapping a RuntimeException? in a WebApplicationException? is no longer required.
See #484.
Changeset: ae57394830c64ce8bf218d2eb10bedc961469122
comment:3 Changed 11 years ago by jri
- Status changed from accepted to closed
- Resolution set to fixed
Access Control: fix exception log (#474, #484).
Exceptions thrown by the Access Control's request filter are not logged twice on the console.
If file logging is activated all excpetions are logged properly.
Generally, since the Servlet Filter is dropped (see #448) exception handling is more straight forward.
Exceptions thrown by resource methods and event listeners are logged more clearly.
Changeset: 2b587af7e68b50d8ca45697fb3a6a129d92585fb
comment:4 Changed 11 years ago by jri
- Status changed from closed to reopened
- Resolution fixed deleted
The JAX-RS Exception Mapper should handle Errors as well (not just RuntimeExceptions?).
Currently an illegible interspersed exception log still appears when e.g. a NoClassDefFoundError? is thrown.
comment:5 Changed 11 years ago by Jörg Richter
- Status changed from reopened to closed
- Resolution set to fixed
Webservice: errors are mapped as well (#484).
The JAX-RS Exception Mapper maps errors as well (not just RuntimeExceptions?).
Thus the exception log is still readable when e.g. a NoClassDefFoundError? occurred.
The provider class is renamed:
RuntimeExceptionMapper -> CatchAllExceptionMapper
Close #484.
comment:6 Changed 11 years ago by Jörg Richter
Webservice: errors are mapped as well (#484).
The JAX-RS Exception Mapper maps errors as well (not just RuntimeExceptions?).
Thus the exception log is still readable when e.g. a NoClassDefFoundError? occurred.
The provider class is renamed:
RuntimeExceptionMapper -> CatchAllExceptionMapper
Close #484.