类 ConvertingEncoderDecoderSupport<T,M>
- java.lang.Object
- org.springframework.web.socket.adapter.standard.ConvertingEncoderDecoderSupport<T,M>
- 类型参数:
T
- the type being converted to (for Encoder) or from (for Decoder)M
- the WebSocket message type (String
orByteBuffer
)
- 直接已知子类:
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 standardEncoder
and/orDecoder
. It provides encode and decode method implementations that delegate to a SpringConversionService
.By default, this class looks up a
ConversionService
registered in theactive 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 thegetConversionService()
method to provide an alternative lookup strategy.Subclasses can extend this class and should also implement one or both of
Encoder
andDecoder
. For convenienceConvertingEncoderDecoderSupport.BinaryEncoder
,ConvertingEncoderDecoderSupport.BinaryDecoder
,ConvertingEncoderDecoderSupport.TextEncoder
andConvertingEncoderDecoderSupport.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
@Autowire
.Converters to convert between the
type
andString
orByteBuffer
should be registered.
嵌套类概要
嵌套类 修饰符和类型 类 说明 static class
ConvertingEncoderDecoderSupport.BinaryDecoder<T>
A binaryjavax.websocket.Encoder
that delegates to Spring's conversion service.static class
ConvertingEncoderDecoderSupport.BinaryEncoder<T>
A binaryjavax.websocket.Encoder
that delegates to Spring's conversion service.static class
ConvertingEncoderDecoderSupport.TextDecoder<T>
A Textjavax.websocket.Encoder
that delegates to Spring's conversion service.static class
ConvertingEncoderDecoderSupport.TextEncoder<T>
A textjavax.websocket.Encoder
that delegates to Spring's conversion service.
构造器概要
构造器 构造器 说明 ConvertingEncoderDecoderSupport()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 T
decode(M message)
void
destroy()
M
encode(T object)
protected ApplicationContext
getApplicationContext()
Returns the activeApplicationContext
.protected ConversionService
getConversionService()
Strategy method used to obtain theConversionService
.protected TypeDescriptor
getMessageType()
Returns the websocket message type.protected TypeDescriptor
getType()
Returns the type being converted.void
init(EndpointConfig config)
boolean
willDecode(M bytes)
构造器详细资料
ConvertingEncoderDecoderSupport
public ConvertingEncoderDecoderSupport()
方法详细资料
init
public void init(EndpointConfig config)
destroy
public void destroy()
getConversionService
protected ConversionService getConversionService()
Strategy method used to obtain theConversionService
. By default this method expects a bean named'webSocketConversionService'
in theactive ApplicationContext
.- 返回:
- 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 viaContextLoader
typically in a Servlet container environment. When not running in a Servlet container and not usingContextLoader
, this method should be overridden.- 返回:
- the
ApplicationContext
ornull
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
willDecode
public boolean willDecode(M bytes)
decode
public T decode(M message) throws DecodeException