| .. | .. |
|---|
| 17 | 17 | |
|---|
| 18 | 18 | @Provider |
|---|
| 19 | 19 | public class DefaultExceptionHandler implements ExceptionMapper<Exception> { |
|---|
| 20 | | - private static final Logger log = LogManager.getLogger(DefaultExceptionHandler.class); |
|---|
| 20 | + private static final Logger LOG = LogManager.getLogger(DefaultExceptionHandler.class); |
|---|
| 21 | 21 | |
|---|
| 22 | 22 | public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR"; |
|---|
| 23 | 23 | |
|---|
| 24 | 24 | public DefaultExceptionHandler() { |
|---|
| 25 | | - log.info("Creating DefaultExceptionHandler "); |
|---|
| 25 | + LOG.info("Creating DefaultExceptionHandler "); |
|---|
| 26 | 26 | } |
|---|
| 27 | 27 | |
|---|
| 28 | 28 | @Context |
|---|
| .. | .. |
|---|
| 32 | 32 | |
|---|
| 33 | 33 | @Override |
|---|
| 34 | 34 | public Response toResponse(Exception e) { |
|---|
| 35 | | - // log.info("Creating DefaultExceptionHandler "); |
|---|
| 36 | | - // e.printStackTrace(); |
|---|
| 37 | 35 | if (e instanceof ForbiddenException) { |
|---|
| 38 | | - log.warn("Unauthorized access to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal()); |
|---|
| 36 | + LOG.warn("Unauthorized access to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal()); |
|---|
| 39 | 37 | return Response.status(Status.UNAUTHORIZED).header(ERROR_MESSAGE_HEADER, "Unathorized access to the application").type(MediaType.APPLICATION_JSON).build(); |
|---|
| 40 | 38 | } |
|---|
| 41 | 39 | |
|---|
| 42 | 40 | if (e instanceof SeCurisServiceException) { |
|---|
| 43 | | - log.warn("SeCurisServiceException accessing to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal()); |
|---|
| 41 | + LOG.warn("SeCurisServiceException accessing to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal()); |
|---|
| 44 | 42 | return Response.status(Status.fromStatusCode(((SeCurisServiceException) e).getStatus())).header(ERROR_MESSAGE_HEADER, e.getMessage()).type(MediaType.APPLICATION_JSON).build(); |
|---|
| 45 | 43 | } |
|---|
| 46 | 44 | |
|---|
| 47 | | - log.error("Unexpected error accesing to '{}' by user: {}", request.getPathInfo(), bsc.getUserPrincipal()); |
|---|
| 48 | | - log.error("Request sent from {}, with User-Agent: {}", request.getRemoteHost(), request.getHeader("User-Agent")); |
|---|
| 49 | | - log.error("Request url: " + request.getRequestURL(), e); |
|---|
| 45 | + LOG.error("Unexpected error accesing to '{}' by user: {}", request.getPathInfo(), bsc.getUserPrincipal()); |
|---|
| 46 | + LOG.error("Request sent from {}, with User-Agent: {}", request.getRemoteHost(), request.getHeader("User-Agent")); |
|---|
| 47 | + LOG.error("Request url: " + request.getRequestURL(), e); |
|---|
| 50 | 48 | return Response.serverError().header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString()).type(MediaType.APPLICATION_JSON).build(); |
|---|
| 51 | 49 | } |
|---|
| 52 | 50 | } |
|---|