Class AbstractNettyWebSocketHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<Object>
io.micronaut.http.netty.websocket.AbstractNettyWebSocketHandler
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler
Direct Known Subclasses:
NettyServerWebSocketHandler, NettyWebSocketClientHandler

@Internal public abstract class AbstractNettyWebSocketHandler extends io.netty.channel.SimpleChannelInboundHandler<Object>
Abstract implementation that handles WebSocket frames.
Since:
1.0
Author:
graemerocher
  • Field Details

  • Constructor Details

    • AbstractNettyWebSocketHandler

      protected AbstractNettyWebSocketHandler(RequestBinderRegistry binderRegistry, MediaTypeCodecRegistry mediaTypeCodecRegistry, MessageBodyHandlerRegistry messageBodyHandlerRegistry, WebSocketBean<?> webSocketBean, HttpRequest<?> request, Map<String,Object> uriVariables, io.netty.handler.codec.http.websocketx.WebSocketVersion version, String subProtocol, WebSocketSessionRepository webSocketSessionRepository, ConversionService conversionService)
      Default constructor.
      Parameters:
      binderRegistry - The request binder registry
      mediaTypeCodecRegistry - The codec registry
      messageBodyHandlerRegistry - The handler registry
      webSocketBean - The websocket bean
      request - The originating request
      uriVariables - The URI variables
      version - The websocket version being used
      subProtocol - The handler sub-protocol
      webSocketSessionRepository - The web socket repository if they are supported (like on the server), null otherwise
      conversionService - The conversion service
  • Method Details

    • callOpenMethod

      protected Publisher<?> callOpenMethod(io.netty.channel.ChannelHandlerContext ctx)
      Calls the open method of the websocket bean.
      Parameters:
      ctx - The handler context
      Returns:
      Publisher for any errors, or the result of the open method
    • getBodyArgument

      public abstract Argument<?> getBodyArgument()
      Returns:
      The body argument for the message handler
    • getPongArgument

      public abstract Argument<?> getPongArgument()
      Returns:
      The pong argument for the pong handler
    • getSession

      public abstract NettyWebSocketSession getSession()
      Returns:
      The session
    • exceptionCaught

      public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelHandler
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
    • forwardErrorToUser

      protected final void forwardErrorToUser(io.netty.channel.ChannelHandlerContext ctx, Consumer<Throwable> fallback, Throwable cause)
    • handlerRemoved

      public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      handlerRemoved in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerRemoved in class io.netty.channel.ChannelHandlerAdapter
      Throws:
      Exception
    • createWebSocketSession

      protected abstract NettyWebSocketSession createWebSocketSession(io.netty.channel.ChannelHandlerContext ctx)
      Subclasses should implement to create the actual NettyWebSocketSession.
      Parameters:
      ctx - The context
      Returns:
      The session
    • instrumentPublisher

      protected Publisher<?> instrumentPublisher(io.netty.channel.ChannelHandlerContext ctx, Object result)
      Subclasses can override to customize publishers returned from message handlers.
      Parameters:
      ctx - The context
      result - The result
      Returns:
      The flowable
    • invokeExecutable

      protected Object invokeExecutable(BoundExecutable boundExecutable, MethodExecutionHandle<?,?> messageHandler)
      Invokes the given executable.
      Parameters:
      boundExecutable - The bound executable
      messageHandler - The message handler
      Returns:
      The result
    • channelRead0

      protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, Object msg)
      Specified by:
      channelRead0 in class io.netty.channel.SimpleChannelInboundHandler<Object>
    • handleWebSocketFrame

      protected void handleWebSocketFrame(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.WebSocketFrame msg)
      Handles WebSocket frame request.
      Parameters:
      ctx - The context
      msg - The frame
    • messageHandled

      protected void messageHandled(io.netty.channel.ChannelHandlerContext ctx, Object message)
      Method called once a message has been handled by the handler.
      Parameters:
      ctx - The channel handler context
      message - The message that was handled
    • writeCloseFrameAndTerminate

      protected void writeCloseFrameAndTerminate(io.netty.channel.ChannelHandlerContext ctx, CloseReason closeReason)
      Writes the give close reason and terminates the session.
      Parameters:
      ctx - The context
      closeReason - The reason
    • handleCloseReason

      protected void handleCloseReason(io.netty.channel.ChannelHandlerContext ctx, CloseReason cr, boolean writeCloseReason)
      Used to close the session with a given reason.
      Parameters:
      ctx - The context
      cr - The reason
      writeCloseReason - Whether to allow writing the close reason to the remote