我可以在录制时为 WireMock 指定 --proxy-all 参数以匹配任何网站吗? [英] Can I specify a --proxy-all parameter to WireMock to match any web site when recording?

查看:64
本文介绍了我可以在录制时为 WireMock 指定 --proxy-all 参数以匹配任何网站吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个代理服务,以使用 WireMock 记录和播放来自网络的响应.我最近发现这两种模式是分开的,所以我试图构建一小组Docker容器来运行这些服务并行.

I am building a proxy service to record and play responses from the web using WireMock. I have recently discovered that these two modes are separate, so am attempting to build a small set of Docker containers to run these services in parallel.

简而言之,我的计划是设置一个 WireMock 用于录制,然后有另一个实例(在不同的端口上)用于播放.我会定期在 cron 上将映射从一个复制到另一个,然后将重置 API 调用发送到播放实例以重新加载新定义.

Briefly, my plan is to set up one WireMock for recording, and then have another instance (on a different port) for playback. I'll periodically copy the mappings from one to the other on a cron, and then send the reset API call to the playback instance to reload new definitions.

所以,我目前正在研究录音机.从特定站点进行记录的一种简单方法是:

So, I am working on the recorder presently. An easy way to record from a specific site is to do this:

java -jar wiremock-standalone-2.4.1.jar \
    --port 8080 \
    --proxy-all="http://www.example.com/" \
    --record-mappings \
    --verbose

然而,这会将长时间运行的实例锁定到 www.example.com,而实际上我希望它记录我发送给它的任何内容.使用不带参数的 --proxy-all 不起作用(这会导致 HTTP 客户端出现 500 个错误,大概是由 WireMock 本身发出的).

However, that locks a long-running instance to www.example.com, when in fact I want it to record anything I send to it. Using --proxy-all without a parameter does not work (it results in 500 errors in the HTTP client, presumably emitted by WireMock itself).

另一方面,省略 --proxy-all 会导致 404,因为大概 WireMock 不知道去哪里.因此,我想做类似的事情:

Omitting --proxy-all on the other hand results in a 404, since presumably WireMock does not know where to go. I would therefore like to do something like:

--proxy-all=*

我看不到任何文档说命令行支持此功能,所以我想知道管理 API 是否支持此功能?替代方案是我构建自己的 API 以在指定的代理 URL 上停止和重新启动 WireMock,但如果已经实现了,我宁愿不重新发明轮子.

I can't see any docs to say this is supported on the command line, so I wonder if the admin API supports this? The alternative is for me to build my own API to stop and restart WireMock on a specified proxy URL, but if that is already implemented I would rather not re-invent the wheel.

正如我在我的另一个问题中所说,使用 Mountebank 可能是一种选择,因为 似乎有一个 API 用于此.然而,这看起来更复杂,而且由于我使用 WireMock 完成了 90% 的工作,所以如果可以的话,我想坚持下去.

As I said on my other question, using Mountebank instead may be an option, since it seems to have an API for this. However that looks more involved, and since I am 90% of the way there with WireMock, I am minded to stick with it if I can.

推荐答案

我已经解决了这个问题,方法是在 Supervisor 的 shell 包装器中使用自动重启选项运行 WireMock,然后调用 /__admin/shutdown 在 API 上.

I have resolved this by running WireMock in a shell wrapper in Supervisor with an auto-restart option, and then calling /__admin/shutdown on the API.

外壳包装器使用 --proxy-all 开关使用代理目标集启动 WireMock.因此,当它关闭时,代理目标会随着它自动恢复而有效更改.

The shell wrapper starts WireMock using a proxy target set using the --proxy-all switch. Thus when it shuts down the proxy target is effectively changed as it comes back up automatically.

这篇关于我可以在录制时为 WireMock 指定 --proxy-all 参数以匹配任何网站吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆