Throw a proper exception if no convert is found
Prior to this commit, no exception was raised if a message could not be converted to the requested payload because no suitable converter were found. This commit adds an explicit check if the converted payload is null. Issue: SPR-11817
This commit is contained in:
@@ -194,11 +194,10 @@ public class JmsMessagingTemplate
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T receiveAndConvert(String destinationName, Class<T> targetClass) throws MessagingException {
|
||||
Message<?> message = doReceive(destinationName);
|
||||
if (message != null) {
|
||||
return (T) getMessageConverter().fromMessage(message, targetClass);
|
||||
return doConvert(message, targetClass);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
||||
@@ -26,7 +26,6 @@ import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
@@ -326,12 +325,11 @@ public class JmsMessagingTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("SPR-11817")
|
||||
public void receiveAndConvertNoConverter() {
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage("Hello");
|
||||
given(jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
|
||||
thrown.expect(MessageConversionException.class);
|
||||
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
messagingTemplate.receiveAndConvert("myQueue", Writer.class);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user