Top Description Inners Fields Constructors Methods
org.springframework.web.reactive.socket

public Class WebSocketMessage

extends Object
Class Inheritance
Imports
java.nio.charset.Charset, .StandardCharsets, org.springframework.core.io.buffer.DataBuffer, .DataBufferUtils, .Netty5DataBufferFactory, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ObjectUtils

Representation of a WebSocket message.

See static factory methods in WebSocketSession for creating messages with the org.springframework.core.io.buffer.DataBufferFactory for the session.

Author
Rossen Stoyanchev
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static enum
WebSocketMessage.Type

WebSocket message types.

Field Summary

Modifier and TypeField and Description
private final Object
private final DataBuffer
private static final boolean
private final WebSocketMessage.Type

Constructor Summary

AccessConstructor and Description
public
WebSocketMessage(WebSocketMessage.Type type, DataBuffer payload)

Constructor for a WebSocketMessage.

public
WebSocketMessage(WebSocketMessage.Type
the type of WebSocket message
type
,
DataBuffer
the message content
payload
,
Object
the message from the API of the underlying WebSocket library, if applicable.
nativeMessage
)

Constructor for an inbound message with access to the underlying message.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public <
the type to cast the underlying message to
T
>
T

Returns:

the underlying message, or null
getNativeMessage
()

Return the message from the API of the underlying WebSocket library.

public DataBuffer
getPayload()

Return the message payload.

public String
getPayloadAsText()

A variant of getPayloadAsText(Charset) that uses UTF-8 for decoding the raw content to text.

public String
getPayloadAsText(Charset
the character encoding
charset
)

A shortcut for decoding the raw content of the message to text with the given character encoding.

public WebSocketMessage.Type
getType()

Return the message type (text, binary, etc).

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public void
release()

Release the payload DataBuffer which is useful on runtimes (e.g. Netty) with pooled buffers such as Netty.

public WebSocketMessage
retain()

Retain the data buffer for the message payload, which is useful on runtimes (e.g. Netty) with pooled buffers.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

nativeMessageback to summary
private final Object nativeMessage
Annotations
@Nullable
payloadback to summary
private final DataBuffer payload
reactorNetty2Presentback to summary
private static final boolean reactorNetty2Present
typeback to summary
private final WebSocketMessage.Type type

Constructor Detail

WebSocketMessageback to summary
public WebSocketMessage(WebSocketMessage.Type type, DataBuffer payload)

Constructor for a WebSocketMessage.

See static factory methods in WebSocketSession or alternatively use WebSocketSession#bufferFactory() to create the payload and then invoke this constructor.

WebSocketMessageback to summary
public WebSocketMessage(WebSocketMessage.Type type, DataBuffer payload, Object nativeMessage)

Constructor for an inbound message with access to the underlying message.

Parameters
type:WebSocketMessage.Type

the type of WebSocket message

payload:DataBuffer

the message content

nativeMessage:Object

the message from the API of the underlying WebSocket library, if applicable.

Since
5.3

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getNativeMessageback to summary
public <T> T getNativeMessage()

Return 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.

Parameters
<T>
the type to cast the underlying message to
Returns:T

the underlying message, or null

Annotations
@Nullable
@SuppressWarnings:unchecked
Since
5.3
getPayloadback to summary
public DataBuffer getPayload()

Return the message payload.

getPayloadAsTextback to summary
public String getPayloadAsText()

A variant of getPayloadAsText(Charset) that uses UTF-8 for decoding the raw content to text.

getPayloadAsTextback to summary
public String getPayloadAsText(Charset charset)

A 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:Charset

the character encoding

Since
5.0.5
getTypeback to summary
public WebSocketMessage.Type getType()

Return the message type (text, binary, etc).

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
releaseback to summary
public void release()

Release the payload DataBuffer which is useful on runtimes (e.g. Netty) with pooled buffers such as Netty. A shortcut for:

DataBuffer payload = message.getPayload();
DataBufferUtils.release(payload);
See Also
DataBufferUtils#release(DataBuffer)
retainback to summary
public WebSocketMessage retain()

Retain the data buffer for the message payload, which is useful on runtimes (e.g. Netty) with pooled buffers. A shortcut for:

DataBuffer payload = message.getPayload();
DataBufferUtils.retain(payload);
See Also
DataBufferUtils#retain(DataBuffer)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.web.reactive.socket back to summary

private Class WebSocketMessage.ReactorNetty2Helper

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.reactive.socket.WebSocketMessage.ReactorNetty2Helper

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static WebSocketMessage
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ReactorNetty2Helperback to summary
private ReactorNetty2Helper()

Method Detail

retainback to summary
pack-priv static WebSocketMessage retain(WebSocketMessage message)
org.springframework.web.reactive.socket back to summary

public final Enum WebSocketMessage.Type

extends Enum<WebSocketMessage.Type>
Class Inheritance

WebSocket message types.

Field Summary

Modifier and TypeField and Description
public static final WebSocketMessage.Type
BINARY

Binary WebSocket message.

public static final WebSocketMessage.Type
PING

WebSocket ping.

public static final WebSocketMessage.Type
PONG

WebSocket pong.

public static final WebSocketMessage.Type
TEXT

Text WebSocket message.

Constructor Summary

AccessConstructor and Description
private
Type()

Method Summary

Modifier and TypeMethod and Description
public static WebSocketMessage.Type
public static WebSocketMessage.Type[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BINARYback to summary
public static final WebSocketMessage.Type BINARY

Binary WebSocket message.

PINGback to summary
public static final WebSocketMessage.Type PING

WebSocket ping.

PONGback to summary
public static final WebSocketMessage.Type PONG

WebSocket pong.

TEXTback to summary
public static final WebSocketMessage.Type TEXT

Text WebSocket message.

Constructor Detail

Typeback to summary
private Type()

Method Detail

valueOfback to summary
public static WebSocketMessage.Type valueOf(String name)
valuesback to summary
public static WebSocketMessage.Type[] values()