T - The type being converted to (for Encoder) or from (for Decoder)M - The WebSocket message type (String or ByteBuffer)public abstract class ConvertingEncoderDecoderSupport<T,M> extends Object
By default, this class looks up a <code>ConversionService</code> 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 <code>Encoder</code> and <code>Decoder</code>.
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 <code>@Autowire</code>.
Converters to convert between the type and String or
ByteBuffer should be registered.
ConvertingEncoderDecoderSupport.BinaryEncoder,
ConvertingEncoderDecoderSupport.BinaryDecoder,
ConvertingEncoderDecoderSupport.TextEncoder,
ConvertingEncoderDecoderSupport.TextDecoder| Modifier and Type | Class and Description |
|---|---|
static class |
ConvertingEncoderDecoderSupport.BinaryDecoder<T>
A Binary <code>javax.websocket.Encoder</code> that delegates
to Spring's conversion service.
|
static class |
ConvertingEncoderDecoderSupport.BinaryEncoder<T>
A Binary <code>javax.websocket.Encoder</code> that
delegates to Spring's conversion service.
|
static class |
ConvertingEncoderDecoderSupport.TextDecoder<T>
A Text <code>javax.websocket.Encoder</code> that delegates
to Spring's conversion service.
|
static class |
ConvertingEncoderDecoderSupport.TextEncoder<T>
A Text <code>javax.websocket.Encoder</code> that delegates
to Spring's conversion service.
|
| Constructor and Description |
|---|
ConvertingEncoderDecoderSupport() |
| Modifier and Type | Method and Description |
|---|---|
T |
decode(M message) |
void |
destroy() |
M |
encode(T object) |
protected org.springframework.context.ApplicationContext |
getApplicationContext()
Returns the active <code>ApplicationContext</code>.
|
protected org.springframework.core.convert.ConversionService |
getConversionService()
Strategy method used to obtain the <code>ConversionService</code>.
|
protected org.springframework.core.convert.TypeDescriptor |
getMessageType()
Returns the websocket message type.
|
protected org.springframework.core.convert.TypeDescriptor |
getType()
Returns the type being converted.
|
void |
init(javax.websocket.EndpointConfig config) |
boolean |
willDecode(M bytes) |
public void init(javax.websocket.EndpointConfig config)
Encoder.init(EndpointConfig),
Decoder.init(EndpointConfig)public void destroy()
Encoder.destroy(),
Decoder.destroy()protected org.springframework.core.convert.ConversionService getConversionService()
'webSocketConversionService' in the
active ApplicationContext.protected org.springframework.context.ApplicationContext getApplicationContext()
ContextLoader.getCurrentWebApplicationContext(), which
finds the ApplicationContext loaded via <code>ContextLoader</code> typically in a
Servlet container environment. When not running in a Servlet container and
not using <code>ContextLoader</code>, this method should be overridden.nullprotected org.springframework.core.convert.TypeDescriptor getType()
protected org.springframework.core.convert.TypeDescriptor getMessageType()
public M encode(T object) throws javax.websocket.EncodeException
javax.websocket.EncodeExceptionEncoder.Text.encode(Object),
Encoder.Binary.encode(Object)public boolean willDecode(M bytes)
Decoder.Text.willDecode(String),
Decoder.Binary.willDecode(ByteBuffer)