wiremock.org.apache.http.conn.HttpHostConnectException

2,021 views
Skip to first unread message

Hina Verma

unread,
Jan 5, 2016, 4:26:35 AM1/5/16
to wiremock-user
Following is the code snippet, this is running fine in my local but when I configure it using Jenkins it is failing every time, irrespective of the port i provide, what I am doing wrong? Please suggest
@Rule
public WireMockRule wireMockRule = 
    new WireMockRule(WireMockConfiguration.wireMockConfig().port(8888)); // No-args constructor defaults to port 8080

@Before
public void setUp(){
    stubFor(get(urlEqualTo("/Path/Get"))
            .willReturn(aResponse()
                    .withStatus(200)
                    .withBody("[1]")));
}

I have configured wiremock rule on 8888 port, have defined all the stub in the @Before method, I have configured @Test which is hitting the external service with the url http://localhost:8888//Path/Get
Every time I am getting this error Connect to localhost:8888 [localhost/127.0.0.1, localhost/127.0.0.1] failed: Connection refused
wiremock.org.apache.http.conn.HttpHostConnectException: Connect to
 localhost:8888 [localhost/127.0.0.1, localhost/127.0.0.1] failed: 
Connection refused
 - Hina

Tom Akehurst

unread,
Jan 5, 2016, 3:48:11 PM1/5/16
to wiremock-user
I suggest using wireMockRule.stubFor(...) as this goes direct rather than via http.

Hina

unread,
Jan 5, 2016, 9:35:43 PM1/5/16
to Tom Akehurst, wiremock-user
Thanks for your reply, when I tried using wireMockRule.stubFor(...) than it gives connect refused error, might be because the stub didn't match the url I am forming http://localist:8888/get/*****

I will try using it without http and host or port and will update

Thanks

> On 6 Jan 2016, at 02:18, Tom Akehurst <t.m.ak...@googlemail.com> wrote:
>
> I suggest using wireMockRule.stubFor(...) as this goes direct rather than via http.
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "wiremock-user" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/wiremock-user/01zZb4coKv4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to wiremock-use...@googlegroups.com.
> To post to this group, send an email to wiremo...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/wiremock-user/f3ae70cc-5322-46e7-a7d4-db69a186ffd3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jets_Hina

unread,
Jan 6, 2016, 2:35:19 AM1/6/16
to wiremock-user
I tried using wireMockRule.stubFor(...) it is giving the below error:
java.net.ConnectException: Connection refused

I am forming the url - http://localhost:8085 while I go and connect to call the external webservice
I am using the below code to connect, please see the comments where it is failing
String url = Env.url + "/GET/WSResults"; // http://localhost:8085/GET/WSResults;
url = new URL(urlLink);// If I don't put http:// it fails here and gives malformed url exception
uri = new URI(url.getProtocol(), null, url.getHost(),url.getPort(), url.getPath(), url.getQuery(), null);
Client client = Client.create();
WebResource webResource = client.resource(uri); // this is failing as its unable to call the wiremock and trying to connect the external webservice at my localhost:8085, whereas it should replace this with the wiremock result.
ClientResponse response = webResource.get(ClientResponse.class);
result = response.getEntity(String.class);

Please let me know when I am using wireMockRule.stubFor("/GET/WSResults") what should be my url for the external service so that it matches with the stub and without any exception replace external webservice result with my wiremock stub result.

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