this.exceptionHandlerCache.put(handlerType, resolver); Method method = resolver.resolveMethod(exception); if (method != null) { return new ServletInvocableHandlerMethod(handlerMethod.getBean(), method); if (advice.isApplicableToBeanType(handlerType)) { ExceptionHandlerMethodResolver resolver = entry.getValue(); Method method = resolver.resolveMethod(exception); if (method != null) { return new ServletInvocableHandlerMethod(advice.resolveBean(), method);
@Test public void resolveMethodNoMatch() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); Exception exception = new Exception(); assertNull("1st lookup", resolver.resolveMethod(exception)); assertNull("2nd lookup from cache", resolver.resolveMethod(exception)); }
@Test public void resolveMethodFromAnnotation() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); IOException exception = new IOException(); assertEquals("handleIOException", resolver.resolveMethod(exception).getName()); }
@Test public void resolveMethodExceptionSubType() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); IOException ioException = new FileNotFoundException(); assertEquals("handleIOException", resolver.resolveMethod(ioException).getName()); SocketException bindException = new BindException(); assertEquals("handleSocketException", resolver.resolveMethod(bindException).getName()); }
@Test public void resolveMethodBestMatch() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); SocketException exception = new SocketException(); assertEquals("handleSocketException", resolver.resolveMethod(exception).getName()); }
@Test public void resolveMethodInherited() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(InheritedController.class); IOException exception = new IOException(); assertEquals("handleIOException", resolver.resolveMethod(exception).getName()); }
@Test public void resolveMethodFromArgument() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); IllegalArgumentException exception = new IllegalArgumentException(); assertEquals("handleIllegalArgumentException", resolver.resolveMethod(exception).getName()); }
this.exceptionHandlerCache.put(handlerType, resolver); Method method = resolver.resolveMethod(exception); if (method != null) { return new ServletInvocableHandlerMethod(handlerMethod.getBean(), method); if (advice.isApplicableToBeanType(handlerType)) { ExceptionHandlerMethodResolver resolver = entry.getValue(); Method method = resolver.resolveMethod(exception); if (method != null) { return new ServletInvocableHandlerMethod(advice.resolveBean(), method);
Method method = resolver.resolveMethod((Exception) exception);
Method method = resolver.resolveMethod((Exception) exception);
@Override protected ServletInvocableHandlerMethod getExceptionHandlerMethod(final HandlerMethod handlerMethod, final Exception exception) { if (((InvocationException) exception).getStatusCode() == HttpStatus.BAD_REQUEST.value()) { Method method = new ExceptionHandlerMethodResolver(BadRequestExceptionAdvice.class).resolveMethod(exception); return new ServletInvocableHandlerMethod(new BadRequestExceptionAdvice(), method); } else if (((InvocationException) exception).getStatusCode() == HttpStatus.TOO_MANY_REQUESTS.value()) { Method method = new ExceptionHandlerMethodResolver(TooManyRequestsExceptionAdvice.class).resolveMethod(exception); return new ServletInvocableHandlerMethod(new TooManyRequestsExceptionAdvice(), method); } return super.getExceptionHandlerMethod(handlerMethod, exception); } }
@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); } };