reverse proxy stub mapping in WireMock

864 views
Skip to first unread message

kv

unread,
Feb 7, 2016, 5:37:35 AM2/7/16
to wiremock-user

Hi


This is from wiremock site:


"The following code will proxy all GET requests made to http://:/other/service/.* to http://otherservice.com/approot,"

but i want opposite of this

The following code should proxy all GET requests made to http://realsite.com/approot to http://local:/other/service and send the mock response

And also I should be able to programmatically disable such proxying. This way i can run my tests code against mock response and real response by passing flag.


Is it possible in WireMock. Anyother mocking solution in Java that meets this requirement?

somthing silimar to nock nodjs module (https://github.com/pgte/nock)


Thanks in advance.


KV

Tom Akehurst

unread,
Feb 7, 2016, 4:44:30 PM2/7/16
to wiremock-user
Do you mean you'd like forward, rather than reverse proxying?

You can do this by enabling browser proxying (see CLI/Java options) and pointing your browser/HTTP client proxy settings at it. By default it'll proxy everything, but it'll give priority to stubs you've configured so you can selectively stub responses.
Message has been deleted

kv

unread,
Feb 7, 2016, 10:30:15 PM2/7/16
to wiremock-user
You are right "reverse proxy" isn't a right word here. I would like to forward call to real site to wiremock server and run mock tests, and on demand I can disable the foward so that tests run on real site. Nock has the feature by design. Can it be added as a feature in Wiremock?. I dont want to do proxying outside the program.

Tom Akehurst

unread,
Feb 8, 2016, 4:00:51 AM2/8/16
to wiremock-user
Ok, I think I see - you want to reverse proxy by default but serve a stub in specific cases. See the Proxy/Intercept section of the docs to learn how to do this.

kv

unread,
Feb 8, 2016, 6:50:36 AM2/8/16
to wiremock-user
Thanks Tom. I think , I got it. With high priority i can stub and with low priority i can forward to real site. I may need to write a wrapper or helper though around this feature . Let me try.

dsch...@sovrn.com

unread,
Feb 9, 2017, 9:10:39 AM2/9/17
to wiremock-user
Hey kv

Were you able to get working the ability to intercept with the mock calls to an external service using Tom's suggested Proxy/Intercept approach?
So to be clear, my app makes calls to an external services like googleapis.com.  I want to selectively intercept that call with a WireMock so that I can fake the response returned to the external service.
It would be awesome if you could share a code example!

Thanks,
Dan
Reply all
Reply to author
Forward
0 new messages