首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wiremock模板fixedDelayMilliseconds

Wiremock模板fixedDelayMilliseconds
EN

Stack Overflow用户
提问于 2020-09-22 12:31:39
回答 1查看 1.3K关注 0票数 0

我试图在一段延迟之后在wiremock中生成一个响应,其中该延迟是从传入的请求派生的。例如,请求中用户的家庭名称是"delay_10000“,然后延迟10000毫秒,或者delay_20000,然后延迟20000.....

代码语言:javascript
复制
{
  "request": {
    "method": "POST",
    "headers": {
      "SOAPAction": {
        "matches": "http://redacted"
      }
    },
    "bodyPatterns": [
      {
        "matchesXPath": {
          "expression": "//*[local-name()=\"family-name\"]/text()",
          "matches": "^delay_([0-9]+)$"
        }
      }
    ]
  },
  "response": {
    "status": 200,
    "bodyFileName": "verify.xml",
    "fixedDelayMilliseconds": "{{soapXPath request.body 'number(substring-after(//*[local-name()=\"family-name\"]/text(), \"delay_\"))'}}"
  }
}

谁能确认哪些字段能够被模板化。文档建议"response headers and be“,以及其他地方的bodyFileName (我正在工作),但它没有提到是否可以将其他响应字段模板化。

现在我看到的是

代码语言:javascript
复制
2020-09-22 02:43:24.441 Verbose logging enabled
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" com.github.tomakehurst.wiremock.standalone.MappingFileException: Error loading file /home/wiremock/./mappings/equifax_generic_verify_identity_delay.json:
Cannot deserialize value of type `java.lang.Integer` from String "{{soapXPath request.body 'number(substring-after(//*[local-name()="family-name"]/text(), "timeout_"))'}}": not a valid Integer value
    at com.github.tomakehurst.wiremock.standalone.JsonFileMappingsSource.loadMappingsInto(JsonFileMappingsSource.java:121)
    at com.github.tomakehurst.wiremock.core.WireMockApp.loadMappingsUsing(WireMockApp.java:204)
    at com.github.tomakehurst.wiremock.core.WireMockApp.loadDefaultMappings(WireMockApp.java:200)
    at com.github.tomakehurst.wiremock.core.WireMockApp.<init>(WireMockApp.java:103)
    at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:73)
    at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:65)
    at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:134)
stream closed           

首先,我可以看到它被捕获的位置,但不能清楚地看到它被抛出的位置https://github.com/tomakehurst/wiremock/blob/master/src/main/java/com/github/tomakehurst/wiremock/standalone/JsonFileMappingsSource.java#L121

其次,我不清楚我是否只是错误地驱动了wiremock,这不可能通过响应转换器实现,但可以通过扩展和“响应定义转换”(http://wiremock.org/docs/extending-wiremock/)来实现。

我可以通过一组固定的延迟来解决这个问题--但如果它是动态的就更好了

感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2020-09-30 00:03:12

所以我最初的假设是这是不可能的,因为模板的任何使用都将解析为一个字符串,但是fixedDelayMilliseconds需要一个数字,所以WireMock将抛出错误:(

我认为您可以使用自定义转换器来扩展WireMock,它将解析响应正文中的延迟,并将其作为数字添加到响应中。有关更多信息,请查看Extending WireMock文档。编辑:我现在明白了,你已经得出了这个假设。我想你是对的:D --这是最容易通过变压器实现的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64003118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档