Class EmbeddedHeaderUtils
java.lang.Object
org.springframework.cloud.stream.binder.EmbeddedHeaderUtils
Encodes requested headers into payload with format
0xff, n(1), [ [lenHdr(1), hdr, lenValue(4), value] ... ]. The 0xff indicates
this new format; n is number of headers (max 255); for each header, the name length (1
byte) is followed by the name, followed by the value length (int) followed by the value
(json).
Previously, there was no leading 0xff; the value length was 1 byte and only String header values were supported (no JSON conversion).
- Since:
- 1.2
- Author:
- Eric Bottard, Gary Russell, Ilayaperumal Gopinathan, Marius Bogoevici
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringdecodeExceptionMessage(org.springframework.messaging.Message<?> requestMessage) static byte[]embedHeaders(MessageValues original, String... headers) Return a new message where some of the original headers oforiginalhave been embedded into the new message payload.static MessageValuesextractHeaders(byte[] payload) Return a message where headers, that were originally embedded into the payload, have been promoted back to actual headers.static MessageValuesextractHeaders(org.springframework.messaging.Message<byte[]> message, boolean copyRequestHeaders) Return a message where headers, that were originally embedded into the payload, have been promoted back to actual headers.static String[]headersToEmbed(String[] configuredHeaders) static booleanmayHaveEmbeddedHeaders(byte[] bytes) Return true if the bytes might have embedded headers.
-
Constructor Details
-
EmbeddedHeaderUtils
public EmbeddedHeaderUtils()
-
-
Method Details
-
decodeExceptionMessage
public static String decodeExceptionMessage(org.springframework.messaging.Message<?> requestMessage) -
embedHeaders
Return a new message where some of the original headers oforiginalhave been embedded into the new message payload.- Parameters:
original- original messageheaders- headers to embedd- Returns:
- a new message
-
extractHeaders
public static MessageValues extractHeaders(org.springframework.messaging.Message<byte[]> message, boolean copyRequestHeaders) throws Exception Return a message where headers, that were originally embedded into the payload, have been promoted back to actual headers. The new payload is now the original payload.- Parameters:
message- the message to extract headerscopyRequestHeaders- boolean value to specify if the request headers should be copied- Returns:
- wrapped message values
- Throws:
Exception- when extraction failed
-
extractHeaders
Return a message where headers, that were originally embedded into the payload, have been promoted back to actual headers. The new payload is now the original payload.- Parameters:
payload- the message payload- Returns:
- the message with extracted headers
- Throws:
Exception- when extraction failed
-
headersToEmbed
-
mayHaveEmbeddedHeaders
public static boolean mayHaveEmbeddedHeaders(byte[] bytes) Return true if the bytes might have embedded headers. (First byte is 0xff and long enough for at least one header).- Parameters:
bytes- the array.- Returns:
- true if it may have embedded headers.
-