Class WebSocketControlFrameHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
org.mockserver.mock.action.http.WebSocketControlFrameHandler
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

public class WebSocketControlFrameHandler extends io.netty.channel.ChannelInboundHandlerAdapter
Answers WebSocket control frames on mocked (user-facing) WebSocket connections.

MockServer performs the WebSocket handshake by hand via WebSocketServerHandshaker.handshake(io.netty.channel.Channel, io.netty.handler.codec.http.FullHttpRequest), which installs only the frame encoder and decoder — unlike Netty's WebSocketServerProtocolHandler, it contributes no control-frame behaviour at all. Without this handler a mocked WebSocket therefore never answers a PING and never echoes a CLOSE, so every keepalive-based client (browsers, OkHttp's pingInterval, Java-WebSocket's connection-lost detector) eventually tears the connection down mid-test. RFC 6455 §5.5.2 makes the Pong a MUST, and §5.5.1 requires the close echo.

Installed immediately after a successful handshake, ahead of GraphQLSubscriptionHandler and BidirectionalWebSocketFrameHandler.

PING frames are answered and forwarded downstream, because WebSocketFrameType.PING is an expressible matcher frame type — swallowing the ping here would silently stop those matchers firing.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Constructor Summary

    Constructors
    Constructor
    Description
    WebSocketControlFrameHandler(io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
     

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, handlerAdded, handlerRemoved, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Constructor Details

    • WebSocketControlFrameHandler

      public WebSocketControlFrameHandler(io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker)
  • Method Details

    • channelRead

      public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
      Specified by:
      channelRead in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRead in class io.netty.channel.ChannelInboundHandlerAdapter