Example 10.2 outlines how to implement a message by
extending the DefaultMessage
class.
Example 10.2. Custom Message Implementation
import org.apache.camel.Exchange; import org.apache.camel.impl.DefaultMessage; public classCustomMessage
extends DefaultMessage {public
CustomMessage
() {// Create message with default properties... } @Override public String toString() {
// Return a stringified message... } public
CustomExchange
getExchange() {return (
CustomExchange
)super.getExchange(); } @Override publicCustomMessage
newInstance() {return new
CustomMessage
( ... ); } @Override protected Object createBody() {// Return message body (lazy creation). } @Override protected void populateInitialHeaders(Map<String, Object> map) {
// Initialize headers from underlying message (lazy creation). } @Override protected void populateInitialAttachments(Map<String, DataHandler> map) {
// Initialize attachments from underlying message (lazy creation). } }
Implements a custom message class, | |
Typically, you need a default constructor that creates a message with default properties. | |
Override the | |
(Optional) This is a convenient method that returns a reference to the parent exchange instance, casts it to the correct type. | |
The | |
The | |
The | |
The |