Wiremock proxy record feature - can it replace Host or IP in responses? Like a reverse proxy?

165 views
Skip to first unread message

Nicholas DiPiazza

unread,
Aug 22, 2018, 11:25:58 AM8/22/18
to wiremock-user
Hello wiremock users!

I am recording rest api's with wiremock... in my case for SharePoint.


So I set up a recorder:

java -jar wiremock-standalone-2.18.0.jar


Now I go to http://localhost:8080/__admin/recorder/ and I enable recording for my http://sharepointhost.


Now I make some requests to sharepoint rest apis through http://localhost:8080.


But the rest api responses still reference the http://sharepointhost. So when my program uses the API responses that contain URLs then make new requests based on those URLs, it goes to the actual URL instead of the proxy URL and a huge number of my requests don't get recorded.


Is there a way to turn on some sort of reverse proxy or URL pattern string replace so I can avoid this issue? What is the way to do that in my case? Do I need to use the Java variety of the recorder instead of using the standalone?


I posted this question here too for visibility: https://stackoverflow.com/questions/51960907/wiremock-proxy-record-feature-can-it-replace-host-or-ip-in-responses

Issam Sabir

unread,
Aug 23, 2018, 4:18:22 AM8/23/18
to nicholas...@gmail.com, wiremo...@googlegroups.com
Hi,

Yes. You can launch WireMock as a proxy with automatic record mode. The command you need is this:

java -jar wiremock-standalone-2.18.0.jar --port 8787 --print-all-network-traffic --verbose  --enable-browser-proxying  --record-mappings

The important params there are **enable-browser-proxying** and **record-mappings**

The proxy is running on port 8787 and you have to configure your browser to use proxy localhost:8787

Now you can browse any web site, and all the trafic will be recorded


--
You received this message because you are subscribed to the Google Groups "wiremock-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wiremock-use...@googlegroups.com.
To post to this group, send email to wiremo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/wiremock-user/4259fcae-b57d-4a61-9f8e-205d788fcf09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Cordialement, Issam Sabir.
06 61 54 39 77

Tom Akehurst

unread,
Aug 23, 2018, 6:05:00 AM8/23/18
to wiremock-user
Issam - I wouldn't recommend what you suggested as this is the legacy record feature and it won't rewrite URLs in payloads.

Nicholas - there isn't a super easy way to fix this unfortunately. Either you need to post process the recordings, which you can do by manipulating the files, calling the HTTP API or the Java DSL, or you can write a stub mapping transformer that manipulates the URLs as the recording happens.

I agree this is an obvious use case and there should be a built in transformer for it. Like everything, time constraints...

Reply all
Reply to author
Forward
0 new messages