Can I specify a --proxy-all parameter to WireMock to match any web site when recording?

我是研究僧i 提交于 2020-01-04 04:20:07

问题


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.

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

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).

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=*

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.

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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/41049289/can-i-specify-a-proxy-all-parameter-to-wiremock-to-match-any-web-site-when-rec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!