org.apache.camel
Interface Message

All Known Implementing Classes:
DefaultMessage, GenericFileMessage, HttpMessage, HttpMessage, IrcMessage, JmsMessage, MailMessage, MessageSupport, QuartzMessage, SmppMessage, SnmpMessage, SpringIntegrationMessage, XmppMessage

public interface Message

Implements the Message pattern and represents an inbound or outbound message as part of an Exchange.

See DefaultMessage for how headers is represented in Camel using a CaseInsensitiveMap.

Version:
$Revision: 19399 $

Method Summary
 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 copyFrom(Message message)
          Copies the contents of the other message into this message
 String createExchangeId()
          Returns the unique ID for a message exchange if this message is capable of creating one or null if not
 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
 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)
          Set all the headers associated with this message
 void setMessageId(String messageId)
          Sets the id of the message
 

Method Detail

getMessageId

String getMessageId()
Returns the id of the message

Returns:
the message id

setMessageId

void setMessageId(String messageId)
Sets the id of the message

Parameters:
messageId - id of the message

getExchange

Exchange getExchange()
Returns the exchange this message is related to

Returns:
the exchange

isFault

boolean isFault()
Returns true if this message represents a fault

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

setFault

void setFault(boolean fault)
Sets the fault flag on this message

Parameters:
fault - the fault flag

getHeader

Object getHeader(String name)
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

Object getHeader(String name,
                 Object defaultValue)
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

<T> T getHeader(String name,
                Class<T> type)
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 or null if it cannot be converted to the given type

getHeader

<T> T getHeader(String name,
                Object defaultValue,
                Class<T> type)
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

void setHeader(String name,
               Object value)
Sets a header on the message

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

removeHeader

Object removeHeader(String name)
Removes the named header from this message

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

removeHeaders

boolean removeHeaders(String pattern)
Removes the headers from this message

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

getHeaders

Map<String,Object> getHeaders()
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

void setHeaders(Map<String,Object> headers)
Set all the headers associated with this message

Parameters:
headers - headers to set

hasHeaders

boolean hasHeaders()
Returns whether has any headers has been set.

Returns:
true if any headers has been set

getBody

Object getBody()
Returns the body of the message as a POJO

The body can be null if no body is set

Returns:
the body, can be null

getMandatoryBody

Object getMandatoryBody()
                        throws InvalidPayloadException
Returns the body of the message as a POJO

Returns:
the body, is never null
Throws:
InvalidPayloadException - Is thrown if the body being null or wrong class type

getBody

<T> T getBody(Class<T> type)
Returns the body as the specified type

Parameters:
type - the type that the body
Returns:
the body of the message as the specified type, or null if not possible to convert

getMandatoryBody

<T> T getMandatoryBody(Class<T> type)
                   throws InvalidPayloadException
Returns the mandatory body as the specified type

Parameters:
type - the type that the body
Returns:
the body of the message as the specified type, is never null.
Throws:
InvalidPayloadException - Is thrown if the body being null or wrong class type

setBody

void setBody(Object body)
Sets the body of the message

Parameters:
body - the body

setBody

<T> void setBody(Object body,
                 Class<T> type)
Sets the body of the message as a specific type

Parameters:
body - the body
type - the type of the body

copy

Message copy()
Creates a copy of this message so that it can be used and possibly modified further in another exchange

Returns:
a new message instance copied from this message

copyFrom

void copyFrom(Message message)
Copies the contents of the other message into this message

Parameters:
message - the other message

getAttachment

DataHandler getAttachment(String id)
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

Set<String> getAttachmentNames()
Returns a set of attachment names of the message

Returns:
a set of attachment names

removeAttachment

void removeAttachment(String id)
Removes the attachment specified by the id

Parameters:
id - the id of the attachment to remove

addAttachment

void addAttachment(String id,
                   DataHandler content)
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

getAttachments

Map<String,DataHandler> getAttachments()
Returns all attachments of the message

Returns:
the attachments in a map or null

setAttachments

void setAttachments(Map<String,DataHandler> attachments)
Set all the attachments associated with this message

Parameters:
attachments - the attachments

hasAttachments

boolean hasAttachments()
Returns whether this message has attachments.

Returns:
true if this message has any attachments.

createExchangeId

String createExchangeId()
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


Copyright © 2007-2010 IONA Open Source Community. All Rights Reserved.