Top Description Fields Constructors Methods
org.springframework.messaging.simp.stomp

public Class StompDecoder

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.ArrayList, .List, org.apache.commons.logging.Log, org.springframework.lang.Nullable, org.springframework.messaging.Message, org.springframework.messaging.simp.SimpLogging, org.springframework.messaging.support.MessageBuilder, .MessageHeaderInitializer, .NativeMessageHeaderAccessor, org.springframework.util.InvalidMimeTypeException, .MultiValueMap, .StreamUtils

Decodes one or more STOMP frames contained in a ByteBuffer.

An attempt is made to read all complete STOMP frames from the buffer, which could be zero, one, or more. If there is any left-over content, i.e. an incomplete STOMP frame, at the end the buffer is reset to point to the beginning of the partial content. The caller is then responsible for dealing with that incomplete content by buffering until there is more input available.

Authors
Andy Wilkinson, Rossen Stoyanchev
Since
4.0

Field Summary

Modifier and TypeField and Description
private MessageHeaderInitializer
pack-priv static final byte[]
private static final Log

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public List<Message<byte[]>>

Returns:

the decoded messages, or an empty list if none
decode
(ByteBuffer
the buffer to decode the STOMP frame from
byteBuffer
)

Decodes one or more STOMP frames from the given ByteBuffer into a list of Messages.

public List<Message<byte[]>>

Returns:

the decoded messages, or an empty list if none
decode
(ByteBuffer
the buffer to decode the STOMP frame from
byteBuffer
,
MultiValueMap<String, String>
an empty output map that will store the last successfully parsed partialMessageHeaders in case of partial message content in cases where the partial buffer ended with a partial STOMP frame
partialMessageHeaders
)

Decodes one or more STOMP frames from the given buffer and returns a list of Messages.

private Message<byte[]>
decodeMessage(ByteBuffer byteBuffer, MultiValueMap<String, String> headers)

Decode a single STOMP frame from the given buffer into a Message.

public MessageHeaderInitializer
getHeaderInitializer()

Return the configured MessageHeaderInitializer, if any.

private void
private String
readCommand(ByteBuffer byteBuffer)

private void
readHeaders(ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor, StompCommand command)

private byte[]
readPayload(ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor)

public void
setHeaderInitializer(MessageHeaderInitializer headerInitializer)

Configure a MessageHeaderInitializer to apply to the headers of Messages from decoded STOMP frames.

protected void
skipEol(ByteBuffer byteBuffer)

Skip one ore more EOL characters at the start of the given ByteBuffer.

private boolean

Returns:

whether an EOL was consumed
tryConsumeEndOfLine
(ByteBuffer byteBuffer)

Try to read an EOL incrementing the buffer position if successful.

private String
unescape(String inString)

See STOMP Spec 1.2: "Value Encoding".

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

headerInitializerback to summary
private MessageHeaderInitializer headerInitializer
Annotations
@Nullable
HEARTBEAT_PAYLOADback to summary
pack-priv static final byte[] HEARTBEAT_PAYLOAD
loggerback to summary
private static final Log logger

Constructor Detail

StompDecoderback to summary
public StompDecoder()

Method Detail

decodeback to summary
public List<Message<byte[]>> decode(ByteBuffer byteBuffer)

Decodes one or more STOMP frames from the given ByteBuffer into a list of Messages. If the input buffer contains partial STOMP frame content, or additional content with a partial STOMP frame, the buffer is reset and null is returned.

Parameters
byteBuffer:ByteBuffer

the buffer to decode the STOMP frame from

Returns:List<Message<byte[]>>

the decoded messages, or an empty list if none

Exceptions
StompConversionException:
raised in case of decoding issues
decodeback to summary
public List<Message<byte[]>> decode(ByteBuffer byteBuffer, MultiValueMap<String, String> partialMessageHeaders)

Decodes one or more STOMP frames from the given buffer and returns a list of Messages.

If the given ByteBuffer contains only partial STOMP frame content and no complete STOMP frames, an empty list is returned, and the buffer is reset to where it was.

If the buffer contains one or more STOMP frames, those are returned and the buffer reset to point to the beginning of the unused partial content.

The output partialMessageHeaders map is used to store successfully parsed headers in case of partial content. The caller can then check if a "content-length" header was read, which helps to determine how much more content is needed before the next attempt to decode.

Parameters
byteBuffer:ByteBuffer

the buffer to decode the STOMP frame from

partialMessageHeaders:MultiValueMap<String, String>

an empty output map that will store the last successfully parsed partialMessageHeaders in case of partial message content in cases where the partial buffer ended with a partial STOMP frame

Returns:List<Message<byte[]>>

the decoded messages, or an empty list if none

Exceptions
StompConversionException:
raised in case of decoding issues
decodeMessageback to summary
private Message<byte[]> decodeMessage(ByteBuffer byteBuffer, MultiValueMap<String, String> headers)

Decode a single STOMP frame from the given buffer into a Message.

Annotations
@Nullable
getHeaderInitializerback to summary
public MessageHeaderInitializer getHeaderInitializer()

Return the configured MessageHeaderInitializer, if any.

Annotations
@Nullable
initHeadersback to summary
private void initHeaders(StompHeaderAccessor headerAccessor)
readCommandback to summary
private String readCommand(ByteBuffer byteBuffer)
readHeadersback to summary
private void readHeaders(ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor, StompCommand command)
readPayloadback to summary
private byte[] readPayload(ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor)
Annotations
@Nullable
setHeaderInitializerback to summary
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer)

Configure a MessageHeaderInitializer to apply to the headers of Messages from decoded STOMP frames.

skipEolback to summary
protected void skipEol(ByteBuffer byteBuffer)

Skip one ore more EOL characters at the start of the given ByteBuffer. STOMP, section 2.1 says: "The NULL octet can be optionally followed by multiple EOLs."

tryConsumeEndOfLineback to summary
private boolean tryConsumeEndOfLine(ByteBuffer byteBuffer)

Try to read an EOL incrementing the buffer position if successful.

Returns:boolean

whether an EOL was consumed

unescapeback to summary
private String unescape(String inString)

See STOMP Spec 1.2: "Value Encoding".