Class ConnectUnaryDetector

java.lang.Object
org.mockserver.grpc.connect.ConnectUnaryDetector

public class ConnectUnaryDetector extends Object
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 (and application/grpc-web*) with length-prefixed framing over HTTP/2 — handled by the existing gRPC pipeline.
  • Connect unary is a plain HTTP POST to a /package.Service/Method-shaped path with Content-Type: application/json (or application/proto) and the request message as the body directly (no framing).
Detection is deliberately conservative: it never matches an 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 Details

    • isConnectUnary

      public static boolean isConnectUnary(String method, String contentType, String path)
      Returns true if the given method/content-type/path looks like a Connect unary request: a POST to a two-segment /Service/Method path with a JSON or proto content type that is not a gRPC content type.
    • isConnectContentType

      public static boolean isConnectContentType(String contentType)
      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

      public static boolean isServiceMethodPath(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.
    • parseServiceMethod

      public static String[] parseServiceMethod(String path)
      Splits a /package.Service/Method path 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. Returns null when valid (or when no descriptor is loaded — validation is best-effort and never blocks a plain-HTTP mock), or a ConnectError with code invalid_argument describing the parse failure.