Reset BytesMessage after payload extraction

Issue: SPR-13769
master
Juergen Hoeller 9 years ago
parent 9589749fb2
commit 8346eeda27
  1. 21
      spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java

@ -16,6 +16,7 @@
package org.springframework.jms.listener.adapter; package org.springframework.jms.listener.adapter;
import javax.jms.BytesMessage;
import javax.jms.Destination; import javax.jms.Destination;
import javax.jms.InvalidDestinationException; import javax.jms.InvalidDestinationException;
import javax.jms.JMSException; import javax.jms.JMSException;
@ -204,9 +205,9 @@ public abstract class AbstractAdaptableMessageListener
/** /**
* Extract the message body from the given JMS message. * Extract the message body from the given JMS message.
* @param message the JMS {@code Message} * @param message the JMS {@code Message}
* @return the content of the message, to be passed into the * @return the content of the message, to be passed into the listener method
* listener method as argument * as an argument
* @throws MessageConversionException if the message could not be unmarshaled * @throws MessageConversionException if the message could not be extracted
*/ */
protected Object extractMessage(Message message) { protected Object extractMessage(Message message) {
try { try {
@ -408,7 +409,19 @@ public abstract class AbstractAdaptableMessageListener
@Override @Override
protected Object extractPayload(Message message) throws JMSException { protected Object extractPayload(Message message) throws JMSException {
return extractMessage(message); Object payload = extractMessage(message);
if (message instanceof BytesMessage) {
try {
// In case the BytesMessage is going to be received as a user argument:
// reset it, otherwise it would appear empty to such processing code...
((BytesMessage) message).reset();
}
catch (JMSException ex) {
// Continue since the BytesMessage typically won't be used any further.
logger.debug("Failed to reset BytesMessage after payload extraction", ex);
}
}
return payload;
} }
@Override @Override

Loading…
Cancel
Save