Код: Выделить всё
private fun buildWebClient(): WebClient {
val httpClient:CloseableHttpAsyncClient =
HttpAsyncClients.createDefault()
val connector = HttpComponentsClientHttpConnector(httpClient)
return WebClient.builder()
.baseUrl("https://example.com")
.clientConnector(connector)
.filter(Filter())
.build()
}
private fun Filter(): ExchangeFilterFunction {
return ExchangeFilterFunction.ofResponseProcessor { response ->
response.bodyToMono(String::class.java).cache().flatMap { body ->
val res = json().decodeFromString(body)
when {
res.isSuccess() -> {
val bufferFactory = DefaultDataBufferFactory()
val cachedBody = bufferFactory.wrap(body.toByteArray())
Mono.just(response.mutate().body(Flux.just(cachedBody)).build())
}
else -> {
throw IllegalArgumentException("error")
}
}
}
}
}
Код: Выделить всё
reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalStateException: The client response body can only be consumed once Caused by: java.lang.IllegalStateException: The client response body can only be consumed once at org.springframework.http.client.reactive.AbstractClientHttpResponse.lambda$singleSubscription$0(AbstractClientHttpResponse.java:65) \~\[spring-web-6.1.5.jar:6.1.5\] Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Error has been observed at the following site(s):пожалуйста, помогите мне
Эта проблема возникает только при использовании асинхронные клиенты
я хочу исправить ошибку
мне так сложно
Подробнее здесь: https://stackoverflow.com/questions/790 ... sumed-once