Class ConvertingEncoderDecoderSupport<T,M>
- java.lang.Object
 - org.springframework.web.socket.adapter.standard.ConvertingEncoderDecoderSupport<T,M>
 
- Type Parameters:
 T- the type being converted to (for Encoder) or from (for Decoder)M- the WebSocket message type (StringorByteBuffer)
- Direct Known Subclasses:
 ConvertingEncoderDecoderSupport.BinaryDecoder,ConvertingEncoderDecoderSupport.BinaryEncoder,ConvertingEncoderDecoderSupport.TextDecoder,ConvertingEncoderDecoderSupport.TextEncoder
public abstract class ConvertingEncoderDecoderSupport<T,M> extends Object
Base class that can be used to implement a standardEncoderand/orDecoder. It provides encode and decode method implementations that delegate to a SpringConversionService.By default, this class looks up a
ConversionServiceregistered in theactive ApplicationContextunder 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 thegetConversionService()method to provide an alternative lookup strategy.Subclasses can extend this class and should also implement one or both of
EncoderandDecoder. For convenienceConvertingEncoderDecoderSupport.BinaryEncoder,ConvertingEncoderDecoderSupport.BinaryDecoder,ConvertingEncoderDecoderSupport.TextEncoderandConvertingEncoderDecoderSupport.TextDecodersubclasses 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
@Autowire.Converters to convert between the
typeandStringorByteBuffershould be registered.
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConvertingEncoderDecoderSupport.BinaryDecoder<T>A binaryjavax.websocket.Encoderthat delegates to Spring's conversion service.static classConvertingEncoderDecoderSupport.BinaryEncoder<T>A binaryjavax.websocket.Encoderthat delegates to Spring's conversion service.static classConvertingEncoderDecoderSupport.TextDecoder<T>A Textjavax.websocket.Encoderthat delegates to Spring's conversion service.static classConvertingEncoderDecoderSupport.TextEncoder<T>A textjavax.websocket.Encoderthat delegates to Spring's conversion service.
Constructor Summary
Constructors Constructor Description ConvertingEncoderDecoderSupport()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tdecode(M message)voiddestroy()Mencode(T object)protected ApplicationContextgetApplicationContext()Returns the activeApplicationContext.protected ConversionServicegetConversionService()Strategy method used to obtain theConversionService.protected TypeDescriptorgetMessageType()Returns the websocket message type.protected TypeDescriptorgetType()Returns the type being converted.voidinit(EndpointConfig config)booleanwillDecode(M bytes)
Constructor Detail
ConvertingEncoderDecoderSupport
public ConvertingEncoderDecoderSupport()
Method Detail
init
public void init(EndpointConfig config)
destroy
public void destroy()
- See Also:
 Encoder.destroy(),Decoder.destroy()
getConversionService
protected ConversionService getConversionService()
Strategy method used to obtain theConversionService. By default this method expects a bean named'webSocketConversionService'in theactive ApplicationContext.- Returns:
 - the 
ConversionService(never null) 
getApplicationContext
protected ApplicationContext getApplicationContext()
Returns the activeApplicationContext. Be default this method obtains the context viaContextLoader.getCurrentWebApplicationContext(), which finds the ApplicationContext loaded viaContextLoadertypically in a Servlet container environment. When not running in a Servlet container and not usingContextLoader, this method should be overridden.- Returns:
 - the 
ApplicationContextornull 
getType
protected TypeDescriptor getType()
Returns the type being converted. By default the type is resolved using the generic arguments of the class.
getMessageType
protected TypeDescriptor getMessageType()
Returns the websocket message type. By default the type is resolved using the generic arguments of the class.
encode
public M encode(T object) throws EncodeException
- Throws:
 EncodeException- See Also:
 Encoder.Text.encode(Object),Encoder.Binary.encode(Object)
willDecode
public boolean willDecode(M bytes)
decode
public T decode(M message) throws DecodeException