Class StreamTemplateRenderer

java.lang.Object
org.mockserver.mock.action.http.StreamTemplateRenderer

public class StreamTemplateRenderer extends Object
Shared renderer that templates a single streaming payload (an SSE event's data, a WebSocket text frame, or a gRPC server-stream message) against the triggering request, reusing exactly the same template engines and request/template context (request.*, jsonPath, the built-in helpers, faker and scenario) that HttpResponseTemplateActionHandler uses.

Opt-in, static-preserving: render(HttpTemplate.TemplateType, String, HttpRequest) returns the payload unchanged when templateType is null (the default) — non-templated streaming responses are byte-for-byte unchanged. Templating is applied only when a templateType is explicitly set on the streaming action, and the payload is rendered once per event/message.

Engines: Velocity and Mustache render the payload text directly. JavaScript executes the template's handle(request) function and coerces its return value to text (TemplateEngine.renderTemplateText(String, HttpRequest)); if the GraalJS engine is not on the classpath, a JAVASCRIPT templateType fails loudly with the same clear error the response-template path uses rather than silently degrading. Engines are created lazily and cached per renderer instance, mirroring HttpResponseTemplateActionHandler's lazy engine caching.

  • Constructor Details

  • Method Details

    • render

      public String render(HttpTemplate.TemplateType templateType, String payload, HttpRequest request)
      Renders payload as a response template of the given templateType against request. When templateType or payload is null, the payload is returned unchanged (static — no engine is created).