AbstractMethodMessageHandler processes Error as MessageHandlingException
Issue: SPR-16912
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,6 +28,7 @@ public interface MessageHandler {
|
||||
/**
|
||||
* Handle the given message.
|
||||
* @param message the message to be handled
|
||||
* @throws MessagingException if the handler failed to process the message
|
||||
*/
|
||||
void handleMessage(Message<?> message) throws MessagingException;
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.core.MethodIntrospector;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.handler.DestinationPatternsMessageCondition;
|
||||
import org.springframework.messaging.handler.HandlerMethod;
|
||||
@@ -83,7 +84,7 @@ public abstract class AbstractMethodMessageHandler<T>
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private Collection<String> destinationPrefixes = new ArrayList<String>();
|
||||
private final List<String> destinationPrefixes = new ArrayList<String>();
|
||||
|
||||
private final List<HandlerMethodArgumentResolver> customArgumentResolvers =
|
||||
new ArrayList<HandlerMethodArgumentResolver>(4);
|
||||
@@ -442,9 +443,9 @@ public abstract class AbstractMethodMessageHandler<T>
|
||||
handleNoMatch(this.handlerMethods.keySet(), lookupDestination, message);
|
||||
return;
|
||||
}
|
||||
|
||||
Comparator<Match> comparator = new MatchComparator(getMappingComparator(message));
|
||||
Collections.sort(matches, comparator);
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Found " + matches.size() + " handler methods: " + matches);
|
||||
}
|
||||
@@ -520,16 +521,16 @@ public abstract class AbstractMethodMessageHandler<T>
|
||||
processHandlerMethodException(handlerMethod, ex, message);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("Error while processing message " + message, ex);
|
||||
}
|
||||
Exception handlingException =
|
||||
new MessageHandlingException(message, "Unexpected handler method invocation error", ex);
|
||||
processHandlerMethodException(handlerMethod, handlingException, message);
|
||||
}
|
||||
}
|
||||
|
||||
protected void processHandlerMethodException(HandlerMethod handlerMethod, Exception ex, Message<?> message) {
|
||||
InvocableHandlerMethod invocable = getExceptionHandlerMethod(handlerMethod, ex);
|
||||
protected void processHandlerMethodException(HandlerMethod handlerMethod, Exception exception, Message<?> message) {
|
||||
InvocableHandlerMethod invocable = getExceptionHandlerMethod(handlerMethod, exception);
|
||||
if (invocable == null) {
|
||||
logger.error("Unhandled exception from message handler method", ex);
|
||||
logger.error("Unhandled exception from message handler method", exception);
|
||||
return;
|
||||
}
|
||||
invocable.setMessageMethodArgumentResolvers(this.argumentResolvers);
|
||||
@@ -537,7 +538,10 @@ public abstract class AbstractMethodMessageHandler<T>
|
||||
logger.debug("Invoking " + invocable.getShortLogMessage());
|
||||
}
|
||||
try {
|
||||
Object returnValue = invocable.invoke(message, ex, handlerMethod);
|
||||
Throwable cause = exception.getCause();
|
||||
Object returnValue = (cause != null ?
|
||||
invocable.invoke(message, exception, cause, handlerMethod) :
|
||||
invocable.invoke(message, exception, handlerMethod));
|
||||
MethodParameter returnType = invocable.getReturnType();
|
||||
if (void.class == returnType.getParameterType()) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user