Reputation: 345
Wiremock proxy stub runs on port 1234 with host http://example.com, but httpURLConnection.getResponseCode() gives connection refused error.
wireMockServer.stubFor(get(urlMatching(".*"))
.willReturn(aResponse().proxiedFrom("http://example.com:1234")));
ConnectionFactory conFac = new ConnectionFactory("http://example.com", 1234);
HttpURLConnection httpURLConnection = conFac.getHttpURLConnection(new URL(new URI("http", null, "http://example.com", 1234, null, null, null).toString()));
httpURLConnection.getResponseCode();
Upvotes: 0
Views: 2473
Reputation: 29
It is 1234 and not 79. Still throws ConectException
WireMockServer wireMockServer = new WireMockServer(wireMockConfig().proxyVia("http://example.com", 1234));
Upvotes: 0
Reputation: 29
WireMockServer wireMockServer = new WireMockServer(wireMockConfig().proxyVia("http://example.com", 79));
Tried proxyVia()... httpURLConnection.getResponseCode(); gives java.net.ConnectException: Connection refused
ConnectionFactory conFac = new ConnectionFactory("http://example.com", 1234);
HttpURLConnection httpURLConnection = conFac.getHttpURLConnection(new URL(new URI("http", null, "http://example.com", 1234, null, null, null).toString()));
httpURLConnection.getResponseCode();
Upvotes: 0
Reputation: 10211
If you want to use WireMock to act as a proxy of http://example.com
, then you missunderstand what proxiedFrom
stand for. It's used for forwarding your request received by your local wiremock server to the other website. For example, you set up wiremock running on localhost:8888
. Then, you set up something like proxiedFrom("example.com")
. As a result, what ever sending to localhost:8888/rooms/{id}
will be forwarding to example.com/rooms/{id}
.
Upvotes: 1