Class HttpContractRecorder

java.lang.Object
com.shaft.tools.io.internal.HttpContractRecorder

public final class HttpContractRecorder extends Object
Thread-local HTTP contract recorder, validator, and browser replay rule factory.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
     
    static final record 
     
    static final record 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    browserReplayRules(String contractFilePath)
    Builds browser replay rules from a recorded contract.
    static void
    Clears current-thread recording and validation state without writing files.
    static void
    handleApiExchange(io.restassured.specification.FilterableRequestSpecification requestSpec, io.restassured.response.Response response)
    Records or validates a SHAFT API HTTP exchange when a contract mode is active.
    static void
    handleBrowserExchange(org.openqa.selenium.remote.http.HttpRequest request, org.openqa.selenium.remote.http.HttpResponse response, String failureReason)
    Records or validates a browser HTTP exchange when a contract mode is active.
    static boolean
    Returns whether browser interception must actively fetch responses for contract work.
    static boolean
    Reports whether a request/response/header/query/JSON-body key is configured as sensitive (see shaft.contract.sensitiveKeys).
    static boolean
    Reports whether a request/response/header/query/JSON-body key is configured as volatile (see shaft.contract.volatileKeys).
    static boolean
    Reports whether a raw string value looks volatile (a UUID or an ISO-8601 instant), regardless of its key name.
    static void
    startAssertMode(String contractFilePath, String... urlContains)
    Starts hard-assert contract validation for current-thread browser and SHAFT API traffic.
    static void
    startRecording(String contractFilePath, String... urlContains)
    Starts recording current-thread browser and SHAFT API HTTP traffic.
    static void
    startVerifyMode(String contractFilePath, String... urlContains)
    Starts soft-verify contract validation for current-thread browser and SHAFT API traffic.
    static void
    Writes the current recording session and clears it.
    static void
    Clears current-thread validation mode.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • startRecording

      public static void startRecording(String contractFilePath, String... urlContains)
      Starts recording current-thread browser and SHAFT API HTTP traffic.
      Parameters:
      contractFilePath - destination JSON contract path
      urlContains - optional URL fragments used to select traffic
    • stopRecording

      public static void stopRecording()
      Writes the current recording session and clears it.
    • startAssertMode

      public static void startAssertMode(String contractFilePath, String... urlContains)
      Starts hard-assert contract validation for current-thread browser and SHAFT API traffic.
      Parameters:
      contractFilePath - source JSON contract path
      urlContains - optional URL fragments used to select traffic
    • startVerifyMode

      public static void startVerifyMode(String contractFilePath, String... urlContains)
      Starts soft-verify contract validation for current-thread browser and SHAFT API traffic.
      Parameters:
      contractFilePath - source JSON contract path
      urlContains - optional URL fragments used to select traffic
    • stopValidation

      public static void stopValidation()
      Clears current-thread validation mode.
    • clear

      public static void clear()
      Clears current-thread recording and validation state without writing files.
    • isBrowserContractModeActive

      public static boolean isBrowserContractModeActive()
      Returns whether browser interception must actively fetch responses for contract work.
      Returns:
      true when recording or validation is active
    • handleBrowserExchange

      public static void handleBrowserExchange(org.openqa.selenium.remote.http.HttpRequest request, org.openqa.selenium.remote.http.HttpResponse response, String failureReason)
      Records or validates a browser HTTP exchange when a contract mode is active.
      Parameters:
      request - browser request
      response - browser response
      failureReason - optional failure reason
    • handleApiExchange

      public static void handleApiExchange(io.restassured.specification.FilterableRequestSpecification requestSpec, io.restassured.response.Response response)
      Records or validates a SHAFT API HTTP exchange when a contract mode is active.
      Parameters:
      requestSpec - REST Assured request spec
      response - REST Assured response
    • browserReplayRules

      public static List<BrowserNetworkInterceptionRule> browserReplayRules(String contractFilePath)
      Builds browser replay rules from a recorded contract.
      Parameters:
      contractFilePath - source JSON contract path
      Returns:
      replay rules that return recorded responses
    • isSensitiveKey

      public static boolean isSensitiveKey(String key)
      Reports whether a request/response/header/query/JSON-body key is configured as sensitive (see shaft.contract.sensitiveKeys). Exposed for reuse by other contract-aware consumers (e.g. com.shaft.capture.generate.api.ResponseNormalizer) that need the exact same sensitive-key detection this class uses for contract redaction.
      Parameters:
      key - request/response/header/query/JSON-body key
      Returns:
      true when the key matches a configured sensitive fragment
    • isVolatileKey

      public static boolean isVolatileKey(String key)
      Reports whether a request/response/header/query/JSON-body key is configured as volatile (see shaft.contract.volatileKeys). Exposed for reuse by other contract-aware consumers that need the exact same volatile-key detection this class uses for contract normalization.
      Parameters:
      key - request/response/header/query/JSON-body key
      Returns:
      true when the key matches a configured volatile name
    • isVolatileValue

      public static boolean isVolatileValue(String rawValue)
      Reports whether a raw string value looks volatile (a UUID or an ISO-8601 instant), regardless of its key name. Exposed for reuse by other contract-aware consumers.
      Parameters:
      rawValue - candidate value
      Returns:
      true when the value matches a UUID or a parseable Instant