public class DefaultMessage extends MessageSupport
Message
This implementation uses a CaseInsensitiveMap
storing the headers.
This allows us to be able to lookup headers using case insensitive keys, making it easier for end users
as they do not have to be worried about using exact keys.
See more details at CaseInsensitiveMap
.Constructor and Description |
---|
DefaultMessage() |
Modifier and Type | Method and Description |
---|---|
void |
addAttachment(String id,
DataHandler content)
Adds an attachment to the message using the id
|
void |
addAttachmentObject(String id,
Attachment content)
Adds an attachment to the message using the id
|
protected Map<String,Attachment> |
createAttachments()
A factory method to lazily create the attachmentObjects to make it easy to
create efficient Message implementations which only construct and
populate the Map on demand
|
String |
createExchangeId()
Returns the unique ID for a message exchange if this message is capable
of creating one or null if not
|
protected Map<String,Object> |
createHeaders()
A factory method to lazily create the headers to make it easy to create
efficient Message implementations which only construct and populate the
Map on demand
|
DataHandler |
getAttachment(String id)
Returns the attachment specified by the id
|
Set<String> |
getAttachmentNames()
Returns a set of attachment names of the message
|
Attachment |
getAttachmentObject(String id)
Returns the attachment specified by the id
|
Map<String,Attachment> |
getAttachmentObjects()
Returns all attachments of the message
|
Map<String,DataHandler> |
getAttachments()
Returns all attachments of the message
|
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
|
Object |
getHeader(String name,
Supplier<Object> defaultValueSupplier)
Accesses a specific header
|
<T> T |
getHeader(String name,
Supplier<Object> defaultValueSupplier,
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.
|
boolean |
hasAttachments()
Returns whether this message has attachments.
|
boolean |
hasHeaders()
Returns whether has any headers has been set.
|
protected boolean |
hasPopulatedHeaders()
Returns true if the headers have been mutated in some way
|
boolean |
isFault()
Returns true if this message represents a fault
|
protected Boolean |
isTransactedRedelivered()
A strategy for component specific messages to determine whether the
message is redelivered or not.
|
DefaultMessage |
newInstance()
Returns a new instance
|
protected void |
populateInitialAttachments(Map<String,Attachment> map)
A strategy method populate the initial set of attachmentObjects on an inbound
message from an underlying binding
|
protected void |
populateInitialHeaders(Map<String,Object> map)
A strategy method populate the initial set of headers on an inbound
message from an underlying binding
|
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 or more excludePatterns
|
void |
setAttachmentObjects(Map<String,Attachment> attachments)
Set all the attachments associated with this message
|
void |
setAttachments(Map<String,DataHandler> attachments)
Set all the attachments associated with this message
|
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)
|
copy, copyAttachments, copyFrom, copyFromWithNewBody, createBody, createMessageId, getBody, getBody, getBody, getDataType, getExchange, getMandatoryBody, getMandatoryBody, getMessageId, setBody, setBody, setBody, setDataType, setExchange, setMessageId, toString
public DefaultMessage()
public boolean isFault()
Message
public void setFault(boolean fault)
Message
fault
- the fault flagpublic Object getHeader(String name)
Message
name
- name of headerpublic Object getHeader(String name, Object defaultValue)
Message
name
- name of headerdefaultValue
- the default value to return if header was absentpublic Object getHeader(String name, Supplier<Object> defaultValueSupplier)
Message
name
- name of headerdefaultValueSupplier
- the default value supplier used to generate the value to return if header was absentpublic <T> T getHeader(String name, Class<T> type)
Message
name
- the name of the headertype
- the type of the headerpublic <T> T getHeader(String name, Object defaultValue, Class<T> type)
Message
name
- the name of the headerdefaultValue
- the default value to return if header was absenttype
- the type of the headerpublic <T> T getHeader(String name, Supplier<Object> defaultValueSupplier, Class<T> type)
Message
name
- the name of the headerdefaultValueSupplier
- the default value supplier used to generate the value to return if header was absenttype
- the type of the headerpublic void setHeader(String name, Object value)
Message
name
- of the headervalue
- to associate with the namepublic Object removeHeader(String name)
Message
name
- name of the headerpublic boolean removeHeaders(String pattern)
Message
pattern
- pattern of namespublic boolean removeHeaders(String pattern, String... excludePatterns)
Message
pattern
- pattern of names that should be removedexcludePatterns
- one or more pattern of header names that should be excluded (= preserved)public Map<String,Object> getHeaders()
Message
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.public void setHeaders(Map<String,Object> headers)
Message
Message
to this Message
, then
use getHeaders().putAll(other) to copy the headers, where other is the other headers.headers
- headers to setpublic boolean hasHeaders()
Message
public DefaultMessage newInstance()
MessageSupport
newInstance
in class MessageSupport
protected Map<String,Object> createHeaders()
protected Map<String,Attachment> createAttachments()
protected void populateInitialHeaders(Map<String,Object> map)
map
- is the empty header map to populateprotected void populateInitialAttachments(Map<String,Attachment> map)
map
- is the empty attachment map to populateprotected Boolean isTransactedRedelivered()
public void addAttachment(String id, DataHandler content)
Message
id
- the id to store the attachment undercontent
- the data handler for the attachmentpublic void addAttachmentObject(String id, Attachment content)
Message
id
- the id to store the attachment undercontent
- the attachmentpublic DataHandler getAttachment(String id)
Message
id
- the id under which the attachment is storedpublic Attachment getAttachmentObject(String id)
Message
id
- the id under which the attachment is storedpublic Set<String> getAttachmentNames()
Message
public void removeAttachment(String id)
Message
id
- the id of the attachment to removepublic Map<String,DataHandler> getAttachments()
Message
public Map<String,Attachment> getAttachmentObjects()
Message
public void setAttachments(Map<String,DataHandler> attachments)
Message
attachments
- the attachmentspublic void setAttachmentObjects(Map<String,Attachment> attachments)
Message
attachments
- the attachmentspublic boolean hasAttachments()
Message
protected boolean hasPopulatedHeaders()
public String createExchangeId()
Message
Apache Camel