Search in sources :

Example 1 with RestExceptionHandler

use of org.entando.entando.web.common.handlers.RestExceptionHandler in project entando-core by entando.

the class AbstractControllerTest method createExceptionResolver.

protected ExceptionHandlerExceptionResolver createExceptionResolver() {
    final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("rest/messages");
    messageSource.setUseCodeAsDefaultMessage(true);
    ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver() {

        @Override
        protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) {
            Method method = new ExceptionHandlerMethodResolver(RestExceptionHandler.class).resolveMethod(exception);
            RestExceptionHandler validationHandler = new RestExceptionHandler();
            validationHandler.setMessageSource(messageSource);
            return new ServletInvocableHandlerMethod(validationHandler, method);
        }
    };
    exceptionResolver.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
    exceptionResolver.afterPropertiesSet();
    return exceptionResolver;
}
Also used : ExceptionHandlerExceptionResolver(org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) RestExceptionHandler(org.entando.entando.web.common.handlers.RestExceptionHandler) ServletInvocableHandlerMethod(org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod) ExceptionHandlerMethodResolver(org.springframework.web.method.annotation.ExceptionHandlerMethodResolver) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) ServletInvocableHandlerMethod(org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) ServletInvocableHandlerMethod(org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) JsonParseException(com.fasterxml.jackson.core.JsonParseException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 RestExceptionHandler (org.entando.entando.web.common.handlers.RestExceptionHandler)1 ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1 ExceptionHandlerMethodResolver (org.springframework.web.method.annotation.ExceptionHandlerMethodResolver)1 ExceptionHandlerExceptionResolver (org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver)1 ServletInvocableHandlerMethod (org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod)1