Reputation: 2040
Within a rest request I send another request to a webservice using Spring WebClient and want to return the result to the caller:
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:
java.lang.IllegalStateException: Only one connection receive subscriber allowed.
When a status 200 code is returned, no error is thrown.
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 :)
Upvotes: 3
Views: 2981
Reputation: 59221
This is a known issue in Spring Framework and it's been fixed in Spring Framework 5.1.4 - see 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.
Upvotes: 2