Class LoadResponseExtractor

java.lang.Object
org.mockserver.load.LoadResponseExtractor

public final class LoadResponseExtractor extends Object
Shared response-extraction primitives used by both LoadCapture (cross-step correlation) and LoadCheck (per-step response assertions). Factored out so the two features share ONE extraction implementation (JSONPath / header / body-regex / status) rather than each carrying its own copy.

Every method is null-safe and returns null on "nothing to extract" (null response, blank expression, empty body, no match). Callers decide what a null means (a capture falls back to its default; a check treats it as the observed value for its comparator). A malformed JSONPath or regex may still throw — the caller is expected to run these best-effort inside a try/catch so a bad expression never breaks the load dispatch path.

  • Method Details

    • jsonPath

      public static String jsonPath(HttpResponse response, String expression)
      Evaluate expression as a Jayway JSONPath over the response body and render the result as a plain string (see stringifyJsonPath(Object)). Returns null when the response, expression or body is blank.
    • header

      public static String header(HttpResponse response, String name)
      Return the first value of the named response header, or null when the response, name or header value is blank.
    • regexGroup1

      public static String regexGroup1(HttpResponse response, String pattern)
      Match pattern as a regex over the response body string and return capture group 1, or null when there is no match (or no group 1).
    • status

      public static String status(HttpResponse response)
      Return the response status code as a string, or null when absent.
    • stringifyJsonPath

      public static String stringifyJsonPath(Object result)
      Render a JSONPath result as a plain string: a scalar becomes its String.valueOf; a single-element collection (the common definite-path-returning-a-list case) is unwrapped to its element; an empty collection is treated as no match. Mirrors CaptureProcessor.