Skip to content

Commit 8346eed

Browse files
committed
Reset BytesMessage after payload extraction
Issue: SPR-13769
1 parent 9589749 commit 8346eed

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.jms.listener.adapter;
1818

19+
import javax.jms.BytesMessage;
1920
import javax.jms.Destination;
2021
import javax.jms.InvalidDestinationException;
2122
import javax.jms.JMSException;
@@ -204,9 +205,9 @@ protected void handleListenerException(Throwable ex) {
204205
/**
205206
* Extract the message body from the given JMS message.
206207
* @param message the JMS {@code Message}
207-
* @return the content of the message, to be passed into the
208-
* listener method as argument
209-
* @throws MessageConversionException if the message could not be unmarshaled
208+
* @return the content of the message, to be passed into the listener method
209+
* as an argument
210+
* @throws MessageConversionException if the message could not be extracted
210211
*/
211212
protected Object extractMessage(Message message) {
212213
try {
@@ -408,7 +409,19 @@ private class MessagingMessageConverterAdapter extends MessagingMessageConverter
408409

409410
@Override
410411
protected Object extractPayload(Message message) throws JMSException {
411-
return extractMessage(message);
412+
Object payload = extractMessage(message);
413+
if (message instanceof BytesMessage) {
414+
try {
415+
// In case the BytesMessage is going to be received as a user argument:
416+
// reset it, otherwise it would appear empty to such processing code...
417+
((BytesMessage) message).reset();
418+
}
419+
catch (JMSException ex) {
420+
// Continue since the BytesMessage typically won't be used any further.
421+
logger.debug("Failed to reset BytesMessage after payload extraction", ex);
422+
}
423+
}
424+
return payload;
412425
}
413426

414427
@Override

0 commit comments

Comments
 (0)