【问题标题】:Spring WebClient - IllegalStateException - The underlying HTTP client completed without emitting a responseSpring WebClient - IllegalStateException - 底层 HTTP 客户端完成但未发出响应
【发布时间】:2022-08-19 02:48:25
【问题描述】:

下面是我的代码:

public static void main(String[] args) {
        TcpClient tcpClient = TcpClient.create()
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 100_000)
                .proxy(p ->
                        p.type(ProxyProvider.Proxy.HTTP)
                        .host(\"myServerHost.com\")
                                .port(8080))
                .doOnConnected ( connection ->
                                    connection.addHandlerLast(new ReadTimeoutHandler(60000, TimeUnit.MILLISECONDS))
                                            .addHandlerLast(new ReadTimeoutHandler(60000, TimeUnit.MILLISECONDS))
                );

        
        WebClient myWebClient  = WebClient
                .builder()
                .clientConnector(new ReactorClientHttpConnector(HttpClient.from(tcpClient)))
                .baseUrl(\"https://baseurl.com\")
                .build();

        
        Mono<String> rs = myWebClient.post()
                .uri(\"uriForRestEndPoints\")
                .header(HttpHeaders.CONTENT_TYPE.toString(), MediaType.valueOf(\"text/plain;charset=UTF-8\").toString())
                .retrieve()
                .bodyToMono(String.class)
                .doOnEach(t -> {System.out.println(\"doOnEach: \" + t.toString()); })
                .doOnSuccess(x -> { System.out.println(\"Success: \") ;})
                .doOnError(x -> { System.out.println(\"Error: \") ; });

        System.out.println(\"got response \"+ rs.block() + \"... \" );
    }

在此示例 POC 中REST API 项目- 我得到\'非法状态异常\'因此我尝试了互联网上的所有内容。 - 喜欢超时、代理、内容标头等。

但仍然遇到同样的问题 \"java.lang.IllegalStateException:底层 HTTP 客户端完成但未发出响应。\"

还有 doOnSuccess、doOnError、doOnEach - 不打印任何东西。

谁能帮我解决这个问题。

    标签: spring rest webclient illegalstateexception


    【解决方案1】:

    我对黄瓜 BDD 测试有完全相同的问题:如果我只运行某个测试,我会收到错误消息“连接在响应期间过早关闭”,但测试结束得很好;当我在 2 个场景下运行 BDD 测试时会出现问题:第二个场景总是卡住,我收到 IllegalStateException: Timeout on clocking read for XXXX seconds" 的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 2019-01-16
      • 1970-01-01
      • 2015-09-24
      • 2021-07-10
      • 2017-12-09
      相关资源
      最近更新 更多