Class JavaScriptTemplateEngine
java.lang.Object
org.mockserver.templates.engine.javascript.JavaScriptTemplateEngine
- All Implemented Interfaces:
TemplateEngine
- Author:
- jamesdbloom
-
Constructor Summary
ConstructorsConstructorDescriptionJavaScriptTemplateEngine(MockServerLogger mockServerLogger, Configuration configuration) -
Method Summary
Modifier and TypeMethodDescription<T> TexecuteTemplate(String template, HttpRequest request, Class<? extends DTO<T>> dtoClass) <T> TexecuteTemplate(String template, HttpRequest request, IterationContext iteration, Class<? extends DTO<T>> dtoClass) Load-generation only: execute a JavaScript template with a per-iteration variable (iteration) bound in the script scope.<T> TexecuteTemplate(String template, HttpRequest request, HttpResponse response, Class<? extends DTO<T>> dtoClass) static booleanrenderTemplate(String template, HttpRequest request) Renders a template against the request and returns the raw rendered text, without attempting to deserialize it into anHttpResponse/HttpRequest.renderTemplateText(String template, HttpRequest request) Renders a template against the request and returns the raw rendered text fragment, for use as a streaming payload (an SSE event'sdata, a WebSocket text frame, or a gRPC stream message).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.mockserver.templates.engine.TemplateEngine
renderTemplate
-
Constructor Details
-
JavaScriptTemplateEngine
-
-
Method Details
-
isPolyglotAvailable
public static boolean isPolyglotAvailable() -
executeTemplate
public <T> T executeTemplate(String template, HttpRequest request, Class<? extends DTO<T>> dtoClass) - Specified by:
executeTemplatein interfaceTemplateEngine
-
executeTemplate
public <T> T executeTemplate(String template, HttpRequest request, HttpResponse response, Class<? extends DTO<T>> dtoClass) - Specified by:
executeTemplatein interfaceTemplateEngine
-
executeTemplate
public <T> T executeTemplate(String template, HttpRequest request, IterationContext iteration, Class<? extends DTO<T>> dtoClass) Load-generation only: execute a JavaScript template with a per-iteration variable (iteration) bound in the script scope. Used by the load executor so a JavaScript load-scenario step can vary its output per iteration. Identical toexecuteTemplate(String, HttpRequest, Class)wheniterationis null. -
renderTemplate
Description copied from interface:TemplateEngineRenders a template against the request and returns the raw rendered text, without attempting to deserialize it into anHttpResponse/HttpRequest. Used to template the contents of aFileBodyso an externally stored response body can contain template placeholders. Supported by the text-based engines (Velocity, Mustache).- Specified by:
renderTemplatein interfaceTemplateEngine
-
renderTemplateText
Description copied from interface:TemplateEngineRenders a template against the request and returns the raw rendered text fragment, for use as a streaming payload (an SSE event'sdata, a WebSocket text frame, or a gRPC stream message). UnlikeTemplateEngine.renderTemplate(String, HttpRequest)— which the text-based engines (Velocity, Mustache) support but the JavaScript engine cannot, because a JavaScript template constructs a whole response object — this method is supported by all three engines: the JavaScript engine executes the template'shandle(request)function and coerces its return value to text (a returned string is used verbatim; any other value isJSON.stringify'd). The default delegates toTemplateEngine.renderTemplate(String, HttpRequest)so the text-based engines need no override.- Specified by:
renderTemplateTextin interfaceTemplateEngine- Parameters:
template- the template textrequest- the request context- Returns:
- the rendered text fragment
-