Class Frame


  • public class Frame
    extends Object
    Represents a STOMP frame. STOMP frames are structured as follows. It starts by a command, followed by a set of headers. Then the frame may have a body and is finished by a 0 byte. This class represents this structure and provide access to the different parts.

    This class is NOT thread-safe.

    Author:
    Clement Escoffier
    • Constructor Detail

      • Frame

        public Frame()
        Creates an un-configured frame. Should only be used by converters.
      • Frame

        public Frame​(Frame other)
        Creates a new instance of Frame by copying the values from the other frame. The body of the frame is copied.
        Parameters:
        other - the frame to copy.
      • Frame

        public Frame​(JsonObject json)
        Creates a new instance of Frame from its JSON representation.
        Parameters:
        json - the json form of the frame
      • Frame

        public Frame​(Command command,
                     Map<String,​String> headers,
                     Buffer body)
        Creates a new instance of Frame.
        Parameters:
        command - the command, must not be null
        headers - the headers, must not be null
        body - the body
    • Method Detail

      • addHeader

        public Frame addHeader​(String key,
                               String value)
        Adds a header to the frame.
        Parameters:
        key - the header name
        value - the header value
        Returns:
        the current Frame
      • getAck

        public String getAck()
        Gets the value of the ack header.
        Returns:
        the ack header value, null if not set
      • getHeaders

        public Map<String,​String> getHeaders()
        Gets the frame headers. Modifications to the returned Map modifies the headers of the frame.
        Returns:
        the headers
      • setHeaders

        public Frame setHeaders​(Map<String,​String> headers)
        Sets the headers of the frames.
        Parameters:
        headers - the header, may be null. In the null case, an empty map is used to store the frame headers.
        Returns:
        the current Frame
      • setCommand

        public Frame setCommand​(Command command)
        Sets the frame command.
        Parameters:
        command - the command, must not be null
        Returns:
        the current Frame
      • setBody

        public Frame setBody​(Buffer body)
        Sets the body of the frame.
        Parameters:
        body - the body
        Returns:
        the current Frame
      • toJson

        public JsonObject toJson()
        Returns:
        the JSON representation of the current frame.
      • validate

        public void validate()
        Checks the validity of the frame. Frames must have a valid command, and not all frames can have a body.
      • hasEmptyBody

        public boolean hasEmptyBody()
        Returns:
        whether or not the frame has a body.
      • getCommand

        public Command getCommand()
      • getHeader

        public String getHeader​(String name)
        Gets the value of the header with the given name.
        Parameters:
        name - the header name
        Returns:
        the value, null if not set
      • getBody

        public Buffer getBody()
      • getBodyAsString

        public String getBodyAsString​(String encoding)
        Gets the body of the frames as a String encoded in the given encoding.
        Parameters:
        encoding - the encoding
        Returns:
        the body, null if none
      • getBodyAsString

        public String getBodyAsString()
        Gets the body of the frames as a String encoded in the frame encoding.
        Returns:
        the body, null if none
      • encoding

        public String encoding()
        Read the frame encoding. If not set defaults to utf-8.
        Returns:
        the encoding
      • getBodyAsByteArray

        public byte[] getBodyAsByteArray()
        Returns:
        the body of the frame as a byte array, null if none.
      • toBuffer

        public Buffer toBuffer​(boolean trailingLine)
        Creates a buffer for the current frame. This buffer may contain an empty line if the trailingLine is set to true
        Parameters:
        trailingLine - whether or not a trailing line should be added to the buffer
        Returns:
        a Buffer containing the STOMP frame. It follows strictly the STOMP specification (including header encoding).
      • toBuffer

        public Buffer toBuffer()
        This method does not enforce the trailing line option. It should not be used directly, except for the PING frame.
        Returns:
        a Buffer containing the STOMP frame. It follows strictly the STOMP specification (including header encoding).
      • setDestination

        public Frame setDestination​(String destination)
      • setTransaction

        public Frame setTransaction​(String id)
      • getId

        public String getId()
      • getReceipt

        public String getReceipt()
      • getTransaction

        public String getTransaction()
      • getDestination

        public String getDestination()