Package org.mockserver.imports
Class HarImporter
java.lang.Object
org.mockserver.imports.HarImporter
Imports expectations from HAR (HTTP Archive) format JSON files.
For each entry in log.entries[], builds a request matcher (method + path + query
string parameters) and a response (status, filtered headers, body). The generated matchers
are intentionally permissive: volatile headers (Date, Set-Cookie, etc.) are excluded from
request matching, and request body matching is only applied when postData.text is
present and reasonably sized.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionimportExpectations(String harJson) Parses a HAR JSON string and returns one expectation per entry, with sensitive headers and body fields redacted (seeImportRedaction).importExpectations(String harJson, ImportRedaction.Options redactionOptions) Parses a HAR JSON string and returns one expectation per entry, applying the supplied redaction options before the expectations are returned.
-
Constructor Details
-
HarImporter
public HarImporter()
-
-
Method Details
-
importExpectations
Parses a HAR JSON string and returns one expectation per entry, with sensitive headers and body fields redacted (seeImportRedaction). Captured HAR files routinely contain realAuthorization/API-key headers and secret body fields, so redaction is on by default.- Parameters:
harJson- the HAR document as a JSON string- Returns:
- the generated expectations (may be empty if there are no entries)
- Throws:
IllegalArgumentException- if the JSON is null, blank, or not a valid HAR
-
importExpectations
public List<Expectation> importExpectations(String harJson, ImportRedaction.Options redactionOptions) Parses a HAR JSON string and returns one expectation per entry, applying the supplied redaction options before the expectations are returned.- Parameters:
harJson- the HAR document as a JSON stringredactionOptions- controls whether/how sensitive data is masked; passImportRedaction.Options.disabled()to keep imported values verbatim- Returns:
- the generated expectations (may be empty if there are no entries)
- Throws:
IllegalArgumentException- if the JSON is null, blank, or not a valid HAR
-