Class GrpcStreamMessageTemplateRenderer

java.lang.Object
org.mockserver.grpc.GrpcStreamMessageTemplateRenderer

public class GrpcStreamMessageTemplateRenderer extends Object
Transport-neutral renderer that turns a GrpcStreamMessage bidi response into the JSON string to emit on the wire, applying optional response templating against the matched inbound gRPC message.

Shared by the HTTP/2 bidi handler (GrpcBidiStreamHandler) and the HTTP/3 bidi handler (Http3GrpcBidiStreamHandler) so templating semantics are identical across transports.

Opt-in, static-preserving: when GrpcStreamMessage.getTemplateType() is null (the default), render(org.mockserver.model.GrpcStreamMessage, java.lang.String) returns GrpcStreamMessage.getJson() verbatim — static (non-template) bidi responses are byte-for-byte unchanged. Templating is only applied when a templateType is explicitly set.

Engine reuse: this reuses the same Velocity / Mustache template engines that the HTTP response-template path uses, via TemplateEngine.renderTemplate(String, HttpRequest). The inbound message JSON is exposed as the request body so a template can echo/derive fields with $!request.body, $jsonPath(...), the built-in helpers, and the scenario helper (so a bidi match can also transition scenario state via $scenario.set(...)). HttpTemplate.TemplateType.JAVASCRIPT is rejected because JavaScript templates construct a full response object rather than a renderable text fragment (mirroring TemplateEngine.renderTemplate's file-body templating restriction).

Engines are created lazily and cached per renderer instance (one renderer per bidi handler / per stream), mirroring HttpResponseTemplateActionHandler's lazy engine caching.

  • Constructor Details

  • Method Details

    • render

      public String render(GrpcStreamMessage message, String inboundJson)
      Returns the JSON to emit for message. If the message has no templateType, the raw GrpcStreamMessage.getJson() is returned unchanged. Otherwise the JSON is rendered as a template against inboundJson (exposed as the request body).
      Parameters:
      message - the configured bidi response message
      inboundJson - the matched inbound gRPC message converted to JSON (may be null)
      Returns:
      the JSON string to encode and write to the stream