Package io.vertx.ext.stomp
Class Frame
- java.lang.Object
-
- io.vertx.ext.stomp.Frame
-
public class Frame extends Object
Represents a STOMP frame. STOMP frames are structured as follows. It starts by acommand, followed by a set of headers. Then the frame may have a body and is finished by a0byte. This class represents this structure and provide access to the different parts. This class is NOT thread-safe.- Author:
- Clement Escoffier
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFrame.HeartbeatRepresents the heartbeat configuration.
-
Field Summary
Fields Modifier and Type Field Description static StringACCEPT_VERSIONstatic StringACKstatic StringCONTENT_LENGTHstatic StringCONTENT_TYPEstatic StringDESTINATIONstatic StringHEARTBEATstatic StringHOSTstatic StringIDstatic StringLOGINstatic StringMESSAGEstatic StringMESSAGE_IDstatic StringPASSCODEstatic StringRECEIPTstatic StringRECEIPT_IDstatic StringSERVERstatic StringSESSIONstatic StringSTOMP_FRAME_COMMANDHeader used when a frame using an unknown command is received.static StringSUBSCRIPTIONstatic StringTRANSACTIONstatic StringVERSION
-
Constructor Summary
Constructors Constructor Description Frame()Creates an un-configured frame.Frame(JsonObject json)Creates a new instance ofFramefrom its JSON representation.Frame(Command command, Map<String,String> headers, Buffer body)Creates a new instance ofFrame.Frame(Frame other)Creates a new instance ofFrameby copying the values from theotherframe.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FrameaddHeader(String key, String value)Adds a header to the frame.Stringencoding()Read the frame encoding.StringgetAck()Gets the value of theackheader.BuffergetBody()byte[]getBodyAsByteArray()StringgetBodyAsString()Gets the body of the frames as a String encoded in the frame encoding.StringgetBodyAsString(String encoding)Gets the body of the frames as a String encoded in the given encoding.CommandgetCommand()StringgetDestination()StringgetHeader(String name)Gets the value of the header with the given name.Map<String,String>getHeaders()Gets the frame headers.StringgetId()StringgetReceipt()StringgetTransaction()booleanhasEmptyBody()FramesetBody(Buffer body)Sets the body of the frame.FramesetCommand(Command command)Sets the frame command.FramesetDestination(String destination)FramesetHeaders(Map<String,String> headers)Sets the headers of the frames.FramesetId(String id)FramesetTransaction(String id)BuffertoBuffer()This method does not enforce the trailing line option.BuffertoBuffer(boolean trailingLine)Creates a buffer for the current frame.JsonObjecttoJson()StringtoString()voidvalidate()Checks the validity of the frame.
-
-
-
Field Detail
-
CONTENT_LENGTH
public static final String CONTENT_LENGTH
- See Also:
- Constant Field Values
-
CONTENT_TYPE
public static final String CONTENT_TYPE
- See Also:
- Constant Field Values
-
HOST
public static final String HOST
- See Also:
- Constant Field Values
-
VERSION
public static final String VERSION
- See Also:
- Constant Field Values
-
ACCEPT_VERSION
public static final String ACCEPT_VERSION
- See Also:
- Constant Field Values
-
SESSION
public static final String SESSION
- See Also:
- Constant Field Values
-
SERVER
public static final String SERVER
- See Also:
- Constant Field Values
-
LOGIN
public static final String LOGIN
- See Also:
- Constant Field Values
-
PASSCODE
public static final String PASSCODE
- See Also:
- Constant Field Values
-
HEARTBEAT
public static final String HEARTBEAT
- See Also:
- Constant Field Values
-
DESTINATION
public static final String DESTINATION
- See Also:
- Constant Field Values
-
RECEIPT
public static final String RECEIPT
- See Also:
- Constant Field Values
-
RECEIPT_ID
public static final String RECEIPT_ID
- See Also:
- Constant Field Values
-
ACK
public static final String ACK
- See Also:
- Constant Field Values
-
ID
public static final String ID
- See Also:
- Constant Field Values
-
SUBSCRIPTION
public static final String SUBSCRIPTION
- See Also:
- Constant Field Values
-
MESSAGE_ID
public static final String MESSAGE_ID
- See Also:
- Constant Field Values
-
TRANSACTION
public static final String TRANSACTION
- See Also:
- Constant Field Values
-
MESSAGE
public static final String MESSAGE
- See Also:
- Constant Field Values
-
STOMP_FRAME_COMMAND
public static final String STOMP_FRAME_COMMAND
Header used when a frame using an unknown command is received. The createdFrameobject uses theCommand.UNKNOWNcommand and gives the original command in this header.- See Also:
- Constant Field Values
-
-
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 ofFrameby copying the values from theotherframe. The body of the frame is copied.- Parameters:
other- the frame to copy.
-
Frame
public Frame(JsonObject json)
Creates a new instance ofFramefrom its JSON representation.- Parameters:
json- the json form of the frame
-
-
Method Detail
-
addHeader
public Frame addHeader(String key, String value)
Adds a header to the frame.- Parameters:
key- the header namevalue- the header value- Returns:
- the current
Frame
-
getAck
public String getAck()
Gets the value of theackheader.- Returns:
- the
ackheader value,nullif not set
-
getHeaders
public Map<String,String> getHeaders()
Gets the frame headers. Modifications to the returnedMapmodifies 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 benull. In thenullcase, 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 benull- 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,
nullif 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,
nullif none
-
getBodyAsString
public String getBodyAsString()
Gets the body of the frames as a String encoded in the frame encoding.- Returns:
- the body,
nullif 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,
nullif none.
-
toBuffer
public Buffer toBuffer(boolean trailingLine)
Creates a buffer for the current frame. This buffer may contain an empty line if thetrailingLineis set totrue- Parameters:
trailingLine- whether or not a trailing line should be added to the buffer- Returns:
- a
Buffercontaining 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
Buffercontaining the STOMP frame. It follows strictly the STOMP specification (including header encoding).
-
getId
public String getId()
-
getReceipt
public String getReceipt()
-
getTransaction
public String getTransaction()
-
getDestination
public String getDestination()
-
-