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)
Copies the contents (except the body) of the other message into this message and uses the provided new body instead
|
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, waitaddAttachment, 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, setHeaderspublic MessageSupport()
public Object getBody()
MessageStreamCache.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)
MessageStreamCache.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
MessagegetMandatoryBody in interface MessageInvalidPayloadException - Is thrown if the body being null or wrong class typepublic <T> T getMandatoryBody(Class<T> type) throws InvalidPayloadException
MessageStreamCache.reset() method to reset the stream to be able to re-read again (if possible).
See more details about stream caching.getMandatoryBody in interface Messagetype - the type that the bodyInvalidPayloadException - Is thrown if the body being null or wrong class typepublic void setBody(Object body)
Messagepublic <T> void setBody(Object value, Class<T> type)
Messagepublic void setBody(Object body, DataType type)
DataTypeAwaresetBody in interface DataTypeAwarebody - message bodytype - data typepublic DataType getDataType()
DataTypeAwaregetDataType in interface DataTypeAwarepublic void setDataType(DataType type)
DataTypeAwaresetDataType in interface DataTypeAwaretype - data typepublic boolean hasDataType()
DataTypeAwarehasDataType in interface DataTypeAwarepublic Message copy()
Messagepublic void copyFrom(Message that)
MessageMessage.copyFromWithNewBody(Message, Object) method instead.copyFrom in interface Messagethat - the other messageMessage.copyFromWithNewBody(Message, Object)public void copyFromWithNewBody(Message that, Object newBody)
MessagecopyFromWithNewBody in interface Messagethat - the other messagenewBody - the new body to usepublic Exchange getExchange()
MessagegetExchange in interface Messagepublic void setExchange(Exchange exchange)
public CamelContext getCamelContext()
CamelContextAwareCamelContextgetCamelContext in interface CamelContextAwarepublic void setCamelContext(CamelContext camelContext)
CamelContextAwareCamelContextsetCamelContext in interface CamelContextAwarecamelContext - the Camel contextpublic void copyAttachments(Message that)
MessagecopyAttachments in interface Messagethat - the other messagepublic abstract Message newInstance()
protected Object createBody()
public String getMessageId()
MessagegetMessageId in interface Messagepublic void setMessageId(String messageId)
MessagesetMessageId in interface MessagemessageId - id of the messageprotected String createMessageId()
Apache Camel