Fix conversion of Message<?> payload for replies
If a custom MessageConverter is set, it is not used for replies defined via the Message abstraction. This commit harmonizes the behaviour of the `MessagingMessageConverter` so that the conversion of the payload can be converted for both incoming and outgoing messages. Issue: SPR-12912
This commit is contained in:
committed by
Stephane Nicoll
parent
444b9032be
commit
72894b26c2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -396,6 +396,15 @@ public abstract class AbstractAdaptableMessageListener
|
||||
protected Object extractPayload(Message message) throws JMSException {
|
||||
return extractMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Message createMessageForPayload(Object payload, Session session) throws JMSException {
|
||||
MessageConverter converter = getMessageConverter();
|
||||
if (converter != null) {
|
||||
return converter.toMessage(payload, session);
|
||||
}
|
||||
throw new IllegalStateException("No message converter, cannot handle '" + payload + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -93,7 +93,7 @@ public class MessagingMessageConverter implements MessageConverter, Initializing
|
||||
Message.class.getName() + "] is handled by this converter");
|
||||
}
|
||||
Message<?> input = (Message<?>) object;
|
||||
javax.jms.Message reply = this.payloadConverter.toMessage(input.getPayload(), session);
|
||||
javax.jms.Message reply = createMessageForPayload(input.getPayload(), session);
|
||||
this.headerMapper.fromHeaders(input.getHeaders(), reply);
|
||||
return reply;
|
||||
}
|
||||
@@ -119,4 +119,12 @@ public class MessagingMessageConverter implements MessageConverter, Initializing
|
||||
return this.payloadConverter.fromMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a JMS message for the specified payload.
|
||||
* @see MessageConverter#toMessage(Object, Session)
|
||||
*/
|
||||
protected javax.jms.Message createMessageForPayload(Object payload, Session session) throws JMSException {
|
||||
return this.payloadConverter.toMessage(payload, session);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user