Package org.mockserver.grpc.connect
Class ConnectUnaryDetector
java.lang.Object
org.mockserver.grpc.connect.ConnectUnaryDetector
Detects Connect protocol (buf.build Connect) unary requests and, when a proto descriptor is
loaded, validates the request message JSON against the method's input type.
Connect unary requests are distinguished from gRPC by content type and shape:
- gRPC uses
application/grpc(andapplication/grpc-web*) with length-prefixed framing over HTTP/2 — handled by the existing gRPC pipeline. - Connect unary is a plain HTTP
POSTto a/package.Service/Method-shaped path withContent-Type: application/json(orapplication/proto) and the request message as the body directly (no framing).
application/grpc* content type,
so real gRPC traffic can never be misclassified as Connect.
This is a pure helper. Connect unary requests are already ordinary HTTP requests that flow through MockServer's normal expectation matching; this class only supports optional descriptor-aware validation/conversion of the request body.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisConnectContentType(String contentType) A Connect unary content type is JSON or proto.static booleanisConnectUnary(String method, String contentType, String path) Returns true if the given method/content-type/path looks like a Connect unary request: aPOSTto a two-segment/Service/Methodpath with a JSON or proto content type that is not a gRPC content type.static booleanisServiceMethodPath(String path) A gRPC/Connect method path has the shape/package.Service/Method— exactly two non-empty segments where the service segment contains a.package separator.static String[]parseServiceMethod(String path) Splits a/package.Service/Methodpath into[service, method].static ConnectErrorvalidateRequestBody(GrpcProtoDescriptorStore descriptorStore, String path, String json) If a descriptor is loaded for this method, validates that the request JSON parses against the method's input message type.
-
Method Details
-
isConnectUnary
Returns true if the given method/content-type/path looks like a Connect unary request: aPOSTto a two-segment/Service/Methodpath with a JSON or proto content type that is not a gRPC content type. -
isConnectContentType
A Connect unary content type is JSON or proto. (The Connect "GET-side" unary variant and compressed/streaming content types are deliberately out of scope.) -
isServiceMethodPath
A gRPC/Connect method path has the shape/package.Service/Method— exactly two non-empty segments where the service segment contains a.package separator. -
parseServiceMethod
Splits a/package.Service/Methodpath into[service, method]. Returns["", ""]for a malformed path. -
validateRequestBody
public static ConnectError validateRequestBody(GrpcProtoDescriptorStore descriptorStore, String path, String json) If a descriptor is loaded for this method, validates that the request JSON parses against the method's input message type. Returnsnullwhen valid (or when no descriptor is loaded — validation is best-effort and never blocks a plain-HTTP mock), or aConnectErrorwith codeinvalid_argumentdescribing the parse failure.
-