private List<HandlerMethodArgumentResolver> getArgumentResolvers() { return getAdapter().getArgumentResolvers(); }
private Mono<HandlerResult> handleException(Throwable ex, HandlerMethod handlerMethod, BindingContext bindingContext, ServerWebExchange exchange) { InvocableHandlerMethod invocable = findExceptionHandler(handlerMethod, ex); if (invocable != null) { try { if (logger.isDebugEnabled()) { logger.debug("Invoking @ExceptionHandler method: " + invocable.getMethod()); } invocable.setArgumentResolvers(getArgumentResolvers()); bindingContext.getModel().asMap().clear(); return invocable.invoke(exchange, bindingContext, ex); } catch (Throwable invocationEx) { if (logger.isWarnEnabled()) { logger.warn("Failed to invoke @ExceptionHandler method: " + invocable.getMethod(), invocationEx); } } } return Mono.error(ex); }
@Override public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) { HandlerMethod handlerMethod = (HandlerMethod) handler; InvocableHandlerMethod invocable = new InvocableHandlerMethod(handlerMethod); invocable.setArgumentResolvers(getArgumentResolvers()); Mono<BindingContext> bindingContextMono = this.bindingContextFactory.createBindingContext(handlerMethod, exchange); return bindingContextMono.then(bindingContext -> invocable.invoke(exchange, bindingContext) .doOnNext(result -> result.setExceptionHandler( ex -> handleException(ex, handlerMethod, bindingContext, exchange))) .otherwise(ex -> handleException( ex, handlerMethod, bindingContext, exchange))); }