public abstract class MessageSupport extends Object implements Message, CamelContextAware, DataTypeAware
Message
body handling features but letting the derived class deal
with headers.
Unless a specific provider wishes to do something particularly clever with
headers you probably want to just derive from DefaultMessage
Constructor and Description |
---|
MessageSupport() |
Modifier and Type | Method and Description |
---|---|
Message |
copy()
Creates a copy of this message so that it can be used and possibly
modified further in another exchange.
|
void |
copyAttachments(Message that)
Copies the attachments of the other message into this message
|
void |
copyFrom(Message that)
Copies the contents of the other message into this message
If you need to do a copy and then set a new body,
then use
Message.copyFromWithNewBody(Message, Object) method instead. |
void |
copyFromWithNewBody(Message that,
Object newBody)
|
protected Object |
createBody()
A factory method to allow a provider to lazily create the message body
for inbound messages from other sources
|
protected String |
createMessageId()
Allow implementations to auto-create a messageId
|
Object |
getBody()
Returns the body of the message as a POJO
The body can be null if no body is set.
|
<T> T |
getBody(Class<T> type)
Returns the body as the specified type
Notice if the message body is stream based then calling this method multiple times may lead to the stream not being able to be re-read again.
|
protected <T> T |
getBody(Class<T> type,
Object body) |
CamelContext |
getCamelContext()
Get the
CamelContext |
DataType |
getDataType()
Get the data type of the message.
|
Exchange |
getExchange()
Returns the exchange this message is related to
|
Object |
getMandatoryBody()
Returns the body of the message as a POJO
Notice if the message body is stream based then calling this method multiple times may lead to the stream not being able to be re-read again.
|
<T> T |
getMandatoryBody(Class<T> type)
Returns the mandatory body as the specified type
Notice if the message body is stream based then calling this method multiple times may lead to the stream not being able to be re-read again.
|
String |
getMessageId()
Returns the id of the message
|
boolean |
hasDataType()
Whether any data type has been configured
|
abstract Message |
newInstance()
Returns a new instance
|
void |
setBody(Object body)
Sets the body of the message
|
<T> void |
setBody(Object value,
Class<T> type)
Sets the body of the message as a specific type
|
void |
setBody(Object body,
DataType type)
Set the message body with data type.
|
void |
setCamelContext(CamelContext camelContext)
Injects the
CamelContext |
void |
setDataType(DataType type)
Set the data type of the message.
|
void |
setExchange(Exchange exchange) |
void |
setMessageId(String messageId)
Sets the id of the message
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addAttachment, addAttachmentObject, createExchangeId, getAttachment, getAttachmentNames, getAttachmentObject, getAttachmentObjects, getAttachments, getHeader, getHeader, getHeader, getHeader, getHeader, getHeader, getHeaders, hasAttachments, hasHeaders, isFault, removeAttachment, removeHeader, removeHeaders, removeHeaders, setAttachmentObjects, setAttachments, setFault, setHeader, setHeaders
public MessageSupport()
public Object getBody()
Message
StreamCache.reset()
method to reset the stream to be able to re-read again (if possible).
See more details about stream caching.public <T> T getBody(Class<T> type)
Message
StreamCache.reset()
method to reset the stream to be able to re-read again (if possible).
See more details about stream caching.public Object getMandatoryBody() throws InvalidPayloadException
Message
getMandatoryBody
in interface Message
InvalidPayloadException
- Is thrown if the body being null or wrong class typepublic <T> T getMandatoryBody(Class<T> type) throws InvalidPayloadException
Message
StreamCache.reset()
method to reset the stream to be able to re-read again (if possible).
See more details about stream caching.getMandatoryBody
in interface Message
type
- the type that the bodyInvalidPayloadException
- Is thrown if the body being null or wrong class typepublic void setBody(Object body)
Message
public <T> void setBody(Object value, Class<T> type)
Message
public void setBody(Object body, DataType type)
DataTypeAware
setBody
in interface DataTypeAware
body
- message bodytype
- data typepublic DataType getDataType()
DataTypeAware
getDataType
in interface DataTypeAware
public void setDataType(DataType type)
DataTypeAware
setDataType
in interface DataTypeAware
type
- data typepublic boolean hasDataType()
DataTypeAware
hasDataType
in interface DataTypeAware
public void copyFrom(Message that)
Message
Message.copyFromWithNewBody(Message, Object)
method instead.
The returned Message
copy will have its Exchange
set
to the same Exchange
instance as from the source.copyFrom
in interface Message
that
- the other messageMessage.copyFromWithNewBody(Message, Object)
public void copyFromWithNewBody(Message that, Object newBody)
Message
Message
copy will have its Exchange
set
to the same Exchange
instance as from the source.copyFromWithNewBody
in interface Message
that
- the other messagenewBody
- the new body to usepublic Exchange getExchange()
Message
getExchange
in interface Message
public void setExchange(Exchange exchange)
public CamelContext getCamelContext()
CamelContextAware
CamelContext
getCamelContext
in interface CamelContextAware
public void setCamelContext(CamelContext camelContext)
CamelContextAware
CamelContext
setCamelContext
in interface CamelContextAware
camelContext
- the Camel contextpublic void copyAttachments(Message that)
Message
copyAttachments
in interface Message
that
- the other messagepublic abstract Message newInstance()
protected Object createBody()
public String getMessageId()
Message
getMessageId
in interface Message
public void setMessageId(String messageId)
Message
setMessageId
in interface Message
messageId
- id of the messageprotected String createMessageId()
Apache Camel