Class EmbeddedHeaderUtils


  • public abstract class EmbeddedHeaderUtils
    extends Object
    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 Detail

      • EmbeddedHeaderUtils

        public EmbeddedHeaderUtils()
    • Method Detail

      • decodeExceptionMessage

        public static String decodeExceptionMessage​(org.springframework.messaging.Message<?> requestMessage)
      • embedHeaders

        public static byte[] embedHeaders​(MessageValues original,
                                          String... headers)
        Return a new message where some of the original headers of original have been embedded into the new message payload.
        Parameters:
        original - original message
        headers - 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 headers
        copyRequestHeaders - boolean value to specify if the request headers should be copied
        Returns:
        wrapped message values
        Throws:
        Exception - when extraction failed
      • extractHeaders

        public static MessageValues extractHeaders​(byte[] payload)
                                            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:
        payload - the message payload
        Returns:
        the message with extracted headers
        Throws:
        Exception - when extraction failed
      • headersToEmbed

        public static String[] headersToEmbed​(String[] configuredHeaders)
      • 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.