MessageHeaders that provides extra features such as
strongly typed accessors for specific headers, the ability to leave headers
in a Message mutable, and the option to suppress automatic generation
of id and timestamp headers. Subclasses such as NativeMessageHeaderAccessor
and others provide support for managing processing vs external source headers
as well as protocol specific headers.
Below is a workflow to initialize headers via MessageHeaderAccessor,
or one of its subclasses, then create a Message, and then re-obtain
the accessor possibly from a different component:
// Create a message with headers
MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("foo", "bar");
MessageHeaders headers = accessor.getMessageHeaders();
Message message = MessageBuilder.createMessage("payload", headers);
// Later on
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message);
Assert.notNull(accessor, "No MessageHeaderAccessor");
In order for the above to work, all participating components must use
MessageHeaders to create, access, or modify headers, or otherwise
MessageHeaderAccessor#getAccessor(Message, Class) will return null.
Below is a workflow that shows how headers are created and left mutable,
then modified possibly by a different component, and finally made immutable
perhaps before the possibility of being accessed on a different thread:
// Create a message with mutable headers
MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("foo", "bar");
accessor.setLeaveMutable(true);
MessageHeaders headers = accessor.getMessageHeaders();
Message message = MessageBuilder.createMessage("payload", headers);
// Later on
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message);
if (accessor.isMutable()) {
// It's mutable, just change the headers
accessor.setHeader("bar", "baz");
}
else {
// It's not, so get a mutable copy, change and re-create
accessor = MessageHeaderAccessor.getMutableAccessor(message);
accessor.setHeader("bar", "baz");
accessor.setLeaveMutable(true); // leave mutable again or not?
message = MessageBuilder.createMessage(message.getPayload(), accessor);
}
// Make the accessor immutable
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message);
accessor.setImmutable();
| Modifier and Type | Class and Description |
|---|---|
| private class | MessageHeaderAccessor.MutableMessageHeaders
Extension of |
| Modifier and Type | Field and Description |
|---|---|
| public static final Charset | DEFAULT_CHARSET
The default charset used for headers. |
| private boolean | |
| private final MessageHeaderAccessor. | |
| private IdGenerator | |
| private boolean | |
| private boolean | |
| private static final MimeType[] |
| Access | Constructor and Description |
|---|---|
| public | |
| public | MessageHeaderAccessor(Message<?>
a message to copy the headers from, or message)null if noneA constructor accepting the headers of an existing message to copy. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| protected MessageHeaderAccessor | Returns: the nested accessor (typically a specific subclass)the message to build a new accessor for message)Build a 'nested' accessor for the given message. |
| public static MessageHeaderAccessor | Returns: an accessor instance of the specified type, ornull if nonethe message to get an accessor for message)Return the original |
| public static <T extends MessageHeaderAccessor> T | Returns: an accessor instance of the specified type, ornull if nonethe message to get an accessor for message, Class<T> the required accessor type (or requiredType)null for any)Return the original |
| public static <T extends MessageHeaderAccessor> T | Returns: an accessor instance of the specified type, ornull if nonethe message headers to get an accessor for messageHeaders, Class<T> the required accessor type (or requiredType)null for any)A variation of |
| private Charset | |
| public MimeType | |
| public String | Returns: the messagethe payload that corresponds to the headers. payload)Return a more detailed message for logging purposes. |
| protected String | |
| public Object | |
| public Object | |
| public UUID | |
| private List | |
| public MessageHeaders | |
| public static MessageHeaderAccessor | Returns: an accessor of the required type (nevernull)Return a mutable |
| public Object | |
| public String | Returns: the messagethe payload that corresponds to the headers. payload)Return a concise message for logging purposes. |
| protected String | |
| public Long | |
| public boolean | Returns: true if the flag has been set, false otherwiseCheck whether the underlying message headers have been marked as modified. |
| public boolean | |
| protected boolean | |
| protected boolean | |
| public void | |
| public void | |
| public void | |
| pack-priv void | setEnableTimestamp(boolean enableTimestamp)
A package private mechanism to enables the automatic addition of the
|
| public void | |
| public void | |
| public void | |
| public void | setHeaderIfAbsent(String name, Object value)
Set the value for the given header name only if the header name is not already associated with a value. |
| pack-priv void | setIdGenerator(IdGenerator idGenerator)
A package-private mechanism to configure the IdGenerator strategy to use. |
| public void | setImmutable()
By default, when |
| public void | setLeaveMutable(boolean leaveMutable)
By default, when |
| protected void | setModified(boolean
typically modified)true, or false to reset the flagMark the underlying message headers as modified. |
| public void | |
| public void | |
| public Map | |
| public MessageHeaders | |
| public String | |
| protected void |
| DEFAULT_CHARSET | back to summary |
|---|---|
| public static final Charset DEFAULT_CHARSET The default charset used for headers. | |
| enableTimestamp | back to summary |
|---|---|
| private boolean enableTimestamp | |
| headers | back to summary |
|---|---|
| private final MessageHeaderAccessor. | |
| idGenerator | back to summary |
|---|---|
| private IdGenerator idGenerator
| |
| leaveMutable | back to summary |
|---|---|
| private boolean leaveMutable | |
| modified | back to summary |
|---|---|
| private boolean modified | |
| READABLE_MIME_TYPES | back to summary |
|---|---|
| private static final MimeType[] READABLE_MIME_TYPES | |
| MessageHeaderAccessor | back to summary |
|---|---|
| public MessageHeaderAccessor() A constructor to create new headers. | |
| MessageHeaderAccessor | back to summary |
|---|---|
| public MessageHeaderAccessor(Message<?> message) A constructor accepting the headers of an existing message to copy.
| |
| copyHeaders | back to summary |
|---|---|
| public void copyHeaders(Map<String, ?> headersToCopy) Copy the name-value pairs from the provided Map. This operation will overwrite any existing values. Use
| |
| copyHeadersIfAbsent | back to summary |
|---|---|
| public void copyHeadersIfAbsent(Map<String, ?> headersToCopy) Copy the name-value pairs from the provided Map. This operation will not overwrite any existing values. | |
| createAccessor | back to summary |
|---|---|
| protected MessageHeaderAccessor createAccessor(Message<?> message) Build a 'nested' accessor for the given message.
| |
| getAccessor | back to summary |
|---|---|
| public static MessageHeaderAccessor getAccessor(Message<?> message) Return the original This is for cases where the existence of an accessor is strongly expected (followed up with an assertion) or where an accessor will be created otherwise.
| |
| getAccessor | back to summary |
|---|---|
| public static <T extends MessageHeaderAccessor> T getAccessor(Message<?> message, Class<T> requiredType) Return the original This is for cases where the existence of an accessor is strongly expected (followed up with an assertion) or where an accessor will be created otherwise. | |
| getAccessor | back to summary |
|---|---|
| public static <T extends MessageHeaderAccessor> T getAccessor(MessageHeaders messageHeaders, Class<T> requiredType) A variation of This is for cases when a full message may not have been created yet.
| |
| getCharset | back to summary |
|---|---|
| private Charset getCharset() | |
| getContentType | back to summary |
|---|---|
public MimeType getContentType()
| |
| getDetailedLogMessage | back to summary |
|---|---|
| public String getDetailedLogMessage(Object payload) Return a more detailed message for logging purposes. | |
| getDetailedPayloadLogMessage | back to summary |
|---|---|
| protected String getDetailedPayloadLogMessage(Object payload) | |
| getErrorChannel | back to summary |
|---|---|
public Object getErrorChannel()
| |
| getHeader | back to summary |
|---|---|
| public Object getHeader(String headerName) Retrieve the value for the header with the given name. | |
| getId | back to summary |
|---|---|
public UUID getId()
| |
| getMatchingHeaderNames | back to summary |
|---|---|
| private List | |
| getMessageHeaders | back to summary |
|---|---|
| public MessageHeaders getMessageHeaders() Return the underlying Unless This method always returns the same
| |
| getMutableAccessor | back to summary |
|---|---|
| public static MessageHeaderAccessor getMutableAccessor(Message<?> message) Return a mutable This is for cases where a header needs to be updated in generic code while preserving the accessor type for downstream processing.
| |
| getReplyChannel | back to summary |
|---|---|
public Object getReplyChannel()
| |
| getShortLogMessage | back to summary |
|---|---|
| public String getShortLogMessage(Object payload) Return a concise message for logging purposes. | |
| getShortPayloadLogMessage | back to summary |
|---|---|
| protected String getShortPayloadLogMessage(Object payload) | |
| getTimestamp | back to summary |
|---|---|
public Long getTimestamp()
| |
| isModified | back to summary |
|---|---|
| public boolean isModified() Check whether the underlying message headers have been marked as modified.
| |
| isMutable | back to summary |
|---|---|
| public boolean isMutable() Whether the underlying headers can still be modified.
| |
| isReadableContentType | back to summary |
|---|---|
| protected boolean isReadableContentType() | |
| isReadOnly | back to summary |
|---|---|
| protected boolean isReadOnly(String headerName) | |
| removeHeader | back to summary |
|---|---|
| public void removeHeader(String headerName) Remove the value for the given header name. | |
| removeHeaders | back to summary |
|---|---|
| public void removeHeaders(String... headerPatterns) Removes all headers provided via array of 'headerPatterns'. As the name suggests, array may contain simple matching patterns for header names. Supported pattern styles are: "xxx*", "*xxx", "*xxx*" and "xxx*yyy". | |
| setContentType | back to summary |
|---|---|
| public void setContentType(MimeType contentType) | |
| setEnableTimestamp | back to summary |
|---|---|
| pack-priv void setEnableTimestamp(boolean enableTimestamp) A package private mechanism to enables the automatic addition of the
By default, this property is set to
| |
| setErrorChannel | back to summary |
|---|---|
| public void setErrorChannel(MessageChannel errorChannel) | |
| setErrorChannelName | back to summary |
|---|---|
| public void setErrorChannelName(String errorChannelName) | |
| setHeader | back to summary |
|---|---|
| public void setHeader(String name, Object value) Set the value for the given header name. If the provided value is | |
| setHeaderIfAbsent | back to summary |
|---|---|
| public void setHeaderIfAbsent(String name, Object value) Set the value for the given header name only if the header name is not already associated with a value. | |
| setIdGenerator | back to summary |
|---|---|
| pack-priv void setIdGenerator(IdGenerator idGenerator) A package-private mechanism to configure the IdGenerator strategy to use. By default this property is not set in which case the default IdGenerator
in
| |
| setImmutable | back to summary |
|---|---|
| public void setImmutable() By default, when
| |
| setLeaveMutable | back to summary |
|---|---|
| public void setLeaveMutable(boolean leaveMutable) By default, when However when this is set to When modifications are complete use By default this is set to
| |
| setModified | back to summary |
|---|---|
| protected void setModified(boolean modified) Mark the underlying message headers as modified.
| |
| setReplyChannel | back to summary |
|---|---|
| public void setReplyChannel(MessageChannel replyChannel) | |
| setReplyChannelName | back to summary |
|---|---|
| public void setReplyChannelName(String replyChannelName) | |
| toMap | back to summary |
|---|---|
| public Map Return a copy of the underlying header values as a plain This method can be invoked many times, with modifications in between where each new call returns a fresh copy of the current header values. | |
| toMessageHeaders | back to summary |
|---|---|
| public MessageHeaders toMessageHeaders() Return a copy of the underlying header values as a This method can be invoked many times, with modifications in between where each new call returns a fresh copy of the current header values.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| verifyType | back to summary |
|---|---|
| protected void verifyType(String headerName, Object headerValue) | |
MessageHeaders that helps to preserve the link to
the outer MessageHeaderAccessor instance that created it as well
as keeps track of whether headers are still mutable.
| Modifier and Type | Field and Description |
|---|---|
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public MessageHeaderAccessor | |
| public Map | |
| public boolean | |
| public void | |
| protected Object |
| mutable | back to summary |
|---|---|
| private boolean mutable | |
| MutableMessageHeaders | back to summary |
|---|---|
| public MutableMessageHeaders(Map<String, Object> headers) | |
| getAccessor | back to summary |
|---|---|
| public MessageHeaderAccessor getAccessor() | |
| getRawHeaders | back to summary |
|---|---|
| public Map Overrides org.
| |
| isMutable | back to summary |
|---|---|
| public boolean isMutable() | |
| setImmutable | back to summary |
|---|---|
| public void setImmutable() | |
| writeReplace | back to summary |
|---|---|
| protected Object writeReplace() | |