polishing

If no converter is found, the MessageConversionException now contains
the message instance that could not be handled

Issue: SPR-11817
This commit is contained in:
Stephane Nicoll 2014-05-30 14:53:09 +02:00
parent 987806f7c2
commit e4ad9c5204
2 changed files with 10 additions and 8 deletions

View File

@ -67,9 +67,9 @@ public abstract class AbstractMessageReceivingTemplate<D> extends AbstractMessag
MessageConverter messageConverter = getMessageConverter(); MessageConverter messageConverter = getMessageConverter();
T value = (T) messageConverter.fromMessage(message, targetClass); T value = (T) messageConverter.fromMessage(message, targetClass);
if (value == null) { if (value == null) {
throw new MessageConversionException("Unable to convert payload='" throw new MessageConversionException(message, "Unable to convert payload='"
+ message.getPayload() + "' to type='" + targetClass + message.getPayload() + "' to type='" + targetClass
+ "', converter=[" + messageConverter + "]"); + "', converter=[" + messageConverter + "]", null);
} }
return value; return value;
} }

View File

@ -29,8 +29,7 @@ import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.support.GenericMessage; import org.springframework.messaging.support.GenericMessage;
import static org.hamcrest.CoreMatchers.isA; import static org.hamcrest.CoreMatchers.isA;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertSame;
import java.io.Writer; import java.io.Writer;
@ -118,10 +117,13 @@ public class MessageReceivingTemplateTests {
this.template.setDefaultDestination("home"); this.template.setDefaultDestination("home");
this.template.setReceiveMessage(expected); this.template.setReceiveMessage(expected);
this.template.setMessageConverter(new GenericMessageConverter(new DefaultConversionService())); this.template.setMessageConverter(new GenericMessageConverter(new DefaultConversionService()));
try {
thrown.expect(MessageConversionException.class); this.template.receiveAndConvert(Writer.class);
thrown.expectMessage("payload"); }
this.template.receiveAndConvert(Writer.class); catch (MessageConversionException e) {
assertTrue("Invalid exception message '"+e.getMessage()+"'", e.getMessage().contains("payload"));
assertSame(expected, e.getFailedMessage());
}
} }