@BeforeClass
 public static void setupOnce() {
   ExceptionHandlerExceptionResolver r = new ExceptionHandlerExceptionResolver();
   r.afterPropertiesSet();
   RESOLVER_COUNT = r.getArgumentResolvers().getResolvers().size();
   HANDLER_COUNT = r.getReturnValueHandlers().getHandlers().size();
 }
Пример #2
0
 @Bean
 public ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver() {
   ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver =
       new ExceptionHandlerExceptionResolver();
   exceptionHandlerExceptionResolver.setOrder(1);
   exceptionHandlerExceptionResolver.setMessageConverters(
       Lists.newArrayList(getJson2MessageConverter()));
   return exceptionHandlerExceptionResolver;
 }
  @Override
  protected List<? extends HandlerExceptionResolver> initHandlerExceptionResolvers() {
    ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver();
    if (messageConverters != null) {
      exceptionResolver.setMessageConverters(messageConverters);
    }
    exceptionResolver.afterPropertiesSet();

    List<HandlerExceptionResolver> resolvers = new ArrayList<HandlerExceptionResolver>();
    resolvers.add(exceptionResolver);
    resolvers.add(new ResponseStatusExceptionResolver());
    resolvers.add(new DefaultHandlerExceptionResolver());

    return resolvers;
  }
Пример #4
0
  /**
   * Register Exception Handlers with the Standalone MockMvc instance.
   *
   * @return the excepation handler resolver
   */
  protected ExceptionHandlerExceptionResolver createExceptionResolver() {
    ExceptionHandlerExceptionResolver exceptionResolver =
        new ExceptionHandlerExceptionResolver() {
          protected ServletInvocableHandlerMethod getExceptionHandlerMethod(
              HandlerMethod handlerMethod, Exception exception) {
            Method method =
                new ExceptionHandlerMethodResolver(GlobalExceptionHandler.class)
                    .resolveMethod(exception);
            return new ServletInvocableHandlerMethod(new GlobalExceptionHandler(), method);
          }
        };
    exceptionResolver.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

    exceptionResolver.afterPropertiesSet();
    return exceptionResolver;
  }
Пример #5
0
  private ExceptionHandlerExceptionResolver createExceptionResolver(Object handler) {

    ExceptionHandlerExceptionResolver resolver =
        new ExceptionHandlerExceptionResolver() {

          @Override
          protected ServletInvocableHandlerMethod getExceptionHandlerMethod(
              HandlerMethod handlerMethod, Exception ex) {

            Method m = new ExceptionHandlerMethodResolver(handler.getClass()).resolveMethod(ex);
            return new ServletInvocableHandlerMethod(handler, m);
          }
        };
    resolver.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
    resolver.afterPropertiesSet();
    return resolver;
  }
 @Bean
 public ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver() {
   ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver();
   resolver.setMessageConverters(HttpMessageConverterUtils.getDefaultHttpMessageConverters());
   return resolver;
 }