Class RecordedTrafficImporter
RecordedRequestsFileSystemPersistence.
The archive is newline-delimited JSON — one serialized HttpRequestAndHttpResponse per
line (see persistRecordedRequestsToDisk). This importer parses each non-blank line back
into an HttpRequestAndHttpResponse using the same HttpRequestAndHttpResponseSerializer
that produced it, so the format round-trips. Unlike HarImporter /
PostmanCollectionImporter (which build expectations), the imported pairs are re-injected
into the event log as recorded exchanges and become retrievable exactly like in-memory recordings.
Crash-tolerant. A malformed line is skipped and counted, not fatal —
the write path flushes line + "\n" per exchange, so a hard kill can leave a truncated
mid-JSON final line. Aborting the whole import on that one artefact would defeat the crash-recovery
guarantee, so this importer returns every intact exchange and reports how many lines it skipped. It
only throws when the input contains non-blank lines but none parse (i.e. the body is not a
recorded-traffic archive at all). Blank/empty input yields an empty result (0 imported).
Redaction is on by default (see ImportRedaction) as a defence-in-depth
re-mask; the persist side already masks secrets on write when mockserver.redactSecretsInLog
is enabled.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classOutcome of a recorded-traffic re-import: the intact pairs plus a count of NDJSON lines that could not be parsed (malformed or truncated) and were skipped. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionimportRecordedTraffic(String ndjson) Parse an NDJSON recorded-traffic archive with redaction enabled (the default).importRecordedTraffic(String ndjson, ImportRedaction.Options redactionOptions) Parse an NDJSON recorded-traffic archive, applying the supplied redaction options.
-
Constructor Details
-
RecordedTrafficImporter
-
-
Method Details
-
importRecordedTraffic
Parse an NDJSON recorded-traffic archive with redaction enabled (the default).- Parameters:
ndjson- the archive content — oneHttpRequestAndHttpResponseJSON object per line- Returns:
- the parsed pairs and skipped-line count
- Throws:
IllegalArgumentException- only when the input has non-blank lines but none parse
-
importRecordedTraffic
public RecordedTrafficImporter.Result importRecordedTraffic(String ndjson, ImportRedaction.Options redactionOptions) Parse an NDJSON recorded-traffic archive, applying the supplied redaction options. Malformed or truncated lines (e.g. the final line left half-written by a crash) are skipped and counted rather than aborting the whole import; see the class javadoc.- Parameters:
ndjson- the archive content — oneHttpRequestAndHttpResponseJSON object per lineredactionOptions- controls whether/how sensitive data is masked; passImportRedaction.Options.disabled()to keep values verbatim- Returns:
- the parsed pairs and skipped-line count (both zero for blank/empty input)
- Throws:
IllegalArgumentException- only when the input has non-blank lines but none parse
-