NativeMessageHeaderAccessor

An extension of {@link MessageHeaderAccessor} that also stores and provides read/write access to message headers from an external source -- e.g. a Spring {@link Message} created to represent a STOMP message received from a STOMP client or message broker. Native message headers are kept in a {@code MultiStringsMap} under the key {@link #NATIVE_HEADERS}.

<p>This class is not intended for direct use but is rather expected to be used indirectly through protocol-specific sub-classes such as {@link hunt.stomp.simp.stomp.StompHeaderAccessor StompHeaderAccessor}. Such sub-classes may provide factory methods to translate message headers from an external messaging source (e.g. STOMP) to Spring {@link Message} headers and reversely to translate Spring {@link Message} headers to a message to send to an external source.

@author Rossen Stoyanchev @since 4.0

Constructors

this
this()

A protected constructor to create new headers.

this
this(MultiStringsMap nativeHeaders)

A protected constructor to create new headers. @param nativeHeaders native headers to create the message with (may be {@code null})

this
this(MessageBase message)

A protected constructor accepting the headers of an existing message to copy.

Members

Functions

addNativeHeader
void addNativeHeader(string name, string value)

Add the specified native header value to existing values.

addNativeHeaders
void addNativeHeaders(MultiValueMap!(string, string) headers)
Undocumented in source. Be warned that the author may not have intended to support it.
containsNativeHeader
bool containsNativeHeader(string headerName)

Whether the native header map contains the give header name.

getFirstNativeHeader
string getFirstNativeHeader(string headerName)

Return the first value for the specified native header, or {@code null} if none.

getNativeHeader
List!(string) getNativeHeader(string headerName)

Return all values for the specified native header. or {@code null} if none.

getNativeHeaders
MultiStringsMap getNativeHeaders()
Undocumented in source. Be warned that the author may not have intended to support it.
removeNativeHeader
List!(string) removeNativeHeader(string name)
Undocumented in source. Be warned that the author may not have intended to support it.
setImmutable
void setImmutable()
Undocumented in source. Be warned that the author may not have intended to support it.
setNativeHeader
void setNativeHeader(string name, string value)

Set the specified native header value replacing existing values.

toNativeHeaderMap
MultiStringsMap toNativeHeaderMap()

Return a copy of the native header values or an empty map.

Static functions

getFirstNativeHeader
string getFirstNativeHeader(string headerName, Map!(string, Object) headers)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

NATIVE_HEADERS
enum string NATIVE_HEADERS;

The header name used to store native headers.

Inherited Members

From MessageHeaderAccessor

DEFAULT_CHARSET
enum Charset DEFAULT_CHARSET;

The default charset used for headers.

createAccessor
MessageHeaderAccessor createAccessor(MessageBase message)

Build a 'nested' accessor for the given message. @param message the message to build a new accessor for @return the nested accessor (typically a specific subclass)

setLeaveMutable
void setLeaveMutable(bool leaveMutable)

By default when {@link #getMessageHeaders()} is called, {@code "this"} {@code MessageHeaderAccessor} instance can no longer be used to modify the underlying message headers and the returned {@code MessageHeaders} is immutable. <p>However when this is set to {@code true}, the returned (underlying) {@code MessageHeaders} instance remains mutable. To make further modifications continue to use the same accessor instance or re-obtain it via:<br> {@link MessageHeaderAccessor#getAccessor(Message, Class) MessageHeaderAccessor.getAccessor(Message, Class)} <p>When modifications are complete use {@link #setImmutable()} to prevent further changes. The intended use case for this mechanism is initialization of a Message within a single thread. <p>By default this is set to {@code false}. @since 4.1

setImmutable
void setImmutable()

By default when {@link #getMessageHeaders()} is called, {@code "this"} {@code MessageHeaderAccessor} instance can no longer be used to modify the underlying message headers. However if {@link #setLeaveMutable()} is used, this method is necessary to indicate explicitly when the {@code MessageHeaders} instance should no longer be modified. @since 4.1

isMutable
bool isMutable()

Whether the underlying headers can still be modified. @since 4.1

setModified
void setModified(bool modified)

Mark the underlying message headers as modified. @param modified typically {@code true}, or {@code false} to reset the flag @since 4.1

isModified
bool isModified()

Check whether the underlying message headers have been marked as modified. @return {@code true} if the flag has been set, {@code false} otherwise

setEnableTimestamp
void setEnableTimestamp(bool enableTimestamp)

A package private mechanism to enables the automatic addition of the {@link hunt.stomp.MessageHeaders#TIMESTAMP} header. <p>By default, this property is set to {@code false}. @see IdTimestampMessageHeaderInitializer

setIdGenerator
void setIdGenerator(IdGenerator idGenerator)

A package-private mechanism to configure the IdGenerator strategy to use. <p>By default this property is not set in which case the default IdGenerator in {@link hunt.stomp.MessageHeaders} is used. @see IdTimestampMessageHeaderInitializer

getMessageHeaders
MessageHeaders getMessageHeaders()

Return the underlying {@code MessageHeaders} instance. <p>Unless {@link #setLeaveMutable()} was set to {@code true}, after this call, the headers are immutable and this accessor can no longer modify them. <p>This method always returns the same {@code MessageHeaders} instance if invoked multiples times. To obtain a copy of the underlying headers, use {@link #toMessageHeaders()} or {@link #toMap()} instead. @since 4.1

toMessageHeaders
MessageHeaders toMessageHeaders()

Return a copy of the underlying header values as a {@link MessageHeaders} object. <p>This method can be invoked many times, with modifications in between where each new call returns a fresh copy of the current header values. @since 4.1

toMap
Map!(string, Object) toMap()

Return a copy of the underlying header values as a plain {@link Map} object. <p>This method can be invoked many times, with modifications in between where each new call returns a fresh copy of the current header values.

getHeader
Object getHeader(string headerName)

Retrieve the value for the header with the given name. @param headerName the name of the header @return the associated value, or {@code null} if none found

getHeaderAs
T getHeaderAs(string headerName)
Undocumented in source. Be warned that the author may not have intended to support it.
setHeader
void setHeader(string name, T value)
Undocumented in source. Be warned that the author may not have intended to support it.
setHeader
void setHeader(string name, Object value)

Set the value for the given header name. <p>If the provided value is {@code null}, the header will be removed.

verifyType
void verifyType(string headerName, Object headerValue)
Undocumented in source. Be warned that the author may not have intended to support it.
setHeaderIfAbsent
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.

removeHeader
void removeHeader(string headerName)

Remove the value for the given header name.

removeHeaders
void removeHeaders(string[] headerPatterns)

Removes all headers provided via array of 'headerPatterns'. <p>As the name suggests, array may contain simple matching patterns for header names. Supported pattern styles are: "xxx*", "*xxx", "*xxx*" and "xxx*yyy".

copyHeaders
void copyHeaders(Map!(string, Object) headersToCopy)

Copy the name-value pairs from the provided Map. <p>This operation will overwrite any existing values. Use {@link #copyHeadersIfAbsent(Map)} to avoid overwriting values.

copyHeadersIfAbsent
void copyHeadersIfAbsent(Map!(string, Object) headersToCopy)

Copy the name-value pairs from the provided Map. <p>This operation will <em>not</em> overwrite any existing values.

isReadOnly
bool isReadOnly(string headerName)
Undocumented in source. Be warned that the author may not have intended to support it.
getId
UUID getId()
Undocumented in source. Be warned that the author may not have intended to support it.
getTimestamp
Long getTimestamp()
Undocumented in source. Be warned that the author may not have intended to support it.
setContentType
void setContentType(MimeType contentType)
Undocumented in source. Be warned that the author may not have intended to support it.
getContentType
MimeType getContentType()
Undocumented in source. Be warned that the author may not have intended to support it.
setReplyChannelName
void setReplyChannelName(string replyChannelName)
Undocumented in source. Be warned that the author may not have intended to support it.
setReplyChannel
void setReplyChannel(MessageChannel replyChannel)
Undocumented in source. Be warned that the author may not have intended to support it.
getReplyChannel
Object getReplyChannel()
Undocumented in source. Be warned that the author may not have intended to support it.
setErrorChannelName
void setErrorChannelName(string errorChannelName)
Undocumented in source. Be warned that the author may not have intended to support it.
setErrorChannel
void setErrorChannel(MessageChannel errorChannel)
Undocumented in source. Be warned that the author may not have intended to support it.
getErrorChannel
Object getErrorChannel()
Undocumented in source. Be warned that the author may not have intended to support it.
getShortLogMessage
string getShortLogMessage(Object payload)

Return a concise message for logging purposes. @param payload the payload that corresponds to the headers. @return the message

getDetailedLogMessage
string getDetailedLogMessage(Object payload)

Return a more detailed message for logging purposes. @param payload the payload that corresponds to the headers. @return the message

getShortPayloadLogMessage
string getShortPayloadLogMessage(Object payload)
Undocumented in source. Be warned that the author may not have intended to support it.
getDetailedPayloadLogMessage
string getDetailedPayloadLogMessage(Object payload)
Undocumented in source. Be warned that the author may not have intended to support it.
isReadableContentType
bool isReadableContentType()
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.
getAccessor
T getAccessor(MessageBase message)

Return the original {@code MessageHeaderAccessor} used to create the headers of the given {@code Message}, or {@code null} if that's not available or if its type does not match the required type. <p>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. @param message the message to get an accessor for @param requiredType the required accessor type (or {@code null} for any) @return an accessor instance of the specified type, or {@code null} if none @since 4.1

getAccessor
T getAccessor(MessageHeaders messageHeaders)

A variation of {@link #getAccessor(hunt.stomp.Message, Class)} with a {@code MessageHeaders} instance instead of a {@code Message}. <p>This is for cases when a full message may not have been created yet. @param messageHeaders the message headers to get an accessor for @param requiredType the required accessor type (or {@code null} for any) @return an accessor instance of the specified type, or {@code null} if none @since 4.1

getMutableAccessor
MessageHeaderAccessor getMutableAccessor(MessageBase message)

Return a mutable {@code MessageHeaderAccessor} for the given message attempting to match the type of accessor used to create the message headers, or otherwise wrapping the message with a {@code MessageHeaderAccessor} instance. <p>This is for cases where a header needs to be updated in generic code while preserving the accessor type for downstream processing. @return an accessor of the required type (never {@code null}) @since 4.1

Meta