2626
2727import java .util .Collections ;
2828
29+ import javax .annotation .Resource ;
30+
2931import org .junit .Before ;
3032import org .junit .Test ;
3133import org .junit .runner .RunWith ;
3234import org .reactivestreams .Publisher ;
3335
3436import org .springframework .beans .DirectFieldAccessor ;
3537import org .springframework .beans .factory .annotation .Autowired ;
38+ import org .springframework .beans .factory .annotation .Qualifier ;
3639import org .springframework .context .annotation .Bean ;
3740import org .springframework .context .annotation .Configuration ;
3841import org .springframework .core .ResolvableType ;
42+ import org .springframework .core .io .buffer .DataBufferFactory ;
3943import org .springframework .http .HttpMethod ;
4044import org .springframework .http .HttpStatus ;
4145import org .springframework .http .MediaType ;
4246import org .springframework .http .client .reactive .ClientHttpConnector ;
47+ import org .springframework .integration .channel .QueueChannel ;
4348import org .springframework .integration .config .EnableIntegration ;
4449import org .springframework .integration .dsl .IntegrationFlow ;
4550import org .springframework .integration .dsl .IntegrationFlows ;
4651import org .springframework .integration .http .dsl .Http ;
52+ import org .springframework .integration .support .MessageBuilder ;
4753import org .springframework .integration .webflux .outbound .WebFluxRequestExecutingMessageHandler ;
4854import org .springframework .messaging .Message ;
55+ import org .springframework .messaging .MessageChannel ;
4956import org .springframework .messaging .PollableChannel ;
5057import org .springframework .security .access .AccessDecisionManager ;
5158import org .springframework .security .access .vote .AffirmativeBased ;
7683/**
7784 * @author Artem Bilan
7885 * @author Shiliang Li
86+ * @author Abhijit Sarkar
7987 *
8088 * @since 5.0
8189 */
@@ -88,7 +96,15 @@ public class WebFluxDslTests {
8896 private WebApplicationContext wac ;
8997
9098 @ Autowired
91- private WebFluxRequestExecutingMessageHandler serviceInternalReactiveGatewayHandler ;
99+ @ Qualifier ("webFluxWithReplyPayloadToFlux.handler" )
100+ private WebFluxRequestExecutingMessageHandler webFluxWithReplyPayloadToFlux ;
101+
102+ @ Resource (name = "org.springframework.integration.webflux.outbound.WebFluxRequestExecutingMessageHandler#1" )
103+ private WebFluxRequestExecutingMessageHandler httpReactiveProxyFlow ;
104+
105+ @ Autowired
106+ @ Qualifier ("webFluxFlowWithReplyPayloadToFlux.input" )
107+ private MessageChannel webFluxFlowWithReplyPayloadToFluxInput ;
92108
93109 private MockMvc mockMvc ;
94110
@@ -106,6 +122,48 @@ public void setup() {
106122 .build ();
107123 }
108124
125+ @ Test
126+ public void testWebFluxFlowWithReplyPayloadToFlux () {
127+ ClientHttpConnector httpConnector = new HttpHandlerConnector ((request , response ) -> {
128+ response .setStatusCode (HttpStatus .OK );
129+ response .getHeaders ().setContentType (MediaType .TEXT_PLAIN );
130+
131+ DataBufferFactory bufferFactory = response .bufferFactory ();
132+ return response .writeWith (
133+ Flux .just (bufferFactory .wrap ("FOO" .getBytes ()),
134+ bufferFactory .wrap ("BAR" .getBytes ())))
135+ .then (Mono .defer (response ::setComplete ));
136+ });
137+
138+ WebClient webClient = WebClient .builder ()
139+ .clientConnector (httpConnector )
140+ .build ();
141+
142+ new DirectFieldAccessor (this .webFluxWithReplyPayloadToFlux )
143+ .setPropertyValue ("webClient" , webClient );
144+
145+ QueueChannel replyChannel = new QueueChannel ();
146+
147+ Message <String > testMessage =
148+ MessageBuilder .withPayload ("test" )
149+ .setReplyChannel (replyChannel )
150+ .build ();
151+
152+ this .webFluxFlowWithReplyPayloadToFluxInput .send (testMessage );
153+
154+ Message <?> receive = replyChannel .receive (10_000 );
155+
156+ assertNotNull (receive );
157+ assertThat (receive .getPayload (), instanceOf (Flux .class ));
158+
159+ @ SuppressWarnings ("unchecked" )
160+ Flux <String > response = (Flux <String >) receive .getPayload ();
161+
162+ StepVerifier .create (response )
163+ .expectNext ("FOO" , "BAR" )
164+ .verifyComplete ();
165+ }
166+
109167 @ Test
110168 public void testHttpReactiveProxyFlow () throws Exception {
111169 ClientHttpConnector httpConnector = new HttpHandlerConnector ((request , response ) -> {
@@ -120,7 +178,7 @@ public void testHttpReactiveProxyFlow() throws Exception {
120178 .clientConnector (httpConnector )
121179 .build ();
122180
123- new DirectFieldAccessor (this .serviceInternalReactiveGatewayHandler )
181+ new DirectFieldAccessor (this .httpReactiveProxyFlow )
124182 .setPropertyValue ("webClient" , webClient );
125183
126184 this .mockMvc .perform (
@@ -200,6 +258,16 @@ protected void configure(HttpSecurity http) throws Exception {
200258 .anonymous ().disable ();
201259 }
202260
261+ @ Bean
262+ public IntegrationFlow webFluxFlowWithReplyPayloadToFlux () {
263+ return f -> f
264+ .handle (WebFlux .outboundGateway ("http://www.springsource.org/spring-integration" )
265+ .httpMethod (HttpMethod .GET )
266+ .replyPayloadToFlux (true )
267+ .expectedResponseType (String .class ),
268+ e -> e .id ("webFluxWithReplyPayloadToFlux" ));
269+ }
270+
203271 @ Bean
204272 public IntegrationFlow httpReactiveProxyFlow () {
205273 return IntegrationFlows
0 commit comments