Wiremock记录不保存请求标头

时间:2018-06-08 13:49:50

标签: java wiremock

我正在尝试使用Wiremocks记录和回放功能来记录大量请求。我正在调用的服务返回不同的值,具体取决于请求中发送的标头,因此我需要录制来捕获标头。我正在使用放心的api电话。 以下是代码

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();

当我查看映射文件时,我没有看到任何请求标题

 {
  "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"
}

我做错了什么?

0 个答案:

没有答案