@Internal public abstract class AbstractNettyWebSocketHandler extends io.netty.channel.SimpleChannelInboundHandler<Object>
Modifier and Type | Field and Description |
---|---|
static String |
ID
The id of the handler used when adding it to the Netty pipeline.
|
protected org.slf4j.Logger |
LOG |
protected MediaTypeCodecRegistry |
mediaTypeCodecRegistry |
protected MethodExecutionHandle<?,?> |
messageHandler |
protected HttpRequest<?> |
originatingRequest |
protected MethodExecutionHandle<?,?> |
pongHandler |
protected String |
subProtocol |
protected Map<String,Object> |
uriVariables |
protected WebSocketBean<?> |
webSocketBean |
protected ArgumentBinderRegistry<WebSocketState> |
webSocketBinder |
protected WebSocketSessionRepository |
webSocketSessionRepository |
protected io.netty.handler.codec.http.websocketx.WebSocketVersion |
webSocketVersion |
Modifier | Constructor and Description |
---|---|
protected |
AbstractNettyWebSocketHandler(io.netty.channel.ChannelHandlerContext ctx,
RequestBinderRegistry binderRegistry,
MediaTypeCodecRegistry mediaTypeCodecRegistry,
WebSocketBean<?> webSocketBean,
HttpRequest<?> request,
Map<String,Object> uriVariables,
io.netty.handler.codec.http.websocketx.WebSocketVersion version,
String subProtocol,
WebSocketSessionRepository webSocketSessionRepository)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected Publisher<?> |
callOpenMethod(io.netty.channel.ChannelHandlerContext ctx)
Calls the open method of the websocket bean.
|
protected void |
channelRead0(io.netty.channel.ChannelHandlerContext ctx,
Object msg) |
protected abstract NettyWebSocketSession |
createWebSocketSession(io.netty.channel.ChannelHandlerContext ctx)
Subclasses should implement to create the actual
NettyWebSocketSession . |
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
protected void |
forwardErrorToUser(io.netty.channel.ChannelHandlerContext ctx,
Consumer<Throwable> fallback,
Throwable cause) |
abstract Argument<?> |
getBodyArgument() |
abstract Argument<?> |
getPongArgument() |
abstract NettyWebSocketSession |
getSession() |
protected void |
handleCloseReason(io.netty.channel.ChannelHandlerContext ctx,
CloseReason cr,
boolean writeCloseReason)
Used to close the session with a given reason.
|
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
protected void |
handleWebSocketFrame(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.websocketx.WebSocketFrame msg)
Handles WebSocket frame request.
|
protected Publisher<?> |
instrumentPublisher(io.netty.channel.ChannelHandlerContext ctx,
Object result)
Subclasses can override to customize publishers returned from message handlers.
|
protected Object |
invokeExecutable(BoundExecutable boundExecutable,
MethodExecutionHandle<?,?> messageHandler)
Invokes the given executable.
|
protected void |
messageHandled(io.netty.channel.ChannelHandlerContext ctx,
Object message)
Method called once a message has been handled by the handler.
|
protected void |
writeCloseFrameAndTerminate(io.netty.channel.ChannelHandlerContext ctx,
CloseReason closeReason)
Writes the give close reason and terminates the session.
|
acceptInboundMessage, channelRead
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
ensureNotSharable, handlerAdded, isSharable
public static final String ID
protected final org.slf4j.Logger LOG
protected final ArgumentBinderRegistry<WebSocketState> webSocketBinder
protected final WebSocketBean<?> webSocketBean
protected final HttpRequest<?> originatingRequest
protected final MethodExecutionHandle<?,?> messageHandler
protected final MethodExecutionHandle<?,?> pongHandler
protected final MediaTypeCodecRegistry mediaTypeCodecRegistry
protected final io.netty.handler.codec.http.websocketx.WebSocketVersion webSocketVersion
protected final String subProtocol
protected final WebSocketSessionRepository webSocketSessionRepository
protected AbstractNettyWebSocketHandler(io.netty.channel.ChannelHandlerContext ctx, RequestBinderRegistry binderRegistry, MediaTypeCodecRegistry mediaTypeCodecRegistry, WebSocketBean<?> webSocketBean, HttpRequest<?> request, Map<String,Object> uriVariables, io.netty.handler.codec.http.websocketx.WebSocketVersion version, String subProtocol, WebSocketSessionRepository webSocketSessionRepository)
ctx
- The channel handler contextbinderRegistry
- The request binder registrymediaTypeCodecRegistry
- The codec registrywebSocketBean
- The websocket beanrequest
- The originating requesturiVariables
- The URI variablesversion
- The websocket version being usedsubProtocol
- The handler sub-protocolwebSocketSessionRepository
- The web socket repository if they are supported (like on the server), null otherwiseprotected Publisher<?> callOpenMethod(io.netty.channel.ChannelHandlerContext ctx)
ctx
- The handler contextpublic abstract Argument<?> getBodyArgument()
public abstract Argument<?> getPongArgument()
public abstract NettyWebSocketSession getSession()
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
protected final void forwardErrorToUser(io.netty.channel.ChannelHandlerContext ctx, Consumer<Throwable> fallback, Throwable cause)
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerRemoved
in interface io.netty.channel.ChannelHandler
handlerRemoved
in class io.netty.channel.ChannelHandlerAdapter
Exception
protected abstract NettyWebSocketSession createWebSocketSession(io.netty.channel.ChannelHandlerContext ctx)
NettyWebSocketSession
.ctx
- The contextprotected Publisher<?> instrumentPublisher(io.netty.channel.ChannelHandlerContext ctx, Object result)
ctx
- The contextresult
- The resultprotected Object invokeExecutable(BoundExecutable boundExecutable, MethodExecutionHandle<?,?> messageHandler)
boundExecutable
- The bound executablemessageHandler
- The message handlerprotected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, Object msg)
channelRead0
in class io.netty.channel.SimpleChannelInboundHandler<Object>
protected void handleWebSocketFrame(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.WebSocketFrame msg)
ctx
- The contextmsg
- The frameprotected void messageHandled(io.netty.channel.ChannelHandlerContext ctx, Object message)
ctx
- The channel handler contextmessage
- The message that was handledprotected void writeCloseFrameAndTerminate(io.netty.channel.ChannelHandlerContext ctx, CloseReason closeReason)
ctx
- The contextcloseReason
- The reasonprotected void handleCloseReason(io.netty.channel.ChannelHandlerContext ctx, CloseReason cr, boolean writeCloseReason)
ctx
- The contextcr
- The reasonwriteCloseReason
- Whether to allow writing the close reason to the remote