Throw identifiable exceptions on input/output conversion failure.

This commit is contained in:
Eric Bottard
2020-02-03 16:21:02 +01:00
committed by Oleg Zhurakousky
parent 72a3c44bcb
commit 005d87181f

View File

@@ -71,6 +71,7 @@ import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.CompositeMessageConverter;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.Assert;
@@ -94,6 +95,16 @@ public class BeanFactoryAwareFunctionRegistry
private static Log logger = LogFactory.getLog(BeanFactoryAwareFunctionRegistry.class);
/**
* Identifies MessageConversionExceptions that happen when input can't be converted.
*/
public static final String COULD_NOT_CONVERT_INPUT = "Could Not Convert Input";
/**
* Identifies MessageConversionExceptions that happen when output can't be converted.
*/
public static final String COULD_NOT_CONVERT_OUTPUT = "Could Not Convert Output";
private ConfigurableApplicationContext applicationContext;
private final Map<Object, FunctionRegistration<Object>> registrationsByFunction = new HashMap<>();
@@ -655,7 +666,10 @@ public class BeanFactoryAwareFunctionRegistry
}
}
}
return convertedValue != null ? convertedValue : value;
if (convertedValue == null) {
throw new MessageConversionException(COULD_NOT_CONVERT_OUTPUT);
}
return convertedValue;
}
@@ -764,6 +778,9 @@ public class BeanFactoryAwareFunctionRegistry
if (logger.isDebugEnabled()) {
logger.debug("Converted input value " + convertedValue);
}
if (convertedValue == null) {
throw new MessageConversionException(COULD_NOT_CONVERT_INPUT);
}
return convertedValue;
}