Skip to content

Commit 5abaf20

Browse files
committed
Merge branch '5.3.x'
2 parents 0e7c7b4 + a3e23cd commit 5abaf20

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Set;
2222

2323
import org.reactivestreams.Publisher;
24+
import reactor.core.publisher.Flux;
2425
import reactor.core.publisher.Mono;
2526

2627
import org.springframework.core.KotlinDetector;
@@ -130,7 +131,8 @@ protected Mono<Void> writeBody(@Nullable Object body, MethodParameter bodyParame
130131
if (adapter != null) {
131132
publisher = adapter.toPublisher(body);
132133
boolean isUnwrapped = KotlinDetector.isSuspendingFunction(bodyParameter.getMethod()) &&
133-
!COROUTINES_FLOW_CLASS_NAME.equals(bodyType.toClass().getName());
134+
!COROUTINES_FLOW_CLASS_NAME.equals(bodyType.toClass().getName()) &&
135+
!Flux.class.equals(bodyType.toClass());
134136
ResolvableType genericType = isUnwrapped ? bodyType : bodyType.getGeneric();
135137
elementType = getElementType(adapter, genericType);
136138
actualElementType = elementType;

spring-webflux/src/test/kotlin/org/springframework/web/reactive/result/method/annotation/CoroutinesIntegrationTests.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import org.springframework.web.bind.annotation.RestController
3737
import org.springframework.web.client.HttpServerErrorException
3838
import org.springframework.web.reactive.config.EnableWebFlux
3939
import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer
40+
import reactor.core.publisher.Flux
41+
import java.time.Duration
4042

4143
class CoroutinesIntegrationTests : AbstractRequestMappingIntegrationTests() {
4244

@@ -111,6 +113,25 @@ class CoroutinesIntegrationTests : AbstractRequestMappingIntegrationTests() {
111113
}
112114
}
113115

116+
@ParameterizedHttpServerTest
117+
fun `Suspending handler method returning ResponseEntity of Flux `(httpServer: HttpServer) {
118+
startServer(httpServer)
119+
120+
val entity = performGet<String>("/entity-flux", HttpHeaders.EMPTY, String::class.java)
121+
assertThat(entity.statusCode).isEqualTo(HttpStatus.OK)
122+
assertThat(entity.body).isEqualTo("01234")
123+
}
124+
125+
@ParameterizedHttpServerTest
126+
fun `Suspending handler method returning ResponseEntity of Flow`(httpServer: HttpServer) {
127+
startServer(httpServer)
128+
129+
val entity = performGet<String>("/entity-flow", HttpHeaders.EMPTY, String::class.java)
130+
assertThat(entity.statusCode).isEqualTo(HttpStatus.OK)
131+
assertThat(entity.body).isEqualTo("foobar")
132+
}
133+
134+
114135
@Configuration
115136
@EnableWebFlux
116137
@ComponentScan(resourcePattern = "**/CoroutinesIntegrationTests*")
@@ -169,6 +190,25 @@ class CoroutinesIntegrationTests : AbstractRequestMappingIntegrationTests() {
169190
throw IllegalStateException()
170191
}
171192

193+
@GetMapping("/entity-flux")
194+
suspend fun entityFlux() : ResponseEntity<Flux<String>> {
195+
val strings = Flux.interval(Duration.ofMillis(100)).take(5)
196+
.map { l -> l.toString() }
197+
delay(1)
198+
return ResponseEntity.ok().body(strings)
199+
}
200+
201+
@GetMapping("/entity-flow")
202+
suspend fun entityFlow() : ResponseEntity<Flow<String>> {
203+
val strings = flow {
204+
emit("foo")
205+
delay(1)
206+
emit("bar")
207+
delay(1)
208+
}
209+
return ResponseEntity.ok().body(strings)
210+
}
211+
172212
}
173213

174214

0 commit comments

Comments
 (0)