Package org.mockserver.netty.grpc
Class GrpcBidiReflectionHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
org.mockserver.netty.grpc.GrpcBidiReflectionHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler
public class GrpcBidiReflectionHandler
extends io.netty.channel.ChannelInboundHandlerAdapter
Per-stream handler for serving gRPC Server Reflection interactively over the
bidirectional-streaming multiplex pipeline. NOT
@Sharable -- holds per-stream
state (the incremental frame decoder, finished guard).
Behaviour:
- On
Http2HeadersFrame: writes initial response HEADERS (:status=200,content-type=application/grpc,endStream=false). If the HEADERS frame hasendStream=true, immediately finishes with grpc-status=0. - On
Http2DataFrame: feeds content bytes toIncrementalGrpcFrameDecoder; for each complete inbound gRPC message, delegates toGrpcServerReflectionHandler.handleReflectionRequest(byte[])and writes the gRPC-framed response as a DATA frame. If the frame hasendStream=true, callsfinish(ChannelHandlerContext). finish(): writes trailing HEADERS with grpc-status=0 andendStream=true. Guarded to run at most once.
This handler reuses the existing GrpcServerReflectionHandler for per-message
reflection logic (decoding the request, looking up services/files in the descriptor
store, encoding the response). The only difference from the buffered-unary path is
that multiple request/response pairs can be interleaved over a single HTTP/2 stream.
Flow control: the channel's autoRead is set to false when this handler is
added; after processing each inbound frame, ctx.read() is called to request
the next frame.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionGrpcBidiReflectionHandler(GrpcServerReflectionHandler reflectionHandler) Creates a new per-stream bidi reflection handler. -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx) Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, 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
handlerRemoved
-
Constructor Details
-
GrpcBidiReflectionHandler
Creates a new per-stream bidi reflection handler.- Parameters:
reflectionHandler- the reflection handler that performs per-message request decoding and response encoding (shared, stateless)
-
-
Method Details
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) - Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter
-
channelRead
- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter
-
exceptionCaught
- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter
-