@Provider public class RestServiceExceptionFacade extends Object implements javax.ws.rs.ext.ExceptionMapper<Throwable>
ExceptionMapper that acts as generic exception facade for REST services. It
maps exceptions to an according HTTP status code and JSON result as
defined by devonfw REST error
specification.| Modifier and Type | Field and Description |
|---|---|
private boolean |
exposeInternalErrorDetails |
private static org.slf4j.Logger |
LOG
Logger instance.
|
private com.fasterxml.jackson.databind.ObjectMapper |
mapper |
private Class<? extends Throwable> |
rollbackException |
private List<Class<? extends Throwable>> |
securityExceptions |
private Class<? extends Throwable> |
transactionSystemException |
| Constructor and Description |
|---|
RestServiceExceptionFacade()
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
createJsonErrorResponseMessage(String message,
String code,
UUID uuid,
Map<String,List<String>> errorsMap)
Create a response message as a JSON-String from the given parts.
|
protected javax.ws.rs.core.Response |
createResponse(NlsRuntimeException error)
Create the
Response for the given NlsRuntimeException. |
protected javax.ws.rs.core.Response |
createResponse(javax.ws.rs.core.Response.Status status,
NlsRuntimeException error,
Map<String,List<String>> errorsMap)
Create a response message as a JSON-String from the given parts.
|
protected javax.ws.rs.core.Response |
createResponse(javax.ws.rs.core.Response.Status status,
NlsRuntimeException error,
String message,
Map<String,List<String>> errorsMap)
Create a response message as a JSON-String from the given parts.
|
protected javax.ws.rs.core.Response |
createResponse(javax.ws.rs.core.Response.Status status,
NlsRuntimeException error,
String message,
String code,
Map<String,List<String>> errorsMap)
Create a response message as a JSON-String from the given parts.
|
protected javax.ws.rs.core.Response |
createResponse(javax.ws.rs.core.Response.Status status,
String message,
String code,
UUID uuid,
Map<String,List<String>> errorsMap)
Create a response message as a JSON-String from the given parts.
|
protected javax.ws.rs.core.Response |
createResponse(Throwable exception,
ValidationErrorUserException error,
Map<String,List<String>> errorsMap)
Creates the
Response for the given validation exception. |
protected javax.ws.rs.core.Response |
createResponse(javax.ws.rs.WebApplicationException exception)
Add a response message to an existing response.
|
protected String |
getExposedErrorDetails(Throwable error) |
com.fasterxml.jackson.databind.ObjectMapper |
getMapper() |
private Throwable |
getRollbackCause(Throwable exception) |
protected javax.ws.rs.core.Response |
handleGenericError(Throwable exception,
Throwable catched)
Exception handling for generic exception (fallback).
|
protected javax.ws.rs.core.Response |
handleSecurityError(Throwable exception,
Throwable catched)
Exception handling for security exception.
|
protected javax.ws.rs.core.Response |
handleValidationException(Throwable exception,
Throwable catched)
Exception handling for validation exception.
|
boolean |
isExposeInternalErrorDetails() |
private Class<? extends Throwable> |
loadException(String className) |
protected void |
registerToplevelSecurityException(Class<? extends Throwable> securityException)
|
protected void |
registerToplevelSecurityExceptions()
This method registers the
top-level security exceptions. |
protected void |
registerToplevelSecurityExceptions(String className) |
void |
setExposeInternalErrorDetails(boolean exposeInternalErrorDetails) |
void |
setMapper(com.fasterxml.jackson.databind.ObjectMapper mapper) |
javax.ws.rs.core.Response |
toResponse(Throwable exception) |
protected javax.ws.rs.core.Response |
toResponse(Throwable exception,
Throwable catched) |
private NlsRuntimeException |
unwrapNlsUserError(Throwable exception)
Unwraps potential NLS user error from a wrapper exception such as
JsonMappingException or
PersistenceException. |
private static final org.slf4j.Logger LOG
private com.fasterxml.jackson.databind.ObjectMapper mapper
private boolean exposeInternalErrorDetails
protected void registerToplevelSecurityException(Class<? extends Throwable> securityException)
Class as a top-level security exception. Instances of this class and all its
subclasses will be handled as security errors. Therefore an according HTTP error code is used and no further
details about the exception is send to the client to prevent
sensitive data exposure.securityException - is the Class reflecting the security error.protected void registerToplevelSecurityExceptions()
top-level security exceptions. You may
override it to add additional or other classes.protected void registerToplevelSecurityExceptions(String className)
className - the className to be registeredpublic javax.ws.rs.core.Response toResponse(Throwable exception)
toResponse in interface javax.ws.rs.ext.ExceptionMapper<Throwable>private NlsRuntimeException unwrapNlsUserError(Throwable exception)
JsonMappingException or
PersistenceException.exception - the exception to unwrap.NlsRuntimeException exception or null if no
use error.protected javax.ws.rs.core.Response toResponse(Throwable exception, Throwable catched)
exception - the exception to handlecatched - the original exception that was cached. Either same as error or a (child-)
cause of it.toResponse(Throwable)protected javax.ws.rs.core.Response createResponse(Throwable exception, ValidationErrorUserException error, Map<String,List<String>> errorsMap)
Response for the given validation exception.exception - is the original validation exception.error - is the wrapped exception or the same as exception.errorsMap - is a map with all validation errorsResponse.protected javax.ws.rs.core.Response handleGenericError(Throwable exception, Throwable catched)
exception - the exception to handlecatched - the original exception that was cached. Either same as error or a (child-)
cause of it.protected javax.ws.rs.core.Response handleSecurityError(Throwable exception, Throwable catched)
exception - the exception to handlecatched - the original exception that was cached. Either same as error or a (child-)
cause of it.protected javax.ws.rs.core.Response handleValidationException(Throwable exception, Throwable catched)
exception - the exception to handlecatched - the original exception that was cached. Either same as error or a (child-)
cause of it.protected String getExposedErrorDetails(Throwable error)
error - is the Throwable to extract message details from.protected javax.ws.rs.core.Response createResponse(NlsRuntimeException error)
Response for the given NlsRuntimeException.error - the generic NlsRuntimeException.Response.protected javax.ws.rs.core.Response createResponse(javax.ws.rs.core.Response.Status status,
NlsRuntimeException error,
Map<String,List<String>> errorsMap)
status - is the HTTP Response.Status.error - is the catched or wrapped NlsRuntimeException.errorsMap - is a map with all validation errorsResponse.protected javax.ws.rs.core.Response createResponse(javax.ws.rs.core.Response.Status status,
NlsRuntimeException error,
String message,
Map<String,List<String>> errorsMap)
status - is the HTTP Response.Status.error - is the catched or wrapped NlsRuntimeException.message - is the JSON message attribute.errorsMap - is a map with all validation errorsResponse.protected javax.ws.rs.core.Response createResponse(javax.ws.rs.core.Response.Status status,
NlsRuntimeException error,
String message,
String code,
Map<String,List<String>> errorsMap)
status - is the HTTP Response.Status.error - is the catched or wrapped NlsRuntimeException.message - is the JSON message attribute.code - is the error code.errorsMap - is a map with all validation errorsResponse.protected javax.ws.rs.core.Response createResponse(javax.ws.rs.core.Response.Status status,
String message,
String code,
UUID uuid,
Map<String,List<String>> errorsMap)
status - is the HTTP Response.Status.message - is the JSON message attribute.code - is the error code.uuid - the UUID of the response message.errorsMap - is a map with all validation errorsResponse.protected String createJsonErrorResponseMessage(String message, String code, UUID uuid, Map<String,List<String>> errorsMap)
message - the message of the response messagecode - the code of the response messageuuid - the uuid of the response messageerrorsMap - is a map with all validation errorsprotected javax.ws.rs.core.Response createResponse(javax.ws.rs.WebApplicationException exception)
exception - the WebApplicationException.public com.fasterxml.jackson.databind.ObjectMapper getMapper()
ObjectMapper for JSON mapping.@Inject public void setMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)
mapper - the mapper to setpublic void setExposeInternalErrorDetails(boolean exposeInternalErrorDetails)
exposeInternalErrorDetails - - true if internal exception details shall be exposed to clients (useful
for debugging and testing), false if such details are hidden to prevent
Sensitive Data Exposure
(default, has to be used in production environment).public boolean isExposeInternalErrorDetails()
setExposeInternalErrorDetails(boolean).Copyright © 2014–2019 devon4j-Team. All rights reserved.