Class GrpcStreamMessageTemplateRenderer
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 Summary
ConstructorsConstructorDescriptionGrpcStreamMessageTemplateRenderer(MockServerLogger mockServerLogger, Configuration configuration) -
Method Summary
Modifier and TypeMethodDescriptionrender(GrpcStreamMessage message, String inboundJson) Returns the JSON to emit formessage.
-
Constructor Details
-
GrpcStreamMessageTemplateRenderer
public GrpcStreamMessageTemplateRenderer(MockServerLogger mockServerLogger, Configuration configuration)
-
-
Method Details
-
render
Returns the JSON to emit formessage. If the message has notemplateType, the rawGrpcStreamMessage.getJson()is returned unchanged. Otherwise the JSON is rendered as a template againstinboundJson(exposed as the request body).- Parameters:
message- the configured bidi response messageinboundJson- the matched inbound gRPC message converted to JSON (may benull)- Returns:
- the JSON string to encode and write to the stream
-