简体   繁体   English

当响应具有HTTP错误状态代码时,为什么会出现“只允许一个连接接收订户”?

[英]Why do I get `Only one connection receive subscriber allowed` when the response has an HTTP error status code?

Within a rest request I send another request to a webservice using Spring WebClient and want to return the result to the caller: 在休息请求中,我使用Spring WebClient向Web服务发送另一个请求,并希望将结果返回给调用者:

return webClient.post()
  .uri(url)
  .body(...)
  .retrieve()
  .bodyToMono(String::class.java)
  .map { ResponseEntity.ok(it) }

Now it that webservice returns a HTTP error status code I receive the following error: 现在webservice返回HTTP错误状态代码我收到以下错误:

java.lang.IllegalStateException: Only one connection receive subscriber allowed.

When a status 200 code is returned, no error is thrown. 返回状态200代码时,不会引发错误。

I also tried checking the status and throwing an exception myself, but the behavior is still the same: 我也尝试检查状态并自己抛出异常,但行为仍然相同:

return webClient.post()
  .uri(url)
  .body(...)
  .retrieve()
  .onStatus(HttpStatus::isError) { clientResonse ->
     clientResonse.bodyToMono(String::class.java)
        .map { RuntimeException(it) }
  }
  .bodyToMono(String::class.java)
  .map { ResponseEntity.ok(it) }

What am I doing wrong? 我究竟做错了什么?

The code samples are in Kotlin but I assume every Java dev can read it :) 代码示例在Kotlin中,但我假设每个Java开发人员都可以读取它:)

This is a known issue in Spring Framework and it's been fixed in Spring Framework 5.1.4 - see SPR-17564 . 这是Spring Framework中的一个已知问题,它已在Spring Framework 5.1.4中修复 - 请参阅SPR-17564

Unfortunately, I'm not aware of any workaround for this problem, so upgrading to Spring Framework 5.1.4 / Spring Boot 2.1.2 is the only solution so far. 不幸的是,我不知道这个问题有任何解决方法,因此升级到Spring Framework 5.1.4 / Spring Boot 2.1.2是迄今为止唯一的解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当响应不包含媒体类型头时,Spring WebClient抛出“仅允许一个连接接收订阅者” - Spring webclient throws “Only one connection receive subscriber allowed” when response does not contain media type header 响应正文为空时,“IllegalStateException:仅允许一个连接接收订阅者” - "IllegalStateException: Only one connection receive subscriber allowed" when response body is empty 仅一个连接允许接收订户 - Only one connection receive subscriber allowed 为什么我只在使用 Java HTTP 客户端时得到 HTTP 响应状态码 451? - Why do I get HTTP Response Status Code 451 only when using the Java HTTP Client? Webflux post 请求:只允许一个连接接收订阅者 - Webflux post request: Only one connection receive subscriber allowed 抛出 RestClientException 时如何检索 HTTP 状态代码和响应正文? - How do I retrieve HTTP status code and response body when an RestClientException is thrown? 在测试时,如何获取泽西/ dropwizard响应的状态代码和响应标头? - How do I get the status code & response headers of a jersey/dropwizard response, when testing? 为什么我在POST请求中收到不允许的HTTP 405方法? - Why do I get an HTTP 405 Method Not Allowed on a POST request? 为什么我得到错误方法有多个实体。 您只能使用一个实体参数 - Why do I get Error method has more than one entity. You must use only one entity parameter 为什么我得到只有祖先查询被允许在事务内部错误 - Why do I get Only ancestor queries are allowed inside transactions error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM