Package org.mockserver.grpc
Class GrpcServerReflectionHandler
java.lang.Object
org.mockserver.grpc.GrpcServerReflectionHandler
Handles gRPC Server Reflection requests without a generated proto stub.
Decodes
ServerReflectionRequest and encodes ServerReflectionResponse
manually using protobuf's CodedInputStream/CodedOutputStream,
mirroring the approach used by GrpcHealthCheckHandler.
Supports both the v1 and v1alpha reflection service paths:
/grpc.reflection.v1.ServerReflection/ServerReflectionInfo/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo
Canonical field numbers (from grpc/reflection/v1/reflection.proto)
ServerReflectionRequest:field 1 = host (string) field 3 = file_by_filename (string) [oneof message_request] field 4 = file_containing_symbol (string) [oneof message_request] field 7 = list_services (string) [oneof message_request]ServerReflectionResponse:
field 1 = valid_host (string) field 2 = original_request (ServerReflectionRequest) field 4 = file_descriptor_response (FileDescriptorResponse) [oneof message_response] field 6 = list_services_response (ListServiceResponse) [oneof message_response]FileDescriptorResponse:
field 1 = file_descriptor_proto (repeated bytes)ListServiceResponse:
field 1 = service (repeated ServiceResponse)ServiceResponse:
field 1 = name (string)
Limitation
The current gRPC path in MockServer is buffered-unary: each HTTP/2 request carries
exactly one gRPC message. This implementation therefore handles a single
ServerReflectionRequest per HTTP/2 request, which is sufficient for tools
like grpcurl list and single symbol/file lookups. Fully-interactive
bidi-streaming reflection (a long-lived stream with multiple back-and-forth messages)
is not supported by the buffered pipeline.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]grpcFrame(byte[] proto) Wraps a protobuf message in a gRPC frame (5-byte header: 1 byte compression flag + 4-byte big-endian message length).byte[]handleReflectionRequest(byte[] grpcFramedBody) Processes a gRPC-framedServerReflectionRequestand returns a gRPC-framedServerReflectionResponse.static booleanisReflectionPath(String path) Static variant ofisReflectionRequest(String)for use from routing code that does not hold a handler instance.booleanisReflectionRequest(String path) Returnstrueif the given path matches either the v1 or v1alpha gRPC Server Reflection method path.
-
Field Details
-
REFLECTION_V1_PATH
- See Also:
-
REFLECTION_V1ALPHA_PATH
- See Also:
-
REQ_HOST_FIELD
public static final int REQ_HOST_FIELD- See Also:
-
REQ_FILE_BY_FILENAME_FIELD
public static final int REQ_FILE_BY_FILENAME_FIELD- See Also:
-
REQ_FILE_CONTAINING_SYMBOL_FIELD
public static final int REQ_FILE_CONTAINING_SYMBOL_FIELD- See Also:
-
REQ_LIST_SERVICES_FIELD
public static final int REQ_LIST_SERVICES_FIELD- See Also:
-
RESP_VALID_HOST_FIELD
public static final int RESP_VALID_HOST_FIELD- See Also:
-
RESP_FILE_DESCRIPTOR_RESPONSE_FIELD
public static final int RESP_FILE_DESCRIPTOR_RESPONSE_FIELD- See Also:
-
RESP_LIST_SERVICES_RESPONSE_FIELD
public static final int RESP_LIST_SERVICES_RESPONSE_FIELD- See Also:
-
FDR_FILE_DESCRIPTOR_PROTO_FIELD
public static final int FDR_FILE_DESCRIPTOR_PROTO_FIELD- See Also:
-
LSR_SERVICE_FIELD
public static final int LSR_SERVICE_FIELD- See Also:
-
SR_NAME_FIELD
public static final int SR_NAME_FIELD- See Also:
-
-
Constructor Details
-
GrpcServerReflectionHandler
-
-
Method Details
-
isReflectionRequest
Returnstrueif the given path matches either the v1 or v1alpha gRPC Server Reflection method path. -
isReflectionPath
Static variant ofisReflectionRequest(String)for use from routing code that does not hold a handler instance. -
handleReflectionRequest
public byte[] handleReflectionRequest(byte[] grpcFramedBody) Processes a gRPC-framedServerReflectionRequestand returns a gRPC-framedServerReflectionResponse.- Parameters:
grpcFramedBody- the raw gRPC-framed request bytes (5-byte header + protobuf)- Returns:
- gRPC-framed response bytes
-
grpcFrame
public static byte[] grpcFrame(byte[] proto) Wraps a protobuf message in a gRPC frame (5-byte header: 1 byte compression flag + 4-byte big-endian message length).
-