当前位置:  开发笔记 > 运维 > 正文

初始化WireMock HTTP服务器时出现HttpHostConnectException

如何解决《初始化WireMockHTTP服务器时出现HttpHostConnectException》经验,为你挑选了0个好方法。

我正在尝试测试对HTTP服务器具有基础GET调用的代码。

我正在尝试使用WireMock,并基于“入门”,我有以下代码:

@Rule
public WireMockRule wireMockRule = 
    new WireMockRule(WireMockConfiguration.wireMockConfig().port(8888)); // No-args constructor defaults to port 8080

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

@Test
public void testGetRanking() throws Exception {
    Fetcher fetcher = new Fetcher("http://localhost:8888",null);
    int rankinganking = fetcher.getRanking("Max");
    Assert.assertEquals(1, ranking);
}

运行测试时,我得到以下堆栈跟踪:

wiremock.org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1] failed: Connection refused
at wiremock.org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
at wiremock.org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at wiremock.org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at wiremock.org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
...

该错误涉及端口8080,但我将端口配置为8888。我知道默认情况下WireMock以端口8080开头,因此这可能是其内部配置存在问题。

这是什么问题?

推荐阅读
ERIK又
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有