Class WebSocketMessage
java.lang.Object
org.springframework.web.reactive.socket.WebSocketMessage
Representation of a WebSocket message.
 
See static factory methods in WebSocketSession for creating messages with
 the DataBufferFactory for the session.
- Since:
- 5.0
- Author:
- Rossen Stoyanchev
- 
Nested Class SummaryNested Classes
- 
Constructor SummaryConstructorsConstructorDescriptionWebSocketMessage(WebSocketMessage.Type type, DataBuffer payload) Constructor for a WebSocketMessage.WebSocketMessage(WebSocketMessage.Type type, DataBuffer payload, Object nativeMessage) Constructor for an inbound message with access to the underlying message.
- 
Method SummaryModifier and TypeMethodDescriptionboolean<T> TReturn the message from the API of the underlying WebSocket library.Return the message payload.A variant ofgetPayloadAsText(Charset)that usesUTF-8for decoding the raw content to text.getPayloadAsText(Charset charset) A shortcut for decoding the raw content of the message to text with the given character encoding.getType()Return the message type (text, binary, etc).inthashCode()voidrelease()Release the payloadDataBufferwhich is useful on runtimes (for example, Netty) with pooled buffers such as Netty.retain()Retain the data buffer for the message payload, which is useful on runtimes (for example, Netty) with pooled buffers.toString()
- 
Constructor Details- 
WebSocketMessageConstructor for a WebSocketMessage.See static factory methods in WebSocketSessionor alternatively useWebSocketSession.bufferFactory()to create the payload and then invoke this constructor.
- 
WebSocketMessagepublic WebSocketMessage(WebSocketMessage.Type type, DataBuffer payload, @Nullable Object nativeMessage) Constructor for an inbound message with access to the underlying message.- Parameters:
- type- the type of WebSocket message
- payload- the message content
- nativeMessage- the message from the API of the underlying WebSocket library, if applicable.
- Since:
- 5.3
 
 
- 
- 
Method Details- 
getTypeReturn the message type (text, binary, etc).
- 
getPayloadReturn the message payload.
- 
getNativeMessageReturn the message from the API of the underlying WebSocket library. This is applicable for inbound messages only and when the underlying message has additional fields other than the content. Currently this is the case for Reactor Netty only.- Type Parameters:
- T- the type to cast the underlying message to
- Returns:
- the underlying message, or null
- Since:
- 5.3
 
- 
getPayloadAsTextA variant ofgetPayloadAsText(Charset)that usesUTF-8for decoding the raw content to text.
- 
getPayloadAsTextA shortcut for decoding the raw content of the message to text with the given character encoding. This is useful for text WebSocket messages, or otherwise when the payload is expected to contain text.- Parameters:
- charset- the character encoding
- Since:
- 5.0.5
 
- 
retainRetain the data buffer for the message payload, which is useful on runtimes (for example, Netty) with pooled buffers. A shortcut for:DataBuffer payload = message.getPayload(); DataBufferUtils.retain(payload); - See Also:
 
- 
releasepublic void release()Release the payloadDataBufferwhich is useful on runtimes (for example, Netty) with pooled buffers such as Netty. A shortcut for:DataBuffer payload = message.getPayload(); DataBufferUtils.release(payload); - See Also:
 
- 
equals
- 
hashCodepublic int hashCode()
- 
toString
 
-