SSE reader support to read full content as a String

The SSE reader is ordered ahead of StringDecoder because with
response.decodeToFlux(String.class) we actually want the SSE reader
to get involved first based on the content-type.

At the same time with response.decodeToMono(String.class) there is
nothing the SSE reader can do while the StringDecoder could read the
entore content as one String, as long as the server does terminate
the stream which can happen in a testing scenario.

This commit updates ServerSentEventHttpMessageReader#readMono in
to support String.class by delegating to StringDecoder. Since
reading to a Mono is an explicit choice there is not much possibility
for interfering with decoding to Flux.

Issue: SPR-15331
This commit is contained in:
Rossen Stoyanchev
2017-03-08 17:13:40 -05:00
parent 8c36d3c4d9
commit a1c24d2122
2 changed files with 25 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ import java.util.Collections;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import org.springframework.core.ResolvableType;
@@ -157,4 +158,18 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractDataBufferAll
.verify();
}
@Test // SPR-15331
public void decodeFullContentAsString() {
String body = "data:foo\ndata:bar\n\ndata:baz\n\n";
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(body);
String actual = messageReader
.readMono(ResolvableType.forClass(String.class), request, Collections.emptyMap())
.cast(String.class)
.block(Duration.ZERO);
assertEquals(body, actual);
}
}