org.apache.camel.impl
Class DefaultMessage

java.lang.Object
  extended by org.apache.camel.impl.MessageSupport
      extended by org.apache.camel.impl.DefaultMessage
All Implemented Interfaces:
Message
Direct Known Subclasses:
GenericFileMessage

public class DefaultMessage
extends MessageSupport

The default implementation of 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.

Version:

Constructor Summary
DefaultMessage()
           
 
Method Summary
 void addAttachment(String id, DataHandler content)
          Adds an attachment to the message using the id
protected  Map<String,DataHandler> createAttachments()
          A factory method to lazily create the attachments 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
 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
 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,DataHandler> map)
          A strategy method populate the initial set of attachments 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 ore more excludePatterns
 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)
          Set all the headers associated with this message
 String toString()
           
 
Methods inherited from class org.apache.camel.impl.MessageSupport
copy, copyFrom, createBody, createMessageId, getBody, getBody, getBody, getExchange, getMandatoryBody, getMandatoryBody, getMessageId, setBody, setBody, setExchange, setMessageId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultMessage

public DefaultMessage()
Method Detail

toString

public String toString()
Overrides:
toString in class Object

isFault

public boolean isFault()
Description copied from interface: Message
Returns true if this message represents a fault

Returns:
true if this is a fault message, false for regular messages.

setFault

public void setFault(boolean fault)
Description copied from interface: Message
Sets the fault flag on this message

Parameters:
fault - the fault flag

getHeader

public Object getHeader(String name)
Description copied from interface: Message
Accesses a specific header

Parameters:
name - name of header
Returns:
the value of the given header or null if there is no header for the given name

getHeader

public Object getHeader(String name,
                        Object defaultValue)
Description copied from interface: Message
Accesses a specific header

Parameters:
name - name of header
defaultValue - the default value to return if header was absent
Returns:
the value of the given header or defaultValue if there is no header for the given name

getHeader

public <T> T getHeader(String name,
                       Class<T> type)
Description copied from interface: Message
Returns a header associated with this message by name and specifying the type required

Parameters:
name - the name of the header
type - the type of the header
Returns:
the value of the given header or null if there is no header for the given name

getHeader

public <T> T getHeader(String name,
                       Object defaultValue,
                       Class<T> type)
Description copied from interface: Message
Returns a header associated with this message by name and specifying the type required

Parameters:
name - the name of the header
defaultValue - the default value to return if header was absent
type - the type of the header
Returns:
the value of the given header or defaultValue if there is no header for the given name or null if it cannot be converted to the given type

setHeader

public void setHeader(String name,
                      Object value)
Description copied from interface: Message
Sets a header on the message

Parameters:
name - of the header
value - to associate with the name

removeHeader

public Object removeHeader(String name)
Description copied from interface: Message
Removes the named header from this message

Parameters:
name - name of the header
Returns:
the old value of the header

removeHeaders

public boolean removeHeaders(String pattern)
Description copied from interface: Message
Removes the headers from this message

Parameters:
pattern - pattern of names
Returns:
boolean whether any headers matched

removeHeaders

public boolean removeHeaders(String pattern,
                             String... excludePatterns)
Description copied from interface: Message
Removes the headers from this message that match the given pattern, except for the ones matching one ore more excludePatterns

Parameters:
pattern - pattern of names that should be removed
excludePatterns - one or more pattern of header names that should be excluded (= preserved)
Returns:
boolean whether any headers matched

getHeaders

public Map<String,Object> getHeaders()
Description copied from interface: Message
Returns all of the headers associated with the message.

See 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.

Returns:
all the headers in a Map

setHeaders

public void setHeaders(Map<String,Object> headers)
Description copied from interface: Message
Set all the headers associated with this message

Parameters:
headers - headers to set

hasHeaders

public boolean hasHeaders()
Description copied from interface: Message
Returns whether has any headers has been set.

Returns:
true if any headers has been set

newInstance

public DefaultMessage newInstance()
Description copied from class: MessageSupport
Returns a new instance

Specified by:
newInstance in class MessageSupport

createHeaders

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

Returns:
return a newly constructed Map possibly containing headers from the underlying inbound transport

createAttachments

protected Map<String,DataHandler> createAttachments()
A factory method to lazily create the attachments to make it easy to create efficient Message implementations which only construct and populate the Map on demand

Returns:
return a newly constructed Map

populateInitialHeaders

protected void populateInitialHeaders(Map<String,Object> map)
A strategy method populate the initial set of headers on an inbound message from an underlying binding

Parameters:
map - is the empty header map to populate

populateInitialAttachments

protected void populateInitialAttachments(Map<String,DataHandler> map)
A strategy method populate the initial set of attachments on an inbound message from an underlying binding

Parameters:
map - is the empty attachment map to populate

isTransactedRedelivered

protected Boolean isTransactedRedelivered()
A strategy for component specific messages to determine whether the message is redelivered or not.

Important: It is not always possible to determine if the transacted is a redelivery or not, and therefore null is returned. Such an example would be a JDBC message. However JMS brokers provides details if a transacted message is redelivered.

Returns:
true if redelivered, false if not, null if not able to determine

addAttachment

public void addAttachment(String id,
                          DataHandler content)
Description copied from interface: Message
Adds an attachment to the message using the id

Parameters:
id - the id to store the attachment under
content - the data handler for the attachment

getAttachment

public DataHandler getAttachment(String id)
Description copied from interface: Message
Returns the attachment specified by the id

Parameters:
id - the id under which the attachment is stored
Returns:
the data handler for this attachment or null

getAttachmentNames

public Set<String> getAttachmentNames()
Description copied from interface: Message
Returns a set of attachment names of the message

Returns:
a set of attachment names

removeAttachment

public void removeAttachment(String id)
Description copied from interface: Message
Removes the attachment specified by the id

Parameters:
id - the id of the attachment to remove

getAttachments

public Map<String,DataHandler> getAttachments()
Description copied from interface: Message
Returns all attachments of the message

Returns:
the attachments in a map or null

setAttachments

public void setAttachments(Map<String,DataHandler> attachments)
Description copied from interface: Message
Set all the attachments associated with this message

Parameters:
attachments - the attachments

hasAttachments

public boolean hasAttachments()
Description copied from interface: Message
Returns whether this message has attachments.

Returns:
true if this message has any attachments.

hasPopulatedHeaders

protected boolean hasPopulatedHeaders()
Returns true if the headers have been mutated in some way


createExchangeId

public String createExchangeId()
Description copied from interface: Message
Returns the unique ID for a message exchange if this message is capable of creating one or null if not

Returns:
the created exchange id, or null if not capable of creating


Apache CAMEL