我试图在延迟后在wiremock中生成响应,该延迟来自传入的请求。例如,请求中用户的姓氏是“delay_10000”然后延迟 10000 毫秒,或者 delay_20000 然后延迟 20000 ......
{
"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_\"))'}}"
}
}
任何人都可以确认哪些字段可以被模板化。doco 建议“响应标头和正文”,以及其他地方的 bodyFileName (我有工作),但它没有说明其他响应字段是否可以模板化。
目前我看到
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。爪哇#L121
其次,我不清楚我是否只是错误地驱动了wiremock,这不可能通过响应转换器实现,但可以通过扩展和“响应定义转换”(http://wiremock.org/docs/extending -wiremock/ )
我可以用一组固定的延迟来解决这个问题——但如果它是动态的会更好
帮助表示赞赏!