简体   繁体   English

Wiremock bodyFileName 模板

[英]Wiremock bodyFileName templating

I'm using Wiremock to stub out some API calls made by mobile clients.我正在使用 Wiremock 排除移动客户端发出的一些 API 调用。

Struggling to get templated filename from request.努力从请求中获取模板文件名。

Can anyone confirm if this should even work with Wiremock standalone pls?任何人都可以确认这是否应该与 Wiremock 独立 pls 一起使用?

"response": { "status": 200, "bodyFileName": "Account-{{jsonPath request.body '$.user.identity'}}.json”}

I've got static files to be returned fine, just seems like bodyFileName doesn't like templating.我有 static 文件可以正常返回,好像bodyFileName不喜欢模板。

Example:例子:

I configure wm with following Json:我使用以下 Json 配置 wm:

{
    "request": {
        "method" : "GET",
        "url": "/users/D8428899330"
    },
    "response": {
        "status": 200,
        "bodyFileName": "user-{{request.path.[1]}}.json"
    }
}

Then when I attempt the url, http://localhost:9696/users/D8428899330 I get the following error,然后,当我尝试 url、 http://localhost:9696/users/D8428899330 时,出现以下错误,

HTTP ERROR: 500 Problem accessing /users/D8428899330. HTTP 错误:500 访问 /users/D8428899330 时出现问题。 Reason:原因:

java.lang.RuntimeException: java.io.FileNotFoundException: /Users/iainframe/Documents/__files/user-{{request.path.[1]}}.json (No such file or directory) java.lang.RuntimeException: java.io.FileNotFoundException: /Users/iainframe/Documents/__files/user-{{request.path.[1]}}.json (No such file or directory)

Should indicate that the file user-D8428899330.json resides in the correct location as I've hard coded it and it returns it ok.应该表明文件user-D8428899330.json resides正确的位置,因为我已经对其进行了硬编码,并且它返回了它。 The command to start WireMock is:启动 WireMock 的命令是:

 java -jar ~/Documents/wm.jar --port 9696 --global-response-templating --verbose --root-dir /Users/iainframe/Documents/ 

The following response definition works fine for me with Wiremock 2.25.1 using the response template<\/a> transformer.以下响应定义对我使用响应模板<\/a>转换器的 Wiremock 2.25.1 来说效果很好。

  "response": {
     "transformers": ["response-template"],
     "status": 200,
     "bodyFileName": "user-{{jsonPath request.body '$.userid'}}.json" }

Interesting, I was running into the same problem and was able to solve it by starting WireMock with --global-response-templating .有趣的是,我遇到了同样的问题,并且能够通过使用--global-response-templating启动 WireMock 来解决它。 But you are using that parameter too... If it matters, I'm using WireMock 2.33.2.但是您也在使用该参数...如果重要的话,我使用的是 WireMock 2.33.2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM