Class WasmResponseShaper

java.lang.Object
org.mockserver.wasm.WasmResponseShaper

public class WasmResponseShaper extends Object
Applies a WASM module's optional shape_response export to the response a matched expectation would return, enabling WASM-computed dynamic responses (ABI v3).

Fail-safe. Shaping is best-effort and never fails a request: any trap, oversized or out-of-bounds return, or invalid JSON from the module leaves the materialised response untouched and logs a single WARN per module (subsequent failures of the same module are silent, so a broken module cannot flood the log). A module that does not export shape_response, or that returns 0 (opt out), is a no-op with no log.

Apply semantics. The module returns a possibly-partial response {statusCode?, headers?, body?}: a present statusCode replaces the status; each entry in a present headers object is merged in (overwriting a same-named header, adding new ones, leaving unmentioned headers intact); a present, non-null body replaces the body. Absent fields leave the corresponding response part unchanged.

  • Constructor Details

    • WasmResponseShaper

      public WasmResponseShaper(MockServerLogger mockServerLogger)
  • Method Details

    • shape

      public void shape(HttpResponse response, HttpRequest request, String moduleName, byte[] wasmBytes)
      Shape response in place using the module's shape_response export, if any. A no-op (leaving response unchanged) when the module does not shape, opts out, or fails.
      Parameters:
      response - the materialised response to (possibly) rewrite — mutated in place
      request - the matched request (exposed to the module under the envelope's request)
      moduleName - the WASM module name (used for the once-per-module warning key)
      wasmBytes - the module bytes
    • resetWarnings

      public static void resetWarnings()
      Clear the once-per-module warning dedup. Intended for tests that assert warn-once behaviour across separate cases; not used on the request path.