public interface Message
Exchange
.
See DefaultMessage
for how headers
is represented in Camel using a CaseInsensitiveMap
.Modifier and Type | Method and Description |
---|---|
void |
addAttachment(String id,
DataHandler content)
Adds an attachment to the message using the id
|
Message |
copy()
Creates a copy of this message so that it can be used and possibly
modified further in another exchange
|
void |
copyAttachments(Message message)
Copies the attachments of the other message into this message
|
void |
copyFrom(Message message)
Copies the contents of the other message into this message
|
String |
createExchangeId()
Deprecated.
will be removed in Camel 3.0. It is discouraged for messages to create exchange ids
|
DataHandler |
getAttachment(String id)
Returns the attachment specified by the id
|
Set<String> |
getAttachmentNames()
Returns a set of attachment names of the message
|
Map<String,DataHandler> |
getAttachments()
Returns all attachments of the message
|
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
|
Exchange |
getExchange()
Returns the exchange this message is related to
|
Object |
getHeader(String name)
Accesses a specific header
|
<T> T |
getHeader(String name,
Class<T> type)
Returns a header associated with this message by name and specifying the
type required
|
Object |
getHeader(String name,
Object defaultValue)
Accesses a specific header
|
<T> T |
getHeader(String name,
Object defaultValue,
Class<T> type)
Returns a header associated with this message by name and specifying the
type required
|
Map<String,Object> |
getHeaders()
Returns all of the headers associated with the message.
|
Object |
getMandatoryBody()
Returns the body of the message as a POJO
|
<T> T |
getMandatoryBody(Class<T> type)
Returns the mandatory body as the specified type
|
String |
getMessageId()
Returns the id of the message
|
boolean |
hasAttachments()
Returns whether this message has attachments.
|
boolean |
hasHeaders()
Returns whether has any headers has been set.
|
boolean |
isFault()
Returns true if this message represents a fault
|
void |
removeAttachment(String id)
Removes the attachment specified by the id
|
Object |
removeHeader(String name)
Removes the named header from this message
|
boolean |
removeHeaders(String pattern)
Removes the headers from this message
|
boolean |
removeHeaders(String pattern,
String... excludePatterns)
Removes the headers from this message that match the given pattern,
except for the ones matching one ore more excludePatterns
|
void |
setAttachments(Map<String,DataHandler> attachments)
Set all the attachments associated with this message
|
void |
setBody(Object body)
Sets the body of the message
|
<T> void |
setBody(Object body,
Class<T> type)
Sets the body of the message as a specific type
|
void |
setFault(boolean fault)
Sets the fault flag on this message
|
void |
setHeader(String name,
Object value)
Sets a header on the message
|
void |
setHeaders(Map<String,Object> headers)
|
void |
setMessageId(String messageId)
Sets the id of the message
|
String getMessageId()
void setMessageId(String messageId)
messageId
- id of the messageExchange getExchange()
boolean isFault()
void setFault(boolean fault)
fault
- the fault flagObject getHeader(String name)
name
- name of headerObject getHeader(String name, Object defaultValue)
name
- name of headerdefaultValue
- the default value to return if header was absent<T> T getHeader(String name, Class<T> type)
name
- the name of the headertype
- the type of the headerTypeConversionException
- is thrown if error during type conversion<T> T getHeader(String name, Object defaultValue, Class<T> type)
name
- the name of the headerdefaultValue
- the default value to return if header was absenttype
- the type of the headervoid setHeader(String name, Object value)
name
- of the headervalue
- to associate with the nameObject removeHeader(String name)
name
- name of the headerboolean removeHeaders(String pattern)
pattern
- pattern of namesboolean removeHeaders(String pattern, String... excludePatterns)
pattern
- pattern of names that should be removedexcludePatterns
- one or more pattern of header names that should be excluded (= preserved)Map<String,Object> getHeaders()
DefaultMessage
for how headers
is represented in Camel using a CaseInsensitiveMap
.
Important: If you want to walk the returned Map
and fetch all the keys and values, you should use
the Map.entrySet()
method, which ensure you get the keys in the original case.void setHeaders(Map<String,Object> headers)
Message
to this Message
, then
use getHeaders().putAll(other) to copy the headers, where other is the other headers.headers
- headers to setboolean hasHeaders()
Object getBody()
Object getMandatoryBody() throws InvalidPayloadException
InvalidPayloadException
- Is thrown if the body being null or wrong class type<T> T getBody(Class<T> type)
type
- the type that the bodyTypeConversionException
- is thrown if error during type conversion<T> T getMandatoryBody(Class<T> type) throws InvalidPayloadException
type
- the type that the bodyInvalidPayloadException
- Is thrown if the body being null or wrong class type<T> void setBody(Object body, Class<T> type)
body
- the bodytype
- the type of the bodyMessage copy()
void copyFrom(Message message)
message
- the other messagevoid copyAttachments(Message message)
message
- the other messageDataHandler getAttachment(String id)
id
- the id under which the attachment is storedSet<String> getAttachmentNames()
void removeAttachment(String id)
id
- the id of the attachment to removevoid addAttachment(String id, DataHandler content)
id
- the id to store the attachment undercontent
- the data handler for the attachmentMap<String,DataHandler> getAttachments()
void setAttachments(Map<String,DataHandler> attachments)
attachments
- the attachmentsboolean hasAttachments()
@Deprecated String createExchangeId()
Apache Camel