WireMock-连接拒绝-Junit5

发布于 2025-01-30 10:50:52 字数 1220 浏览 6 评论 0原文

我有一个可以在/__管理员/__管理员下看到的存根,但是在__admin/requests或__Admin/request/nocted/noteed中进行任何rest呼叫时,我觉得很奇怪。 WireMock无法拦截请求吗?

简化代码:

class MyTestClass {

    @Test
    void testStuff(){
        WireMock.configureFor("localhost", 9050); // Running in docker with custom port
        WireMock.reset();

        stubFor(
            get("/getStuff?include-archived=yes")
                .withPort(<myServicePort>)
                .willReturn(
                    aResponse()
                        .withHeader("Content-Type", "application/json")
                        .withStatus(200)
            )
        );
    }
}

错误:

在以下站点上观察到错误: *__检查点⇢ 请求获取 http:// localhost:&lt; myServiceport&gt;/getStuff?include-archive = yes [DefaultWebClient]

...

[org.springframework.web.servlet.mvc.method.annotation.exceptionhandlerexceptionResolver] :解决 [org.springframework.web.reactive.function.client.webclientrequestexexception: 连接拒绝:没有更多信息: localhost/127.0.0.1:&lt; myServiceport&gt;;嵌套异常是 io.netty.channel.AbstractChannel $ entotatedConnectException:Connection 拒绝:没有更多信息:localhost/127.0.0.1:&lt; myServiceport&gt;]

I have a stub that I can see under /__admin/ but when making any sort of rest calls nothing registers in either __admin/requests or __admin/requests/unmatched which I feel is strange. Is Wiremock failing to intercept the request?

Simplified code:

class MyTestClass {

    @Test
    void testStuff(){
        WireMock.configureFor("localhost", 9050); // Running in docker with custom port
        WireMock.reset();

        stubFor(
            get("/getStuff?include-archived=yes")
                .withPort(<myServicePort>)
                .willReturn(
                    aResponse()
                        .withHeader("Content-Type", "application/json")
                        .withStatus(200)
            )
        );
    }
}

Error:

Error has been observed at the following site(s): *__checkpoint ⇢
Request to GET
http://localhost:<myServicePort>/getStuff?include-archived=yes
[DefaultWebClient]

...

[org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver]
: Resolved
[org.springframework.web.reactive.function.client.WebClientRequestException:
Connection refused: no further information:
localhost/127.0.0.1:<myServicePort>; nested exception is
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection
refused: no further information: localhost/127.0.0.1:<myServicePort>]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海风掠过北极光 2025-02-06 10:50:52

终于找到了这个问题,我试图拦截的端口没有在容器中打开

Finally found the issue, the port that I was trying to intercept wasn't open in the container thus why I got no entries in either __admin/requests or __admin/requests/unmatched

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文