[英]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.