Nella nostra base di codice (legacy), stiamo lanciando WebApplicationException in diversi modi. Nel tentativo di fare un ordine nel modo in cui gestiamo le eccezioni, volevo creare un ExceptionMapper per questi WAE (e altri).ExceptionMapper per WebApplicationException generate con l'entità?
Mi sono reso conto, tuttavia, che ExceptionMapper di Jersey mappa solo WAE che non è stato gettato con un'entità.
Ad esempio:
throw new WebApplicationException(Response.status(500).build());
Questa eccezione ricade nel ExceptionMapper.
throw new WebApplicationException(Response.status(500).entity(WsResourceUtils.createWSResourceRestError(500, "bla")).build());
Questa eccezione NON viene rilevata da ExceptionMapper.
Entrambi vengono lanciati dallo stesso punto nel codice.
Questo è il mio ExceptionMapper:
@Provider
public class GeneralExceptionMapper implements ExceptionMapper<Throwable> {
private static final Logger logger = LoggerFactory.getLogger(GeneralExceptionMapper.class);
@Override
public Response toResponse(Throwable e) {
logger.error("Caught a WAE", e);
...
}
E 'possibile creare un ExceptionMapper che cattura WebApplicationExceptions anche se la loro risposta è già integrato con un'entità?
Stiamo usando Jersey 1.17.
Grazie.
2 anni dopo, questo è ancora un problema con Jersey 2. 26 – ChrisO