| .. | .. |
|---|
| 67 | 67 | HttpServletRequest request; |
|---|
| 68 | 68 | @Context |
|---|
| 69 | 69 | SecurityContext bsc; |
|---|
| 70 | | - @Context |
|---|
| 71 | | - EntityManager em; |
|---|
| 72 | 70 | |
|---|
| 73 | 71 | /** |
|---|
| 74 | 72 | * toResponse |
|---|
| .. | .. |
|---|
| 81 | 79 | releaseEntityManager(); |
|---|
| 82 | 80 | if (e instanceof ForbiddenException) { |
|---|
| 83 | 81 | LOG.warn("ForbiddenException: {}", e.toString()); |
|---|
| 84 | | - return Response.status(Status.UNAUTHORIZED).header(ERROR_CODE_MESSAGE_HEADER, ErrorCodes.INVALID_CREDENTIALS) |
|---|
| 85 | | - .header(ERROR_MESSAGE_HEADER, "Unathorized access to the application").type(MediaType.APPLICATION_JSON).build(); |
|---|
| 82 | + return Response.status(Status.UNAUTHORIZED) |
|---|
| 83 | + .header(ERROR_CODE_MESSAGE_HEADER, ErrorCodes.INVALID_CREDENTIALS) |
|---|
| 84 | + .header(ERROR_MESSAGE_HEADER, "Unathorized access to the application") |
|---|
| 85 | + .type(MediaType.APPLICATION_JSON) |
|---|
| 86 | + .build(); |
|---|
| 86 | 87 | } |
|---|
| 87 | 88 | |
|---|
| 88 | 89 | if (e instanceof SeCurisServiceException) { |
|---|
| 89 | 90 | LOG.warn("SeCurisServiceException: {}", e.toString()); |
|---|
| 90 | | - return Response.status(DEFAULT_APP_ERROR_STATUS_CODE).header(ERROR_CODE_MESSAGE_HEADER, ((SeCurisServiceException) e).getStatus()) |
|---|
| 91 | | - .header(ERROR_MESSAGE_HEADER, e.getMessage()).type(MediaType.APPLICATION_JSON).build(); |
|---|
| 91 | + return Response.status(DEFAULT_APP_ERROR_STATUS_CODE) |
|---|
| 92 | + .header(ERROR_CODE_MESSAGE_HEADER, ((SeCurisServiceException) e).getStatus()) |
|---|
| 93 | + .header(ERROR_MESSAGE_HEADER, e.getMessage()) |
|---|
| 94 | + .type(MediaType.APPLICATION_JSON) |
|---|
| 95 | + .build(); |
|---|
| 92 | 96 | } |
|---|
| 93 | 97 | |
|---|
| 98 | + String path = request != null ? request.getPathInfo() : null; |
|---|
| 99 | + Object user = (bsc != null && bsc.getUserPrincipal() != null) ? bsc.getUserPrincipal() : null; |
|---|
| 100 | + String host = request != null ? request.getRemoteHost() : null; |
|---|
| 101 | + String ua = request != null ? request.getHeader("User-Agent") : null; |
|---|
| 102 | + String url = request != null ? String.valueOf(request.getRequestURL()) : null; |
|---|
| 103 | + |
|---|
| 104 | + LOG.error("Unexpected error accessing to '{}' by user: {}", path, user); |
|---|
| 105 | + LOG.error("Request sent from {}, with User-Agent: {}", host, ua); |
|---|
| 106 | + LOG.error("Request url: {}", url, e); |
|---|
| 107 | + |
|---|
| 108 | + /** |
|---|
| 94 | 109 | LOG.error("Unexpected error accesing to '{}' by user: {}", request.getPathInfo(), bsc.getUserPrincipal()); |
|---|
| 95 | 110 | LOG.error("Request sent from {}, with User-Agent: {}", request.getRemoteHost(), request.getHeader("User-Agent")); |
|---|
| 96 | 111 | LOG.error("Request url: " + request.getRequestURL(), e); |
|---|
| 97 | | - return Response.serverError().header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString()).type(MediaType.APPLICATION_JSON).build(); |
|---|
| 112 | + */ |
|---|
| 113 | + |
|---|
| 114 | + return Response.serverError() |
|---|
| 115 | + .header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString()) |
|---|
| 116 | + .type(MediaType.APPLICATION_JSON) |
|---|
| 117 | + .build(); |
|---|
| 98 | 118 | } |
|---|
| 99 | 119 | |
|---|
| 100 | 120 | /** |
|---|
| .. | .. |
|---|
| 103 | 123 | * Best-effort cleanup: rollback active transaction (if joined) and close the {@link EntityManager}. |
|---|
| 104 | 124 | */ |
|---|
| 105 | 125 | private void releaseEntityManager() { |
|---|
| 126 | + |
|---|
| 127 | + /** |
|---|
| 106 | 128 | try { |
|---|
| 107 | 129 | if (em != null && em.isOpen()) { |
|---|
| 108 | 130 | LOG.debug("CLOSING EM: {}, trans: {}", em, em.isJoinedToTransaction()); |
|---|
| .. | .. |
|---|
| 116 | 138 | ex.printStackTrace(); |
|---|
| 117 | 139 | LOG.error("Error closing EM: {}, {}", em, ex); |
|---|
| 118 | 140 | } |
|---|
| 141 | + */ |
|---|
| 119 | 142 | } |
|---|
| 120 | 143 | } |
|---|