Class ContentTypeDelegatingMessageConverter
- java.lang.Object
-
- org.springframework.amqp.support.converter.ContentTypeDelegatingMessageConverter
-
- All Implemented Interfaces:
MessageConverter
public class ContentTypeDelegatingMessageConverter extends Object implements MessageConverter
A compositeMessageConverter
that delegates to an actualMessageConverter
based on the contentType header. Supports a default converter when no content type matches. Note: theMessageProperties
requires a content type header to select a converter when used for outbound conversion, but the converter will (generally) override it to match the actual conversion.- Since:
- 1.4.2
- Author:
- Eric Rizzo, Gary Russell, Artem Bilan
-
-
Constructor Summary
Constructors Constructor Description ContentTypeDelegatingMessageConverter()
Constructs an instance using a defaultSimpleMessageConverter
.ContentTypeDelegatingMessageConverter(MessageConverter defaultConverter)
Constructs an instance using a the supplied default converter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDelegate(String contentType, MessageConverter messageConverter)
Add a delegate converter for the content type.Object
fromMessage(Message message)
Convert from a Message to a Java object.protected MessageConverter
getConverterForContentType(String contentType)
Map<String,MessageConverter>
getDelegates()
MessageConverter
removeDelegate(String contentType)
Remove the delegate for the content type.void
setDelegates(Map<String,MessageConverter> delegatesByContentType)
Message
toMessage(Object object, MessageProperties messageProperties)
Convert a Java object to a Message.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.amqp.support.converter.MessageConverter
toMessage
-
-
-
-
Constructor Detail
-
ContentTypeDelegatingMessageConverter
public ContentTypeDelegatingMessageConverter()
Constructs an instance using a defaultSimpleMessageConverter
.
-
ContentTypeDelegatingMessageConverter
public ContentTypeDelegatingMessageConverter(MessageConverter defaultConverter)
Constructs an instance using a the supplied default converter. May be null meaning a strict content-type match is required.- Parameters:
defaultConverter
- the converter.
-
-
Method Detail
-
setDelegates
public void setDelegates(Map<String,MessageConverter> delegatesByContentType)
-
getDelegates
public Map<String,MessageConverter> getDelegates()
-
addDelegate
public void addDelegate(String contentType, MessageConverter messageConverter)
Add a delegate converter for the content type.- Parameters:
contentType
- the content type to check.messageConverter
- theMessageConverter
for the content type.- Since:
- 1.6
-
removeDelegate
public MessageConverter removeDelegate(String contentType)
Remove the delegate for the content type.- Parameters:
contentType
- the content type key to removeMessageConverter
from delegates.- Returns:
- the remove
MessageConverter
.
-
fromMessage
public Object fromMessage(Message message) throws MessageConversionException
Description copied from interface:MessageConverter
Convert from a Message to a Java object.- Specified by:
fromMessage
in interfaceMessageConverter
- Parameters:
message
- the message to convert- Returns:
- the converted Java object
- Throws:
MessageConversionException
- in case of conversion failure
-
toMessage
public Message toMessage(Object object, MessageProperties messageProperties)
Description copied from interface:MessageConverter
Convert a Java object to a Message.- Specified by:
toMessage
in interfaceMessageConverter
- Parameters:
object
- the object to convertmessageProperties
- The message properties.- Returns:
- the Message
-
getConverterForContentType
protected MessageConverter getConverterForContentType(String contentType)
-
-