Example usage for org.springframework.web.method.annotation ExceptionHandlerMethodResolver ExceptionHandlerMethodResolver

List of usage examples for org.springframework.web.method.annotation ExceptionHandlerMethodResolver ExceptionHandlerMethodResolver

Introduction

In this page you can find the example usage for org.springframework.web.method.annotation ExceptionHandlerMethodResolver ExceptionHandlerMethodResolver.

Prototype

public ExceptionHandlerMethodResolver(Class<?> handlerType) 

Source Link

Document

A constructor that finds ExceptionHandler methods in the given type.

Usage

From source file:od.controller.tests.ControllerTests.java

protected ExceptionHandlerExceptionResolver createExceptionResolver() {
    ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver() {
        @Override//from  w w  w  . j  ava 2s  .c om
        protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod,
                Exception exception) {
            Method method = new ExceptionHandlerMethodResolver(AppControllerAdvice.class)
                    .resolveMethod(exception);
            return new ServletInvocableHandlerMethod(new AppControllerAdvice(), method);
        }
    };
    exceptionResolver.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
    exceptionResolver.afterPropertiesSet();
    return exceptionResolver;
}

From source file:org.exoplatform.acceptance.rest.administration.credential.CredentialCRUDControllerTest.java

private ExceptionHandlerExceptionResolver createExceptionResolver() {
    ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver() {
        protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod,
                Exception exception) {
            Method method = new ExceptionHandlerMethodResolver(JsonErrorHandler.class).resolveMethod(exception);
            return new ServletInvocableHandlerMethod(jsonErrorHandler, method);
        }//  w  w  w. j a v  a2  s  . c  o m
    };
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    messageConverters.add(new MappingJackson2HttpMessageConverter());
    exceptionResolver.setMessageConverters(messageConverters);
    exceptionResolver.afterPropertiesSet();
    return exceptionResolver;
}

From source file:org.finra.dm.service.config.ServiceSpringModuleConfig.java

/**
 * Returns a new "exception handler method resolver" that knows how to resolve exception handler methods based on the "DM error information exception
 * handler". This provides the ability to return an "exception handling" method for a specific exception.
 *
 * @return the exception handler method resolver.
 *///from w w  w . j  a  va  2  s .  c  om
@Bean
public ExceptionHandlerMethodResolver exceptionHandlerMethodResolver() {
    return new ExceptionHandlerMethodResolver(DmErrorInformationExceptionHandler.class);
}

From source file:org.finra.herd.service.config.ServiceSpringModuleConfig.java

/**
 * Returns a new "exception handler method resolver" that knows how to resolve exception handler methods based on the "herd error information exception
 * handler". This provides the ability to return an "exception handling" method for a specific exception.
 *
 * @return the exception handler method resolver.
 *///from www . j  ava 2 s  .c om
@Bean
public ExceptionHandlerMethodResolver exceptionHandlerMethodResolver() {
    return new ExceptionHandlerMethodResolver(HerdErrorInformationExceptionHandler.class);
}

From source file:org.springframework.web.reactive.result.method.annotation.ControllerMethodResolver.java

private void initControllerAdviceCaches(@Nullable ApplicationContext applicationContext) {
    if (applicationContext == null) {
        return;//from w w w. ja  v a  2  s  .  com
    }
    if (logger.isInfoEnabled()) {
        logger.info("Looking for @ControllerAdvice: " + applicationContext);
    }

    List<ControllerAdviceBean> beans = ControllerAdviceBean.findAnnotatedBeans(applicationContext);
    AnnotationAwareOrderComparator.sort(beans);

    for (ControllerAdviceBean bean : beans) {
        Class<?> beanType = bean.getBeanType();
        if (beanType != null) {
            Set<Method> attrMethods = selectMethods(beanType, ATTRIBUTE_METHODS);
            if (!attrMethods.isEmpty()) {
                this.modelAttributeAdviceCache.put(bean, attrMethods);
                if (logger.isInfoEnabled()) {
                    logger.info("Detected @ModelAttribute methods in " + bean);
                }
            }
            Set<Method> binderMethods = selectMethods(beanType, BINDER_METHODS);
            if (!binderMethods.isEmpty()) {
                this.initBinderAdviceCache.put(bean, binderMethods);
                if (logger.isInfoEnabled()) {
                    logger.info("Detected @InitBinder methods in " + bean);
                }
            }
            ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(beanType);
            if (resolver.hasExceptionMappings()) {
                this.exceptionHandlerAdviceCache.put(bean, resolver);
                if (logger.isInfoEnabled()) {
                    logger.info("Detected @ExceptionHandler methods in " + bean);
                }
            }
        }
    }
}