Class ContentTypeDelegatingMessageConverter
- java.lang.Object
-
- org.springframework.amqp.support.converter.ContentTypeDelegatingMessageConverter
-
- All Implemented Interfaces:
MessageConverter
public class ContentTypeDelegatingMessageConverter extends Object implements MessageConverter
A compositeMessageConverterthat delegates to an actualMessageConverterbased on the contentType header. Supports a default converter when no content type matches. Note: theMessagePropertiesrequires 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 voidaddDelegate(String contentType, MessageConverter messageConverter)Add a delegate converter for the content type.ObjectfromMessage(Message message)Convert from a Message to a Java object.protected MessageConvertergetConverterForContentType(String contentType)Map<String,MessageConverter>getDelegates()MessageConverterremoveDelegate(String contentType)Remove the delegate for the content type.voidsetDelegates(Map<String,MessageConverter> delegatesByContentType)MessagetoMessage(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- theMessageConverterfor 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 removeMessageConverterfrom delegates.- Returns:
- the remove
MessageConverter.
-
fromMessage
public Object fromMessage(Message message) throws MessageConversionException
Description copied from interface:MessageConverterConvert from a Message to a Java object.- Specified by:
fromMessagein 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:MessageConverterConvert a Java object to a Message.- Specified by:
toMessagein interfaceMessageConverter- Parameters:
object- the object to convertmessageProperties- The message properties.- Returns:
- the Message
-
getConverterForContentType
protected MessageConverter getConverterForContentType(String contentType)
-
-