GH-154: Change FORM CT to JSON for HTTP supplier

Fixes https://github.com/spring-cloud/stream-applications/issues/154

The Binder conversion mechanism is not aware about a `MediaType.APPLICATION_FORM_URLENCODED`
and does not know how to convert the `MultiValueMap` with such a content-type

* Change the Http-Supplier to replace a `MediaType.APPLICATION_FORM_URLENCODED`
content-type header to the `MediaType.APPLICATION_JSON` for the proper
JSON serialization for the `MultiValueMap` on the binder level before sending to
the output destination
This commit is contained in:
Artem Bilan
2021-03-09 11:48:41 -05:00
parent 4c044d2d14
commit 4eb34fb245

View File

@@ -26,6 +26,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.expression.ValueExpression;
import org.springframework.integration.http.support.DefaultHttpHeaderMapper;
@@ -33,6 +34,7 @@ import org.springframework.integration.mapping.HeaderMapper;
import org.springframework.integration.webflux.dsl.WebFlux;
import org.springframework.integration.webflux.inbound.WebFluxInboundEndpoint;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
/**
* Configuration for the HTTP Supplier.
@@ -55,6 +57,14 @@ public class HttpSupplierConfiguration {
.allowedHeaders(httpSupplierProperties.getCors().getAllowedHeaders())
.allowCredentials(httpSupplierProperties.getCors().getAllowCredentials()))
.autoStartup(false))
.enrichHeaders((headers) ->
headers.headerFunction(MessageHeaders.CONTENT_TYPE,
(message) ->
(MediaType.APPLICATION_FORM_URLENCODED_VALUE.equals(
message.getHeaders().get(MessageHeaders.CONTENT_TYPE).toString()))
? MediaType.APPLICATION_JSON
: null,
true))
.toReactivePublisher();
}