GH-186 ensured FluxReturnValueConfiguration is used
Ensured that regardless of the version of Spring and presense of webflux, the FluxReturnValueConfiguration is used Resolves #186
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2017 the original author or authors.
|
* Copyright 2013-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -25,7 +25,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
|
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||||
@@ -41,7 +40,6 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.core.convert.support.DefaultConversionService;
|
import org.springframework.core.convert.support.DefaultConversionService;
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
import org.springframework.web.method.support.AsyncHandlerMethodReturnValueHandler;
|
import org.springframework.web.method.support.AsyncHandlerMethodReturnValueHandler;
|
||||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||||
@@ -52,6 +50,7 @@ import reactor.core.publisher.Flux;
|
|||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
|
* @author Oleg Zhurakousky
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnWebApplication
|
@ConditionalOnWebApplication
|
||||||
@@ -77,7 +76,6 @@ public class ReactorAutoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnMissingClass("org.springframework.core.ReactiveAdapter")
|
|
||||||
protected static class FluxReturnValueConfiguration {
|
protected static class FluxReturnValueConfiguration {
|
||||||
@Bean
|
@Bean
|
||||||
public FluxReturnValueHandler fluxReturnValueHandler(FunctionInspector inspector,
|
public FluxReturnValueHandler fluxReturnValueHandler(FunctionInspector inspector,
|
||||||
@@ -107,13 +105,10 @@ public class ReactorAutoConfiguration {
|
|||||||
adapter.getArgumentResolvers());
|
adapter.getArgumentResolvers());
|
||||||
resolvers.add(0, resolver);
|
resolvers.add(0, resolver);
|
||||||
adapter.setArgumentResolvers(resolvers);
|
adapter.setArgumentResolvers(resolvers);
|
||||||
if (!ClassUtils.isPresent("org.springframework.core.ReactiveAdapter",
|
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(
|
||||||
null)) {
|
adapter.getReturnValueHandlers());
|
||||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(
|
handlers.add(0, context.getBean(FluxReturnValueHandler.class));
|
||||||
adapter.getReturnValueHandlers());
|
adapter.setReturnValueHandlers(handlers);
|
||||||
handlers.add(0, context.getBean(FluxReturnValueHandler.class));
|
|
||||||
adapter.setReturnValueHandlers(handlers);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.cloud.function.web;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
|
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Oleg Zhurakousky
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"spring.cloud.function.web.path=/functions" })
|
||||||
|
public class HeadersToMessageTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TestRestTemplate rest;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBodyAndCustomHeaderFromMessagePropagation() throws Exception {
|
||||||
|
ResponseEntity<String> postForEntity = rest.postForEntity(new URI("/functions/employee"), "{\"name\":\"Bob\",\"age\":25}", String.class);
|
||||||
|
assertEquals("{\"name\":\"Bob\",\"age\":25}", postForEntity.getBody());
|
||||||
|
assertTrue(postForEntity.getHeaders().containsKey("x-content-type"));
|
||||||
|
assertEquals("application/xml", postForEntity.getHeaders().get("x-content-type").get(0));
|
||||||
|
assertEquals("bar", postForEntity.getHeaders().get("foo").get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@org.springframework.boot.test.context.TestConfiguration
|
||||||
|
protected static class TestConfiguration {
|
||||||
|
@Bean({ "employee"})
|
||||||
|
public Function<Message<String>, Message<String>> function() {
|
||||||
|
return request -> {
|
||||||
|
Message<String> message = MessageBuilder.withPayload(request.getPayload())
|
||||||
|
.setHeader("X-Content-Type", "application/xml")
|
||||||
|
.setHeader("foo", "bar")
|
||||||
|
.build();
|
||||||
|
return message;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user