spring-framework / org.springframework.web.socket.adapter.standard / ConvertingEncoderDecoderSupport

ConvertingEncoderDecoderSupport

abstract class ConvertingEncoderDecoderSupport<T : Any, M : Any>

Base class that can be used to implement a standard javax.websocket.Encoder and/or javax.websocket.Decoder. It provides encode and decode method implementations that delegate to a Spring ConversionService.

By default, this class looks up a ConversionService registered in the active ApplicationContext under the name 'webSocketConversionService'. This works fine for both client and server endpoints, in a Servlet container environment. If not running in a Servlet container, subclasses will need to override the #getConversionService() method to provide an alternative lookup strategy.

Subclasses can extend this class and should also implement one or both of javax.websocket.Encoder and javax.websocket.Decoder. For convenience ConvertingEncoderDecoderSupport.BinaryEncoder, ConvertingEncoderDecoderSupport.BinaryDecoder, ConvertingEncoderDecoderSupport.TextEncoder and ConvertingEncoderDecoderSupport.TextDecoder subclasses are provided.

Since JSR-356 only allows Encoder/Decoder to be registered by type, instances of this class are therefore managed by the WebSocket runtime, and do not need to be registered as Spring Beans. They can, however, by injected with Spring-managed dependencies via Autowired.

Converters to convert between the type and String or ByteBuffer should be registered.

Parameters

- the type being converted to (for Encoder) or from (for Decoder)

- the WebSocket message type (String or ByteBuffer)

Author
Phillip Webb

Since
4.0

See Also
ConvertingEncoderDecoderSupport.BinaryEncoderConvertingEncoderDecoderSupport.BinaryDecoderConvertingEncoderDecoderSupport.TextEncoderConvertingEncoderDecoderSupport.TextDecoder

Constructors

<init>

ConvertingEncoderDecoderSupport()

Base class that can be used to implement a standard javax.websocket.Encoder and/or javax.websocket.Decoder. It provides encode and decode method implementations that delegate to a Spring ConversionService.

By default, this class looks up a ConversionService registered in the active ApplicationContext under the name 'webSocketConversionService'. This works fine for both client and server endpoints, in a Servlet container environment. If not running in a Servlet container, subclasses will need to override the #getConversionService() method to provide an alternative lookup strategy.

Subclasses can extend this class and should also implement one or both of javax.websocket.Encoder and javax.websocket.Decoder. For convenience ConvertingEncoderDecoderSupport.BinaryEncoder, ConvertingEncoderDecoderSupport.BinaryDecoder, ConvertingEncoderDecoderSupport.TextEncoder and ConvertingEncoderDecoderSupport.TextDecoder subclasses are provided.

Since JSR-356 only allows Encoder/Decoder to be registered by type, instances of this class are therefore managed by the WebSocket runtime, and do not need to be registered as Spring Beans. They can, however, by injected with Spring-managed dependencies via Autowired.

Converters to convert between the type and String or ByteBuffer should be registered.

Functions

decode

open fun decode(message: M): T

destroy

open fun destroy(): Unit

encode

open fun encode(object: T): M

init

open fun init(config: EndpointConfig): Unit

willDecode

open fun willDecode(bytes: M): Boolean