I am trying to use Wiremocks record and playback feature to record a number of requests. The service I am calling returns different values depending on the headers that are sent in the request so I need the recording to capture the headers. I am using rest-assured to make the api call. Below is the code
WireMockServer proxyingService = new WireMockServer(
wireMockConfig()
.dynamicPort()
.preserveHostHeader(true)
.withRootDirectory(fileRoot.getAbsolutePath()));
FileSource fileSource = new SingleRootFileSource("wiremock");
FileSource filesFileSource = fileSource.child(FILES_ROOT);
FileSource mappingsFileSource = fileSource.child(MAPPINGS_ROOT);
proxyingService.enableRecordMappings(mappingsFileSource, filesFileSource);
proxyingService.start();
proxyingService.startRecording(recordSpec()
.forTarget("https://dev.target.mycompany.com:447/")
.captureHeader("ConsumerID")
.captureHeader("Accept")
.captureHeader("Content-Type")
.extractBinaryBodiesOver(10240)
.extractTextBodiesOver(2048)
.makeStubsPersistent(false)
.ignoreRepeatRequests()
.matchRequestBodyWithEqualToJson(false, true));
requestSpec = new RequestSpecBuilder().setBaseUri("http://localhost:" + proxyingService.port() + "/")
.addFilter(new ResponseLoggingFilter())// log request and response for better debugging. You can also
.addFilter(new RequestLoggingFilter()) // only log if a requests fails.
.build();
request = given()
.spec(requestSpec)
.header("ConsumerID", "ABC")
.header("ContextID", "DEF")
.header("Content-Type", "text/xml; charset=ISO-8859-1")
.contentType("text/xml").body(inputFile);
response = request.post("myapi/endpoint");
proxyingService.stopRecording();
proxyingService.saveMappings();
proxyingService.stop();
When I look in the mappings file though, I do not see any of the request headers
{
"id" : "e5f1d765-ed1c-30ba-ab74-997820a7d9b8",
"request" : {
"url" : "/myapi/endpoint",
"method" : "POST",
"bodyPatterns" : [ {
"equalToXml" : "<?xml version=\"1.0\" encoding=\"UTF-8\"> "
} ]
},
"response" : {
"status" : 201,
"bodyFileName" : "body-ccm-compiler-compile-h2LAO.txt",
"headers" : {
"X-Backside-Transport" : "OK OK,OK OK",
"Connection" : "Keep-Alive",
"Pragma" : "no-cache",
"Expires" : "0",
"Strict-Transport-Security" : "max-age=31536000 ; includeSubDomains",
"Content-Type" : "text/plain",
"Date" : "Fri, 08 Jun 2018 13:00:28 GMT",
}
},
"uuid" : "e5f1d765-ed1c-30ba-ab74-997820a7d9b8"
}
What am I doing wrong?