|
16 | 16 |
|
17 | 17 | package org.springframework.jms.listener.adapter;
|
18 | 18 |
|
| 19 | +import javax.jms.BytesMessage; |
19 | 20 | import javax.jms.Destination;
|
20 | 21 | import javax.jms.InvalidDestinationException;
|
21 | 22 | import javax.jms.JMSException;
|
@@ -204,9 +205,9 @@ protected void handleListenerException(Throwable ex) {
|
204 | 205 | /**
|
205 | 206 | * Extract the message body from the given JMS message.
|
206 | 207 | * @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 |
210 | 211 | */
|
211 | 212 | protected Object extractMessage(Message message) {
|
212 | 213 | try {
|
@@ -408,7 +409,19 @@ private class MessagingMessageConverterAdapter extends MessagingMessageConverter
|
408 | 409 |
|
409 | 410 | @Override
|
410 | 411 | 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; |
412 | 425 | }
|
413 | 426 |
|
414 | 427 | @Override
|
|
0 commit comments