Class NtsExceptionTranslator
- java.lang.Object
-
- org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
- org.nentangso.core.web.rest.errors.NtsExceptionTranslator
-
- All Implemented Interfaces:
org.springframework.security.web.access.AccessDeniedHandler,org.springframework.security.web.AuthenticationEntryPoint
@ConditionalOnProperty(prefix="nts.web.rest.exception-translator", name="enabled", havingValue="true", matchIfMissing=true) @ControllerAdvice @ConditionalOnMissingBean(name="exceptionTranslator") public class NtsExceptionTranslator extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler implements org.springframework.security.web.AuthenticationEntryPoint, org.springframework.security.web.access.AccessDeniedHandlerController advice to translate the server side exceptions to client-friendly json structures. The error response follows RFC7807 - Problem Details for HTTP APIs (RFC7807).
-
-
Constructor Summary
Constructors Constructor Description NtsExceptionTranslator()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected Map<String,List<String>>buildUnprocessableErrors(Exception ex)voidcommence(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException authException)Collect error details from the provided parameters and format according to RFC 6750, specificallyerror,error_description,error_uri, andscope.protected Map<String,String>createAuthenticationParameters(org.springframework.security.core.AuthenticationException authException)protected StringgenerateAuthenticateHeader(Exception ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)Deprecated.protected org.springframework.http.HttpStatusgetAuthenticationStatus(org.springframework.security.core.AuthenticationException authException)voidhandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.access.AccessDeniedException accessDeniedException)Collect error details from the provided parameters and format according to RFC 6750, specificallyerror,error_description,error_uri, andscope.protected org.springframework.http.ResponseEntity<Object>handleBindException(org.springframework.validation.BindException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)protected org.springframework.http.ResponseEntity<Object>handleConversionNotSupported(org.springframework.beans.ConversionNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)protected org.springframework.http.ResponseEntity<Object>handleExceptionInternal(Exception ex, Object body, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)protected org.springframework.http.ResponseEntity<Object>handleHttpMediaTypeNotSupported(org.springframework.web.HttpMediaTypeNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)protected org.springframework.http.ResponseEntity<Object>handleHttpRequestMethodNotSupported(org.springframework.web.HttpRequestMethodNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)protected org.springframework.http.ResponseEntity<Object>handleInternalServerError(Exception ex, org.springframework.web.context.request.WebRequest request)protected org.springframework.http.ResponseEntity<Object>handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)protected org.springframework.http.ResponseEntity<Object>handleMissingPathVariable(org.springframework.web.bind.MissingPathVariableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)protected org.springframework.http.ResponseEntity<Object>handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)protected org.springframework.http.ResponseEntity<Object>handleMissingServletRequestPart(org.springframework.web.multipart.support.MissingServletRequestPartException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)protected org.springframework.http.ResponseEntity<Object>handleNtsException(Exception ex, org.springframework.web.context.request.WebRequest request)protected org.springframework.http.ResponseEntity<Object>handleServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)-
Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
handleAsyncRequestTimeoutException, handleException, handleHttpMediaTypeNotAcceptable, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleNoHandlerFoundException, handleTypeMismatch
-
-
-
-
Field Detail
-
realmName
@Value("${nts.web.rest.exception-translator.realm-name:API Authentication by nentangso.org}") protected String realmName
-
-
Method Detail
-
handleNtsException
@ExceptionHandler({org.springframework.web.server.ResponseStatusException.class,org.springframework.dao.ConcurrencyFailureException.class,org.nentangso.core.service.errors.NotFoundException.class,org.nentangso.core.web.rest.errors.BadRequestAlertException.class,org.nentangso.core.service.errors.FormValidationException.class}) protected org.springframework.http.ResponseEntity<Object> handleNtsException(Exception ex, org.springframework.web.context.request.WebRequest request) throws Exception- Throws:
Exception
-
generateAuthenticateHeader
@Deprecated(since="1.1.5") protected String generateAuthenticateHeader(Exception ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
Deprecated.
-
handleConversionNotSupported
protected org.springframework.http.ResponseEntity<Object> handleConversionNotSupported(org.springframework.beans.ConversionNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
- Overrides:
handleConversionNotSupportedin classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
handleMissingPathVariable
protected org.springframework.http.ResponseEntity<Object> handleMissingPathVariable(org.springframework.web.bind.MissingPathVariableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
- Overrides:
handleMissingPathVariablein classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
handleHttpRequestMethodNotSupported
protected org.springframework.http.ResponseEntity<Object> handleHttpRequestMethodNotSupported(org.springframework.web.HttpRequestMethodNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
- Overrides:
handleHttpRequestMethodNotSupportedin classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
handleHttpMediaTypeNotSupported
protected org.springframework.http.ResponseEntity<Object> handleHttpMediaTypeNotSupported(org.springframework.web.HttpMediaTypeNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
- Overrides:
handleHttpMediaTypeNotSupportedin classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
handleServletRequestBindingException
protected org.springframework.http.ResponseEntity<Object> handleServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
- Overrides:
handleServletRequestBindingExceptionin classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
handleMethodArgumentNotValid
protected org.springframework.http.ResponseEntity<Object> handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
- Overrides:
handleMethodArgumentNotValidin classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
handleMissingServletRequestPart
protected org.springframework.http.ResponseEntity<Object> handleMissingServletRequestPart(org.springframework.web.multipart.support.MissingServletRequestPartException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
- Overrides:
handleMissingServletRequestPartin classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
handleMissingServletRequestParameter
protected org.springframework.http.ResponseEntity<Object> handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
- Overrides:
handleMissingServletRequestParameterin classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
handleBindException
protected org.springframework.http.ResponseEntity<Object> handleBindException(org.springframework.validation.BindException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
- Overrides:
handleBindExceptionin classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
handleExceptionInternal
protected org.springframework.http.ResponseEntity<Object> handleExceptionInternal(Exception ex, @Nullable Object body, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
- Overrides:
handleExceptionInternalin classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
-
buildUnprocessableErrors
protected Map<String,List<String>> buildUnprocessableErrors(Exception ex)
-
handleInternalServerError
@ExceptionHandler(java.lang.Exception.class) protected org.springframework.http.ResponseEntity<Object> handleInternalServerError(Exception ex, org.springframework.web.context.request.WebRequest request)
-
commence
@ExceptionHandler(org.springframework.security.core.AuthenticationException.class) public void commence(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException authException) throws IOExceptionCollect error details from the provided parameters and format according to RFC 6750, specificallyerror,error_description,error_uri, andscope.- Specified by:
commencein interfaceorg.springframework.security.web.AuthenticationEntryPoint- Parameters:
request- that resulted in anAuthenticationExceptionresponse- so that the user agent can begin authenticationauthException- that caused the invocation- Throws:
IOException
-
getAuthenticationStatus
protected org.springframework.http.HttpStatus getAuthenticationStatus(org.springframework.security.core.AuthenticationException authException)
-
createAuthenticationParameters
protected Map<String,String> createAuthenticationParameters(org.springframework.security.core.AuthenticationException authException)
-
handle
@ExceptionHandler(org.springframework.security.access.AccessDeniedException.class) public void handle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.access.AccessDeniedException accessDeniedException)Collect error details from the provided parameters and format according to RFC 6750, specificallyerror,error_description,error_uri, andscope.- Specified by:
handlein interfaceorg.springframework.security.web.access.AccessDeniedHandler- Parameters:
request- that resulted in anAccessDeniedExceptionresponse- so that the user agent can be advised of the failureaccessDeniedException- that caused the invocation
-
-