Class ConnectResponse

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

public class ConnectResponse extends Object
Convenience factory for Connect protocol (buf.build Connect) unary responses.

Connect unary RPCs are ordinary HTTP POSTs to /package.Service/Method carrying the request message directly (JSON or proto, not gRPC length-prefixed framing). Because they are plain HTTP, MockServer's normal expectation matching already handles them — a user can mock a Connect unary call with a standard httpRequest/httpResponse expectation. These helpers exist only for convenience and correctness:

  • success(String) sets the application/json content type expected by Connect clients on a 200 response whose body is the response message directly.
  • error(ConnectError) builds the non-200 Connect error envelope ({"code","message","details"}) with the HTTP status mapped from the Connect error code per the Connect spec.
No new action type, pipeline handler, or serialization wiring is required: the helpers return a plain HttpResponse, so all existing response infrastructure (delays, headers, verification, the dashboard, DTO serialization) works unchanged, and real gRPC (application/grpc) traffic is completely unaffected.
  • Field Details

  • Method Details

    • success

      public static HttpResponse success(String messageJson)
      A successful Connect unary response: HTTP 200, Content-Type: application/json, body is the response message JSON directly (no envelope, no framing).
    • success

      public static HttpResponse success(String body, String contentType)
      A successful Connect unary response with an explicit content type, e.g. CONNECT_PROTO_CONTENT_TYPE. The body is passed through verbatim.
    • error

      public static HttpResponse error(ConnectError error)
      A Connect unary error response: a non-200 HTTP status mapped from the Connect error code, with a JSON body of the shape {"code","message","details"} and Content-Type: application/json.
    • error

      public static HttpResponse error(ConnectError.Code code, String message)
      Shorthand for error(ConnectError) from a ConnectError.Code and message.