Skip to content

Commit e4faaa3

Browse files
committed
Reset BytesMessage after payload extraction
Issue: SPR-13769 (cherry picked from commit 8346eed)
1 parent d04f785 commit e4faaa3

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 {
@@ -396,7 +397,19 @@ private class MessagingMessageConverterAdapter extends MessagingMessageConverter
396397

397398
@Override
398399
protected Object extractPayload(Message message) throws JMSException {
399-
return extractMessage(message);
400+
Object payload = extractMessage(message);
401+
if (message instanceof BytesMessage) {
402+
try {
403+
// In case the BytesMessage is going to be received as a user argument:
404+
// reset it, otherwise it would appear empty to such processing code...
405+
((BytesMessage) message).reset();
406+
}
407+
catch (JMSException ex) {
408+
// Continue since the BytesMessage typically won't be used any further.
409+
logger.debug("Failed to reset BytesMessage after payload extraction", ex);
410+
}
411+
}
412+
return payload;
400413
}
401414
}
402415

0 commit comments

Comments
 (0)