An instance of org.apache.camel.Message
type can represent any kind of
message (In, Out, or Fault).
Figure 10.1 shows the inheritance hierarchy for
the message type. You do not always need to implement a custom message type for a component.
In many cases, the default implementation, DefaultMessage
, is adequate.
Example 10.1 shows the definition of the
org.apache.camel.Message
interface.
Example 10.1. Message Interface
package org.apache.camel; import java.util.Map; import java.util.Set; import javax.activation.DataHandler; public interface Message { String getMessageId(); void setMessageId(String messageId); Exchange getExchange(); Object getHeader(String name); <T> T getHeader(String name, Class<T> type); void setHeader(String name, Object value); Object removeHeader(String name); Map<String, Object> getHeaders(); void setHeaders(Map<String, Object> headers); Object getBody(); <T> T getBody(Class<T> type); void setBody(Object body); <T> void setBody(Object body, Class<T> type); DataHandler getAttachment(String id); Map<String, DataHandler> getAttachments(); Set<String> getAttachmentNames(); void removeAttachment(String id); void addAttachment(String id, DataHandler content); void setAttachments(Map<String, DataHandler> attachments); boolean hasAttachments(); Message copy(); void copyFrom(Message message); }
The Message
interface defines the following methods:
setMessageId()
, getMessageId()
—Getter and setter
methods for the message ID. Whether or not you need to
use a message ID in your custom component is an implementation detail.
getExchange()
—Returns a reference to the parent exchange
object.
getHeader()
, getHeaders()
, setHeader()
,
setHeaders()
, removeHeader()
—Getter and setter methods
for the message headers. In general, these message headers can be used either to store
actual header data, or to store miscellaneous metadata.
getBody()
, setBody()
—Getter and setter methods for
the message body.
getAttachment()
, getAttachments()
,
getAttachmentNames()
, removeAttachment()
,
addAttachment()
, setAttachments()
,
hasAttachments()
—Methods to get, set, add, and remove
attachments.
copy()
—Creates a new, identical (including the message ID) copy of
the current custom message object.
copyFrom()
—Copies the complete contents (including the message ID)
of the specified generic message object, message
, into the current message
instance. Because this method must be able to copy from any
message type, it copies the generic message properties, but not the custom properties.