Package org.mockserver.mock.action.http
Class GraphQLSubscriptionHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.websocketx.WebSocketFrame>
org.mockserver.mock.action.http.GraphQLSubscriptionHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler
public class GraphQLSubscriptionHandler
extends io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.websocketx.WebSocketFrame>
Handles the graphql-transport-ws
protocol over an already-established WebSocket connection.
Installed after the WebSocket handshake when the negotiated subprotocol is
graphql-transport-ws or the legacy graphql-ws.
Protocol messages handled:
connection_init- repliesconnection_ackping- repliespongsubscribe- AST-matches the query against the configured subscription expectation; on match pushes a scripted sequence ofnextmessages thencomplete; on no match sendserrorcomplete(client) - cancels that subscription's pending messages
Inbound breakpoints (A1e): when an INBOUND_STREAM breakpoint matcher is registered and
inbound stream ID is configured, incoming WebSocket frames are parked in the
StreamFrameBreakpointRegistry before protocol dispatch. The frame text is copied
to byte[] (UTF-8) at park time and the original TextWebSocketFrame is
released immediately. On resume, the text is reconstructed from the captured/modified bytes.
Backpressure is applied via autoRead=false while a frame is parked.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface for sending text frames to the client, with optional delay support.Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionGraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker) Original constructor — no inbound breakpoint support (backward compatible).GraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker, Configuration configuration, String inboundStreamId, WebSocketClientRegistry webSocketClientRegistry) Deprecated.use the constructor that accepts inboundBreakpointClientId and inboundBreakpointIdGraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker, Configuration configuration, String inboundStreamId, WebSocketClientRegistry webSocketClientRegistry, String inboundBreakpointClientId, String inboundBreakpointId) Constructor with inbound breakpoint support and pre-resolved breakpoint identity. -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) protected voidchannelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.WebSocketFrame frame) voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) static booleanisGraphQLWebSocketProtocol(String subprotocol) Check whether the given subprotocol string indicates a graphql-transport-ws or legacy graphql-ws protocol.Methods inherited from class io.netty.channel.SimpleChannelInboundHandler
acceptInboundMessage, channelReadMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Constructor Details
-
GraphQLSubscriptionHandler
public GraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker) Original constructor — no inbound breakpoint support (backward compatible).- Parameters:
expectedSubscriptionQuery- a GraphQLBody describing the subscription query to matchsubscriptionPayloads- the sequence of payloads to push asnextmessagesframeSender- callback for sending text frames with optional delayshandshaker- the WebSocket handshaker for closing the connection
-
GraphQLSubscriptionHandler
public GraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker, Configuration configuration, String inboundStreamId, WebSocketClientRegistry webSocketClientRegistry) Deprecated.use the constructor that accepts inboundBreakpointClientId and inboundBreakpointIdConstructor with inbound breakpoint support (performs its own findMatch for backward compatibility). -
GraphQLSubscriptionHandler
public GraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker, Configuration configuration, String inboundStreamId, WebSocketClientRegistry webSocketClientRegistry, String inboundBreakpointClientId, String inboundBreakpointId) Constructor with inbound breakpoint support and pre-resolved breakpoint identity.- Parameters:
expectedSubscriptionQuery- a GraphQLBody describing the subscription query to matchsubscriptionPayloads- the sequence of payloads to push asnextmessagesframeSender- callback for sending text frames with optional delayshandshaker- the WebSocket handshaker for closing the connectionconfiguration- the active server configuration (null to disable inbound breakpoints)inboundStreamId- the stream ID for inbound breakpoints (null to disable)webSocketClientRegistry- the per-server WS registry for callback dispatch (null to disable WS dispatch)inboundBreakpointClientId- the matched inbound breakpoint's owning clientId (from outer caller)inboundBreakpointId- the matched inbound breakpoint's id (from outer caller)
-
-
Method Details
-
channelRead0
protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.WebSocketFrame frame) - Specified by:
channelRead0in classio.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.websocketx.WebSocketFrame>
-
exceptionCaught
- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter
-
channelInactive
- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
isGraphQLWebSocketProtocol
Check whether the given subprotocol string indicates a graphql-transport-ws or legacy graphql-ws protocol.
-