26
26
27
27
import java .util .Collections ;
28
28
29
+ import javax .annotation .Resource ;
30
+
29
31
import org .junit .Before ;
30
32
import org .junit .Test ;
31
33
import org .junit .runner .RunWith ;
32
34
import org .reactivestreams .Publisher ;
33
35
34
36
import org .springframework .beans .DirectFieldAccessor ;
35
37
import org .springframework .beans .factory .annotation .Autowired ;
38
+ import org .springframework .beans .factory .annotation .Qualifier ;
36
39
import org .springframework .context .annotation .Bean ;
37
40
import org .springframework .context .annotation .Configuration ;
38
41
import org .springframework .core .ResolvableType ;
42
+ import org .springframework .core .io .buffer .DataBufferFactory ;
39
43
import org .springframework .http .HttpMethod ;
40
44
import org .springframework .http .HttpStatus ;
41
45
import org .springframework .http .MediaType ;
42
46
import org .springframework .http .client .reactive .ClientHttpConnector ;
47
+ import org .springframework .integration .channel .QueueChannel ;
43
48
import org .springframework .integration .config .EnableIntegration ;
44
49
import org .springframework .integration .dsl .IntegrationFlow ;
45
50
import org .springframework .integration .dsl .IntegrationFlows ;
46
51
import org .springframework .integration .http .dsl .Http ;
52
+ import org .springframework .integration .support .MessageBuilder ;
47
53
import org .springframework .integration .webflux .outbound .WebFluxRequestExecutingMessageHandler ;
48
54
import org .springframework .messaging .Message ;
55
+ import org .springframework .messaging .MessageChannel ;
49
56
import org .springframework .messaging .PollableChannel ;
50
57
import org .springframework .security .access .AccessDecisionManager ;
51
58
import org .springframework .security .access .vote .AffirmativeBased ;
76
83
/**
77
84
* @author Artem Bilan
78
85
* @author Shiliang Li
86
+ * @author Abhijit Sarkar
79
87
*
80
88
* @since 5.0
81
89
*/
@@ -88,7 +96,15 @@ public class WebFluxDslTests {
88
96
private WebApplicationContext wac ;
89
97
90
98
@ 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 ;
92
108
93
109
private MockMvc mockMvc ;
94
110
@@ -106,6 +122,48 @@ public void setup() {
106
122
.build ();
107
123
}
108
124
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
+
109
167
@ Test
110
168
public void testHttpReactiveProxyFlow () throws Exception {
111
169
ClientHttpConnector httpConnector = new HttpHandlerConnector ((request , response ) -> {
@@ -120,7 +178,7 @@ public void testHttpReactiveProxyFlow() throws Exception {
120
178
.clientConnector (httpConnector )
121
179
.build ();
122
180
123
- new DirectFieldAccessor (this .serviceInternalReactiveGatewayHandler )
181
+ new DirectFieldAccessor (this .httpReactiveProxyFlow )
124
182
.setPropertyValue ("webClient" , webClient );
125
183
126
184
this .mockMvc .perform (
@@ -200,6 +258,16 @@ protected void configure(HttpSecurity http) throws Exception {
200
258
.anonymous ().disable ();
201
259
}
202
260
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
+
203
271
@ Bean
204
272
public IntegrationFlow httpReactiveProxyFlow () {
205
273
return IntegrationFlows
0 commit comments