org.apache.servicemix.nmr.api
Interface Message

All Superinterfaces:
java.io.Serializable

public interface Message
extends java.io.Serializable

The Message represents the content of a request, a response or a fault. Messages are part of Exchanges are created using Exchange.getIn(), Exchange.getOut() and Exchange.getFault(). If the Exchange has to go to a remote ServiceMix instance to be processed (if the instance is part of a cluster), all headers, attachments and content have to be Serializable. TODO: security

Since:
4.0
Version:
$Revision: $

Method Summary
 void addAttachment(java.lang.String id, java.lang.Object value)
          Add an attachment to this message
 Message copy()
          Creates a copy of this message so that it can be used and possibly modified further in another exchange
 void copyFrom(Message msg)
          Copies the contents of the other message into this message
 java.lang.String display(boolean displayContent)
          Returns a string representation of this message.
 void ensureReReadable()
          Make sure that all streams contained in the content and in attachments are transformed to re-readable sources.
 java.lang.Object getAttachment(java.lang.String id)
          Retrieve an attachment given its id.
 java.util.Map<java.lang.String,java.lang.Object> getAttachments()
          Retrieve a map of all attachments
 java.lang.Object getBody()
          Returns the body of the message in its default format.
<T> T
getBody(java.lang.Class<T> type)
          Returns the body as the specified type.
 java.lang.String getContentEncoding()
          Get the encoding of the message
 java.lang.String getContentType()
          Get the mime content type describing the content of the message
<T> T
getHeader(java.lang.Class<T> type)
          Get a typed header.
 java.lang.Object getHeader(java.lang.String name)
          Get a header on this message.
<T> T
getHeader(java.lang.String name, java.lang.Class<T> type)
          Get a header, converting it to the desired type
 java.util.Map<java.lang.String,java.lang.Object> getHeaders()
          Get a map of all the headers for this message
 javax.security.auth.Subject getSecuritySubject()
          Get the security subject for this message
 void removeAttachment(java.lang.String id)
          Remove an attachment on this message
<T> T
removeHeader(java.lang.Class<T> type)
          Remove the header of the specified type
 java.lang.Object removeHeader(java.lang.String name)
          Remove the given header and returns its value.
 void setBody(java.lang.Object body)
          Set the body of the message.
<T> void
setBody(java.lang.Object body, java.lang.Class<T> type)
          Set the body of the message.
 void setContentEncoding(java.lang.String encoding)
          Set the encoding of the message
 void setContentType(java.lang.String type)
          Set the mime content type describing the content of the message
<T> void
setHeader(java.lang.Class<T> type, T value)
          Set a typed header for this message.
 void setHeader(java.lang.String name, java.lang.Object value)
          Set a header for this message
 void setHeaders(java.util.Map<java.lang.String,java.lang.Object> headers)
          Set all the headers
 void setSecuritySubject(javax.security.auth.Subject securitySubject)
          Set the security subject for this message
 

Method Detail

getHeader

java.lang.Object getHeader(java.lang.String name)
Get a header on this message.

Parameters:
name - the name of the header
Returns:
the value of the header of null if none has been set

getHeader

<T> T getHeader(java.lang.Class<T> type)
Get a typed header. This is equivalent to: exchange.getHeader(type.getName())

Parameters:
type - the type of the header
Returns:
the header

getHeader

<T> T getHeader(java.lang.String name,
                java.lang.Class<T> type)
Get a header, converting it to the desired type

Parameters:
name - the name of the header
type - the desired type
Returns:
the converted header or null if no header has been set or if it can not be transformed to the desired type

setHeader

void setHeader(java.lang.String name,
               java.lang.Object value)
Set a header for this message

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

setHeader

<T> void setHeader(java.lang.Class<T> type,
                   T value)
Set a typed header for this message. This is equivalent to: exchange.setHeader(type.getName(), value)

Parameters:
type - the type of the header
value - the value of the header

removeHeader

java.lang.Object removeHeader(java.lang.String name)
Remove the given header and returns its value.

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

removeHeader

<T> T removeHeader(java.lang.Class<T> type)
Remove the header of the specified type

Parameters:
type - the type of the header
Returns:
the previous value

getHeaders

java.util.Map<java.lang.String,java.lang.Object> getHeaders()
Get a map of all the headers for this message

Returns:
a map of headers

setHeaders

void setHeaders(java.util.Map<java.lang.String,java.lang.Object> headers)
Set all the headers

Parameters:
headers - the new map of headers

getAttachment

java.lang.Object getAttachment(java.lang.String id)
Retrieve an attachment given its id.

Parameters:
id - the id of the attachment to retrieve
Returns:
the attachement or null if none exists

addAttachment

void addAttachment(java.lang.String id,
                   java.lang.Object value)
Add an attachment to this message

Parameters:
id - the id of the attachment
value - the attachment to add

removeAttachment

void removeAttachment(java.lang.String id)
Remove an attachment on this message

Parameters:
id - the id of the attachment to remove

getAttachments

java.util.Map<java.lang.String,java.lang.Object> getAttachments()
Retrieve a map of all attachments

Returns:
the map of attachments

getBody

java.lang.Object getBody()
Returns the body of the message in its default format.

Returns:
the servicemix body of this message

getBody

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

Parameters:
type - the type in which the body is to be transformed
Returns:
the transformed body

setBody

void setBody(java.lang.Object body)
Set the body of the message.

Parameters:
body - the body of the message

setBody

<T> void setBody(java.lang.Object body,
                 java.lang.Class<T> type)
Set the body of the message.

Parameters:
body - the body of the message

getContentType

java.lang.String getContentType()
Get the mime content type describing the content of the message

Returns:
the mime content type

setContentType

void setContentType(java.lang.String type)
Set the mime content type describing the content of the message

Parameters:
type - the mime content type

getContentEncoding

java.lang.String getContentEncoding()
Get the encoding of the message

Returns:
the encoding

setContentEncoding

void setContentEncoding(java.lang.String encoding)
Set the encoding of the message

Parameters:
encoding - the encoding

getSecuritySubject

javax.security.auth.Subject getSecuritySubject()
Get the security subject for this message

Returns:
the security subject

setSecuritySubject

void setSecuritySubject(javax.security.auth.Subject securitySubject)
Set the security subject for this message

Parameters:
securitySubject - the security subject

copyFrom

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

Parameters:
msg - the message to copy from

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

ensureReReadable

void ensureReReadable()
Make sure that all streams contained in the content and in attachments are transformed to re-readable sources. This method will be called by the framework when persisting the message or when displaying it.


display

java.lang.String display(boolean displayContent)
Returns a string representation of this message. The displayContent property can be specified to control wether the content should be displayed or not. If set to true, the content and attachments will be converted into re-readable objects (for java.io.InputStream and javax.xml.transform.Source objects) and printed.

Parameters:
displayContent - if the content and attachments of the exchange should be transformed if needed and displayed or left unmodified
Returns:
the string representation


Copyright © 2005-2009 The Apache Software Foundation. All Rights Reserved.