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 has endStream=true, immediately finishes with grpc-status=0.
  • On Http2DataFrame: feeds content bytes to IncrementalGrpcFrameDecoder; for each complete inbound gRPC message, delegates to GrpcServerReflectionHandler.handleReflectionRequest(byte[]) and writes the gRPC-framed response as a DATA frame. If the frame has endStream=true, calls finish(ChannelHandlerContext).
  • finish(): writes trailing HEADERS with grpc-status=0 and endStream=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

    Constructors
    Constructor
    Description
    Creates a new per-stream bidi reflection handler.
  • Method Summary

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

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

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

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, 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

    handlerRemoved
  • Constructor Details

    • GrpcBidiReflectionHandler

      public GrpcBidiReflectionHandler(GrpcServerReflectionHandler reflectionHandler)
      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:
      handlerAdded in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerAdded in class io.netty.channel.ChannelHandlerAdapter
    • 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
    • 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