|
|
|
@ -57,7 +57,6 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, BeanFactory |
|
|
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog(RequestMappingHandlerAdapter.class); |
|
|
|
private static final Log logger = LogFactory.getLog(RequestMappingHandlerAdapter.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final List<HttpMessageReader<?>> messageReaders = new ArrayList<>(10); |
|
|
|
private final List<HttpMessageReader<?>> messageReaders = new ArrayList<>(10); |
|
|
|
|
|
|
|
|
|
|
|
private WebBindingInitializer webBindingInitializer; |
|
|
|
private WebBindingInitializer webBindingInitializer; |
|
|
|
@ -74,7 +73,6 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, BeanFactory |
|
|
|
new ConcurrentHashMap<>(64); |
|
|
|
new ConcurrentHashMap<>(64); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RequestMappingHandlerAdapter() { |
|
|
|
public RequestMappingHandlerAdapter() { |
|
|
|
this.messageReaders.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder())); |
|
|
|
this.messageReaders.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder())); |
|
|
|
this.messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); |
|
|
|
this.messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); |
|
|
|
@ -226,28 +224,27 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, BeanFactory |
|
|
|
private Mono<HandlerResult> handleException(Throwable ex, HandlerMethod handlerMethod, |
|
|
|
private Mono<HandlerResult> handleException(Throwable ex, HandlerMethod handlerMethod, |
|
|
|
BindingContext bindingContext, ServerWebExchange exchange) { |
|
|
|
BindingContext bindingContext, ServerWebExchange exchange) { |
|
|
|
|
|
|
|
|
|
|
|
if (ex instanceof Exception) { |
|
|
|
InvocableHandlerMethod invocable = findExceptionHandler(handlerMethod, ex); |
|
|
|
InvocableHandlerMethod invocable = findExceptionHandler(handlerMethod, (Exception) ex); |
|
|
|
if (invocable != null) { |
|
|
|
if (invocable != null) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug("Invoking @ExceptionHandler method: " + invocable.getMethod()); |
|
|
|
logger.debug("Invoking @ExceptionHandler method: " + invocable); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
invocable.setHandlerMethodArgumentResolvers(getArgumentResolvers()); |
|
|
|
|
|
|
|
bindingContext.getModel().clear(); |
|
|
|
|
|
|
|
return invocable.invokeForRequest(exchange, bindingContext, ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception invocationEx) { |
|
|
|
invocable.setHandlerMethodArgumentResolvers(getArgumentResolvers()); |
|
|
|
if (logger.isErrorEnabled()) { |
|
|
|
bindingContext.getModel().clear(); |
|
|
|
logger.error("Failed to invoke @ExceptionHandler method: " + invocable, invocationEx); |
|
|
|
return invocable.invokeForRequest(exchange, bindingContext, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch (Throwable invocationEx) { |
|
|
|
|
|
|
|
if (logger.isWarnEnabled()) { |
|
|
|
|
|
|
|
logger.warn("Failed to invoke @ExceptionHandler method: " + invocable.getMethod(), |
|
|
|
|
|
|
|
invocationEx); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return Mono.error(ex); |
|
|
|
return Mono.error(ex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected InvocableHandlerMethod findExceptionHandler(HandlerMethod handlerMethod, Exception exception) { |
|
|
|
protected InvocableHandlerMethod findExceptionHandler(HandlerMethod handlerMethod, Throwable exception) { |
|
|
|
if (handlerMethod == null) { |
|
|
|
if (handlerMethod == null) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -257,8 +254,8 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, BeanFactory |
|
|
|
resolver = new ExceptionHandlerMethodResolver(handlerType); |
|
|
|
resolver = new ExceptionHandlerMethodResolver(handlerType); |
|
|
|
this.exceptionHandlerCache.put(handlerType, resolver); |
|
|
|
this.exceptionHandlerCache.put(handlerType, resolver); |
|
|
|
} |
|
|
|
} |
|
|
|
Method method = resolver.resolveMethod(exception); |
|
|
|
Method method = resolver.resolveMethodByExceptionType(exception.getClass()); |
|
|
|
return (method != null ? new InvocableHandlerMethod(handlerMethod.getBean(), method) : null); |
|
|
|
return (method != null ? new InvocableHandlerMethod(handlerMethod.getBean(), method) : null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|