[英]Spring webclient throws “Only one connection receive subscriber allowed” when response does not contain media type header
[英]Why do I get `Only one connection receive subscriber allowed` when the response has an HTTP error status code?
在休息請求中,我使用Spring WebClient向Web服務發送另一個請求,並希望將結果返回給調用者:
return webClient.post()
.uri(url)
.body(...)
.retrieve()
.bodyToMono(String::class.java)
.map { ResponseEntity.ok(it) }
現在webservice返回HTTP錯誤狀態代碼我收到以下錯誤:
java.lang.IllegalStateException: Only one connection receive subscriber allowed.
返回狀態200代碼時,不會引發錯誤。
我也嘗試檢查狀態並自己拋出異常,但行為仍然相同:
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) }
我究竟做錯了什么?
代碼示例在Kotlin中,但我假設每個Java開發人員都可以讀取它:)
這是Spring Framework中的一個已知問題,它已在Spring Framework 5.1.4中修復 - 請參閱SPR-17564 。
不幸的是,我不知道這個問題有任何解決方法,因此升級到Spring Framework 5.1.4 / Spring Boot 2.1.2是迄今為止唯一的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.