From 6aca63806f8b6e4a946f6797e7c9588aa208ceb0 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 3 Aug 2017 19:23:35 -0400 Subject: [PATCH] Upgrade to the latest SF, SS and Reactor https://build.spring.io/browse/INT-FATS5IC-249 --- build.gradle | 8 ++--- ...iveHttpRequestExecutingMessageHandler.java | 30 ++++++++++++++++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 23cb0edc10..584b6e1699 100644 --- a/build.gradle +++ b/build.gradle @@ -123,8 +123,8 @@ subprojects { subproject -> mysqlVersion = '5.1.41' pahoMqttClientVersion = '1.1.1' postgresVersion = '42.0.0' - reactorNettyVersion = '0.7.0.M1' - reactorVersion = '3.1.0.M3' + reactorNettyVersion = '0.7.0.BUILD-SNAPSHOT' + reactorVersion = '3.1.0.BUILD-SNAPSHOT' romeToolsVersion = '1.7.2' servletApiVersion = '3.1.0' slf4jVersion = "1.7.25" @@ -134,10 +134,10 @@ subprojects { subproject -> springDataMongoVersion = '2.0.0.RC2' springDataRedisVersion = '2.0.0.RC2' springGemfireVersion = '2.0.0.RC2' - springSecurityVersion = '5.0.0.M3' + springSecurityVersion = '5.0.0.BUILD-SNAPSHOT' springSocialTwitterVersion = '2.0.0.M4' springRetryVersion = '1.2.0.RELEASE' - springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.0.0.RC3' + springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.0.0.BUILD-SNAPSHOT' springWsVersion = '2.4.0.RELEASE' tomcatVersion = "8.5.16" xmlUnitVersion = '1.6' diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/ReactiveHttpRequestExecutingMessageHandler.java b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/ReactiveHttpRequestExecutingMessageHandler.java index 56de77a6d3..5f372a6f1f 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/ReactiveHttpRequestExecutingMessageHandler.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/ReactiveHttpRequestExecutingMessageHandler.java @@ -17,10 +17,13 @@ package org.springframework.integration.http.outbound; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.function.Supplier; import org.springframework.beans.factory.BeanFactory; import org.springframework.core.ParameterizedTypeReference; +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.expression.Expression; import org.springframework.expression.common.LiteralExpression; import org.springframework.http.HttpEntity; @@ -32,12 +35,13 @@ import org.springframework.integration.expression.ValueExpression; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.util.Assert; +import org.springframework.util.MimeType; import org.springframework.web.reactive.function.BodyExtractor; import org.springframework.web.reactive.function.BodyExtractors; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.WebClient; -import org.springframework.web.reactive.function.client.WebClientException; +import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Mono; @@ -129,9 +133,27 @@ public class ReactiveHttpRequestExecutingMessageHandler extends AbstractHttpRequ .doOnNext(response -> { HttpStatus httpStatus = response.statusCode(); if (httpStatus.is4xxClientError() || httpStatus.is5xxServerError()) { - throw new WebClientException( - "ClientResponse has erroneous status code: " + httpStatus.value() + - " " + httpStatus.getReasonPhrase()); + throw new WebClientResponseException( + String.format("ClientResponse has erroneous status code: %d %s", + response.statusCode().value(), + response.statusCode().getReasonPhrase()), + httpStatus.value(), + httpStatus.getReasonPhrase(), + response.headers() + .asHttpHeaders(), + response.body(BodyExtractors.toDataBuffers()) + .reduce(DataBuffer::write) + .map(dataBuffer -> { + byte[] bytes = new byte[dataBuffer.readableByteCount()]; + dataBuffer.read(bytes); + DataBufferUtils.release(dataBuffer); + return bytes; + }) + .block(), + response.headers() + .contentType() + .map(MimeType::getCharset) + .orElse(StandardCharsets.ISO_8859_1)); } });