From 4eb34fb245e70f47e034b45973ce987c4de00680 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 9 Mar 2021 11:48:41 -0500 Subject: [PATCH] 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 --- .../fn/supplier/http/HttpSupplierConfiguration.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/functions/supplier/http-supplier/src/main/java/org/springframework/cloud/fn/supplier/http/HttpSupplierConfiguration.java b/functions/supplier/http-supplier/src/main/java/org/springframework/cloud/fn/supplier/http/HttpSupplierConfiguration.java index 12aae265..f2c9a80e 100644 --- a/functions/supplier/http-supplier/src/main/java/org/springframework/cloud/fn/supplier/http/HttpSupplierConfiguration.java +++ b/functions/supplier/http-supplier/src/main/java/org/springframework/cloud/fn/supplier/http/HttpSupplierConfiguration.java @@ -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(); }