Polish Javadoc of [Server]HttpMessage[Reader|Writer]

This commit is contained in:
Rossen Stoyanchev 2017-03-21 10:57:21 -04:00
parent 54013a0920
commit 124cdb5c58
15 changed files with 136 additions and 141 deletions

View File

@ -81,19 +81,19 @@ public class DecoderHttpMessageReader<T> implements ServerHttpMessageReader<T> {
} }
@Override @Override
public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage inputMessage, public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
MediaType contentType = getContentType(inputMessage); MediaType contentType = getContentType(message);
return this.decoder.decode(inputMessage.getBody(), elementType, contentType, hints); return this.decoder.decode(message.getBody(), elementType, contentType, hints);
} }
@Override @Override
public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage inputMessage, public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
MediaType contentType = getContentType(inputMessage); MediaType contentType = getContentType(message);
return this.decoder.decodeToMono(inputMessage.getBody(), elementType, contentType, hints); return this.decoder.decodeToMono(message.getBody(), elementType, contentType, hints);
} }
private MediaType getContentType(HttpMessage inputMessage) { private MediaType getContentType(HttpMessage inputMessage) {
@ -105,22 +105,22 @@ public class DecoderHttpMessageReader<T> implements ServerHttpMessageReader<T> {
// ServerHttpMessageReader... // ServerHttpMessageReader...
@Override @Override
public Flux<T> read(ResolvableType streamType, ResolvableType elementType, public Flux<T> read(ResolvableType actualType, ResolvableType elementType,
ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> hints) { ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> hints) {
Map<String, Object> allHints = new HashMap<>(4); Map<String, Object> allHints = new HashMap<>(4);
allHints.putAll(getReadHints(streamType, elementType, request, response)); allHints.putAll(getReadHints(actualType, elementType, request, response));
allHints.putAll(hints); allHints.putAll(hints);
return read(elementType, request, allHints); return read(elementType, request, allHints);
} }
@Override @Override
public Mono<T> readMono(ResolvableType streamType, ResolvableType elementType, public Mono<T> readMono(ResolvableType actualType, ResolvableType elementType,
ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> hints) { ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> hints) {
Map<String, Object> allHints = new HashMap<>(4); Map<String, Object> allHints = new HashMap<>(4);
allHints.putAll(getReadHints(streamType, elementType, request, response)); allHints.putAll(getReadHints(actualType, elementType, request, response));
allHints.putAll(hints); allHints.putAll(hints);
return readMono(elementType, request, allHints); return readMono(elementType, request, allHints);

View File

@ -120,10 +120,10 @@ public class EncoderHttpMessageWriter<T> implements ServerHttpMessageWriter<T> {
@Override @Override
public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType, public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType,
MediaType mediaType, ReactiveHttpOutputMessage outputMessage, MediaType mediaType, ReactiveHttpOutputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
HttpHeaders headers = outputMessage.getHeaders(); HttpHeaders headers = message.getHeaders();
if (headers.getContentType() == null) { if (headers.getContentType() == null) {
MediaType fallback = this.defaultMediaType; MediaType fallback = this.defaultMediaType;
@ -135,11 +135,11 @@ public class EncoderHttpMessageWriter<T> implements ServerHttpMessageWriter<T> {
} }
Flux<DataBuffer> body = this.encoder.encode(inputStream, Flux<DataBuffer> body = this.encoder.encode(inputStream,
outputMessage.bufferFactory(), elementType, headers.getContentType(), hints); message.bufferFactory(), elementType, headers.getContentType(), hints);
return isStreamingMediaType(headers.getContentType()) ? return isStreamingMediaType(headers.getContentType()) ?
outputMessage.writeAndFlushWith(body.map(Flux::just)) : message.writeAndFlushWith(body.map(Flux::just)) :
outputMessage.writeWith(body); message.writeWith(body);
} }
private static boolean useFallback(MediaType main, MediaType fallback) { private static boolean useFallback(MediaType main, MediaType fallback) {
@ -162,12 +162,12 @@ public class EncoderHttpMessageWriter<T> implements ServerHttpMessageWriter<T> {
// ServerHttpMessageWriter... // ServerHttpMessageWriter...
@Override @Override
public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType streamType, public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType actualType,
ResolvableType elementType, MediaType mediaType, ServerHttpRequest request, ResolvableType elementType, MediaType mediaType, ServerHttpRequest request,
ServerHttpResponse response, Map<String, Object> hints) { ServerHttpResponse response, Map<String, Object> hints) {
Map<String, Object> allHints = new HashMap<>(); Map<String, Object> allHints = new HashMap<>();
allHints.putAll(getWriteHints(streamType, elementType, mediaType, request, response)); allHints.putAll(getWriteHints(actualType, elementType, mediaType, request, response));
allHints.putAll(hints); allHints.putAll(hints);
return write(inputStream, elementType, mediaType, response, allHints); return write(inputStream, elementType, mediaType, response, allHints);

View File

@ -83,19 +83,19 @@ public class FormHttpMessageReader implements HttpMessageReader<MultiValueMap<St
@Override @Override
public Flux<MultiValueMap<String, String>> read(ResolvableType elementType, public Flux<MultiValueMap<String, String>> read(ResolvableType elementType,
ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) { ReactiveHttpInputMessage message, Map<String, Object> hints) {
return Flux.from(readMono(elementType, inputMessage, hints)); return Flux.from(readMono(elementType, message, hints));
} }
@Override @Override
public Mono<MultiValueMap<String, String>> readMono(ResolvableType elementType, public Mono<MultiValueMap<String, String>> readMono(ResolvableType elementType,
ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) { ReactiveHttpInputMessage message, Map<String, Object> hints) {
MediaType contentType = inputMessage.getHeaders().getContentType(); MediaType contentType = message.getHeaders().getContentType();
Charset charset = getMediaTypeCharset(contentType); Charset charset = getMediaTypeCharset(contentType);
return inputMessage.getBody() return message.getBody()
.reduce(DataBuffer::write) .reduce(DataBuffer::write)
.map(buffer -> { .map(buffer -> {
CharBuffer charBuffer = charset.decode(buffer.asByteBuffer()); CharBuffer charBuffer = charset.decode(buffer.asByteBuffer());

View File

@ -82,13 +82,13 @@ public class FormHttpMessageWriter implements HttpMessageWriter<MultiValueMap<St
@Override @Override
public Mono<Void> write(Publisher<? extends MultiValueMap<String, String>> inputStream, public Mono<Void> write(Publisher<? extends MultiValueMap<String, String>> inputStream,
ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage outputMessage, ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
MediaType contentType = outputMessage.getHeaders().getContentType(); MediaType contentType = message.getHeaders().getContentType();
if (contentType == null) { if (contentType == null) {
contentType = MediaType.APPLICATION_FORM_URLENCODED; contentType = MediaType.APPLICATION_FORM_URLENCODED;
outputMessage.getHeaders().setContentType(contentType); message.getHeaders().setContentType(contentType);
} }
Charset charset = getMediaTypeCharset(contentType); Charset charset = getMediaTypeCharset(contentType);
@ -99,9 +99,9 @@ public class FormHttpMessageWriter implements HttpMessageWriter<MultiValueMap<St
.map(form -> generateForm(form, charset)) .map(form -> generateForm(form, charset))
.then(value -> { .then(value -> {
ByteBuffer byteBuffer = charset.encode(value); ByteBuffer byteBuffer = charset.encode(value);
DataBuffer buffer = outputMessage.bufferFactory().wrap(byteBuffer); DataBuffer buffer = message.bufferFactory().wrap(byteBuffer);
outputMessage.getHeaders().setContentLength(byteBuffer.remaining()); message.getHeaders().setContentLength(byteBuffer.remaining());
return outputMessage.writeWith(Mono.just(buffer)); return message.writeWith(Mono.just(buffer));
}); });
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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.
@ -27,8 +27,10 @@ import org.springframework.http.MediaType;
import org.springframework.http.ReactiveHttpInputMessage; import org.springframework.http.ReactiveHttpInputMessage;
/** /**
* Strategy interface that specifies a reader that can convert from the HTTP * Strategy for reading from a {@link ReactiveHttpInputMessage} and decoding
* request body from a stream of bytes to Objects. * the stream of bytes to Objects of type {@code <T>}.
*
* @param <T> the type of objects in the decoded output stream
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Arjen Poutsma * @author Arjen Poutsma
@ -38,40 +40,39 @@ import org.springframework.http.ReactiveHttpInputMessage;
public interface HttpMessageReader<T> { public interface HttpMessageReader<T> {
/** /**
* Indicates whether the given class can be read by this converter. * Return the {@link MediaType}'s that this reader supports.
* @param elementType the stream element type to test for readability */
* @param mediaType the media type to read, can be {@code null} if not specified. List<MediaType> getReadableMediaTypes();
* Typically the value of a {@code Content-Type} header.
* @return {@code true} if readable; {@code false} otherwise /**
* Whether the given object type is supported by this reader.
* @param elementType the type of object to check
* @param mediaType the media type for the read, possibly {@code null}
* @return {@code true} if readable, {@code false} otherwise
*/ */
boolean canRead(ResolvableType elementType, MediaType mediaType); boolean canRead(ResolvableType elementType, MediaType mediaType);
/** /**
* Read a {@link Flux} of the given type form the given input message, and returns it. * Read from the input message and encode to a stream of objects.
* @param elementType the stream element type to return. This type must have previously been *
* passed to the {@link #canRead canRead} method of this interface, which must have * @param elementType the type of objects in the stream which must have been
* returned {@code true}. * previously checked via {@link #canRead(ResolvableType, MediaType)}
* @param inputMessage the HTTP input message to read from * @param message the message to read from
* @param hints additional information about how to read the body * @param hints additional information about how to read and decode the input
* @return the converted {@link Flux} of elements * @return the decoded stream of elements
*/ */
Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage inputMessage, Map<String, Object> hints); Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints);
/** /**
* Read a {@link Mono} of the given type form the given input message, and returns it. * Read from the input message and encode to a single object.
* @param elementType the stream element type to return. This type must have previously been *
* passed to the {@link #canRead canRead} method of this interface, which must have * @param elementType the type of objects in the stream which must have been
* returned {@code true}. * previously checked via {@link #canRead(ResolvableType, MediaType)}
* @param inputMessage the HTTP input message to read from * @param message the message to read from
* @param hints additional information about how to read the body * @param hints additional information about how to read and decode the input
* @return the converted {@link Mono} of object * @return the decoded object
*/ */
Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage inputMessage, Map<String, Object> hints); Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints);
/**
* Return the list of {@link MediaType} objects that can be read by this converter.
* @return the list of supported readable media types
*/
List<MediaType> getReadableMediaTypes();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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.
@ -27,8 +27,10 @@ import org.springframework.http.MediaType;
import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.ReactiveHttpOutputMessage;
/** /**
* Strategy interface that specifies a converter that can convert a stream of * Strategy for encoding a stream of objects of type {@code <T>} and writing
* Objects to a stream of bytes to be written to the HTTP response body. * the encoded stream of bytes to an {@link ReactiveHttpOutputMessage}.
*
* @param <T> the type of objects in the input stream
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Arjen Poutsma * @author Arjen Poutsma
@ -38,34 +40,31 @@ import org.springframework.http.ReactiveHttpOutputMessage;
public interface HttpMessageWriter<T> { public interface HttpMessageWriter<T> {
/** /**
* Indicates whether the given class can be written by this converter. * Return the {@link MediaType}'s that this writer supports.
* @param elementType the stream element type to test for writability */
* @param mediaType the media type to write, can be {@code null} if not specified. List<MediaType> getWritableMediaTypes();
* Typically the value of an {@code Accept} header.
* @return {@code true} if writable; {@code false} otherwise /**
* Whether the given object type is supported by this writer.
* @param elementType the type of object to check
* @param mediaType the media type for the write, possibly {@code null}
* @return {@code true} if writable, {@code false} otherwise
*/ */
boolean canWrite(ResolvableType elementType, MediaType mediaType); boolean canWrite(ResolvableType elementType, MediaType mediaType);
/** /**
* Write an given object to the given output message. * Write an given stream of object to the output message.
* @param inputStream the input stream to write * @param inputStream the objects to write
* @param elementType the stream element type to process. This type must have previously * @param elementType the type of objects in the stream which must have been
* been passed to the {@link #canWrite} canWrite} method of this interface, which must * previously checked via {@link #canWrite(ResolvableType, MediaType)}
* have returned {@code true}. * @param mediaType the content type for the write, possibly {@code null} to
* @param mediaType the content type to use when writing, typically the value of an * indicate that the default content type of the writer must be used.
* {@code Accept} header. May be {@code null} to indicate that the default content * @param message the message to write to
* type of the converter must be used. * @param hints additional information about how to encode and write
* @param outputMessage the message to write to * @return indicates completion or error
* @param hints additional information about how to write
* @return a {@link Mono} that indicates completion or error
*/ */
Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType, Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType,
MediaType mediaType, ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints); MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints);
/**
* Return the list of {@link MediaType} objects that can be written by this converter.
* @return the list of supported readable media types
*/
List<MediaType> getWritableMediaTypes();
} }

View File

@ -176,7 +176,7 @@ public class ResourceHttpMessageWriter implements ServerHttpMessageWriter<Resour
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Mono<Void> write(Publisher<? extends Resource> inputStream, ResolvableType streamType, public Mono<Void> write(Publisher<? extends Resource> inputStream, ResolvableType actualType,
ResolvableType elementType, MediaType mediaType, ServerHttpRequest request, ResolvableType elementType, MediaType mediaType, ServerHttpRequest request,
ServerHttpResponse response, Map<String, Object> hints) { ServerHttpResponse response, Map<String, Object> hints) {

View File

@ -31,7 +31,6 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
*/ */
public interface ServerHttpDecoder<T> extends Decoder<T> { public interface ServerHttpDecoder<T> extends Decoder<T> {
/** /**
* Get decoding hints based on the server request or annotations on the * Get decoding hints based on the server request or annotations on the
* target controller method parameter. * target controller method parameter.

View File

@ -33,7 +33,6 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
*/ */
public interface ServerHttpEncoder<T> extends Encoder<T> { public interface ServerHttpEncoder<T> extends Encoder<T> {
/** /**
* Get decoding hints based on the server request or annotations on the * Get decoding hints based on the server request or annotations on the
* target controller method parameter. * target controller method parameter.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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.
@ -27,46 +27,43 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponse;
/** /**
* Server oriented {@link HttpMessageReader} that allows to resolve hints using annotations or * An extension of {@code HttpMessageReader} for decoding and reading the
* perform additional operation using {@link ServerHttpRequest} or {@link ServerHttpResponse}. * request body with extra information available on the server side.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @author Rossen Stoyanchev
* @since 5.0 * @since 5.0
*/ */
public interface ServerHttpMessageReader<T> extends HttpMessageReader<T> { public interface ServerHttpMessageReader<T> extends HttpMessageReader<T> {
/** /**
* Read a {@link Flux} of the given type form the given input message with additional server related * Decode and read the request body to an object stream.
* parameters which could be used to create some hints or set the response status for example.
* *
* Return hints that can be used to customize how the body should be read * @param actualType the actual type of the target method parameter; for
* @param streamType the original type used in the method parameter. For annotation * annotated controllers, the {@link MethodParameter} can be accessed via
* based controllers, the {@link MethodParameter} is available via {@link ResolvableType#getSource()}. * {@link ResolvableType#getSource()}.
* @param elementType the stream element type to return * @param elementType the type of Objects in the output stream
* Typically the value of a {@code Content-Type} header. * @param request the current request
* @param request the current HTTP request * @param response the current response
* @param response the current HTTP response
* @param hints additional information about how to read the body * @param hints additional information about how to read the body
* @return the converted {@link Flux} of elements * @return the decoded stream of elements
*/ */
Flux<T> read(ResolvableType streamType, ResolvableType elementType, ServerHttpRequest request, Flux<T> read(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request,
ServerHttpResponse response, Map<String, Object> hints); ServerHttpResponse response, Map<String, Object> hints);
/** /**
* Read a {@link Mono} of the given type form the given input message with additional server related * Decode and read the request body to a single object.
* parameters which could be used to create some hints or set the response status for example.
* *
* Return hints that can be used to customize how the body should be read * @param actualType the actual type of the target method parameter; for
* @param streamType the original type used in the method parameter. For annotation * annotated controllers, the {@link MethodParameter} can be accessed via
* based controllers, the {@link MethodParameter} is available via {@link ResolvableType#getSource()}. * {@link ResolvableType#getSource()}.
* @param elementType the stream element type to return * @param elementType the type of Objects in the output stream
* Typically the value of a {@code Content-Type} header. * @param request the current request
* @param request the current HTTP request * @param response the current response
* @param response the current HTTP response
* @param hints additional information about how to read the body * @param hints additional information about how to read the body
* @return the converted {@link Mono} of object * @return the decoded stream of elements
*/ */
Mono<T> readMono(ResolvableType streamType, ResolvableType elementType, ServerHttpRequest request, Mono<T> readMono(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request,
ServerHttpResponse response, Map<String, Object> hints); ServerHttpResponse response, Map<String, Object> hints);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 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.
@ -28,29 +28,29 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponse;
/** /**
* Server oriented {@link HttpMessageWriter} that allows to resolve hints using annotations or * An extension of {@code HttpMessageWriter} for encoding and writing the
* perform additional operation using {@link ServerHttpRequest} or {@link ServerHttpResponse}. * response body with extra information available on the server side.
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @author Rossen Stoyanchev
* @since 5.0 * @since 5.0
*/ */
public interface ServerHttpMessageWriter<T> extends HttpMessageWriter<T> { public interface ServerHttpMessageWriter<T> extends HttpMessageWriter<T> {
/** /**
* Write a given object to the given output message with additional server related * Encode and write the given object stream to the response.
* parameters which could be used to create some hints or set the response status for example.
* *
* @param streamType the original type used for the method return value. For annotation * @param actualType the actual return type of the method that returned the
* based controllers, the {@link MethodParameter} is available via {@link ResolvableType#getSource()}. * value; for annotated controllers, the {@link MethodParameter} can be
* Can be {@code null}. * accessed via {@link ResolvableType#getSource()}.
* @param elementType the stream element type to process * @param elementType the type of Objects in the input stream
* @param mediaType the content type to use when writing. May be {@code null} to * @param mediaType the content type to use, possibly {@code null} indicating
* indicate that the default content type of the converter must be used. * the default content type of the writer should be used.
* @param request the current HTTP request * @param request the current request
* @param response the current HTTP response * @param response the current response
* @return a {@link Mono} that indicates completion or error * @return a {@link Mono} that indicates completion of writing or error
*/ */
Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType streamType, Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType actualType,
ResolvableType elementType, MediaType mediaType, ServerHttpRequest request, ResolvableType elementType, MediaType mediaType, ServerHttpRequest request,
ServerHttpResponse response, Map<String, Object> hints); ServerHttpResponse response, Map<String, Object> hints);

View File

@ -87,13 +87,13 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
@Override @Override
public Flux<Object> read(ResolvableType elementType, ReactiveHttpInputMessage inputMessage, public Flux<Object> read(ResolvableType elementType, ReactiveHttpInputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
boolean hasSseWrapper = ServerSentEvent.class.isAssignableFrom(elementType.getRawClass()); boolean hasSseWrapper = ServerSentEvent.class.isAssignableFrom(elementType.getRawClass());
ResolvableType dataType = (hasSseWrapper ? elementType.getGeneric(0) : elementType); ResolvableType dataType = (hasSseWrapper ? elementType.getGeneric(0) : elementType);
return Flux.from(inputMessage.getBody()) return Flux.from(message.getBody())
.concatMap(ServerSentEventHttpMessageReader::splitOnNewline) .concatMap(ServerSentEventHttpMessageReader::splitOnNewline)
.map(buffer -> { .map(buffer -> {
CharBuffer charBuffer = StandardCharsets.UTF_8.decode(buffer.asByteBuffer()); CharBuffer charBuffer = StandardCharsets.UTF_8.decode(buffer.asByteBuffer());
@ -178,13 +178,13 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
} }
@Override @Override
public Mono<Object> readMono(ResolvableType elementType, ReactiveHttpInputMessage inputMessage, public Mono<Object> readMono(ResolvableType elementType, ReactiveHttpInputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
// Let's give StringDecoder a chance since SSE is ordered ahead of it // Let's give StringDecoder a chance since SSE is ordered ahead of it
if (String.class.equals(elementType.getRawClass())) { if (String.class.equals(elementType.getRawClass())) {
Flux<DataBuffer> body = inputMessage.getBody(); Flux<DataBuffer> body = message.getBody();
return stringDecoder.decodeToMono(body, elementType, null, null).cast(Object.class); return stringDecoder.decodeToMono(body, elementType, null, null).cast(Object.class);
} }

View File

@ -87,14 +87,14 @@ public class ServerSentEventHttpMessageWriter implements ServerHttpMessageWriter
@Override @Override
public Mono<Void> write(Publisher<?> inputStream, ResolvableType elementType, MediaType mediaType, public Mono<Void> write(Publisher<?> inputStream, ResolvableType elementType, MediaType mediaType,
ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints) { ReactiveHttpOutputMessage message, Map<String, Object> hints) {
outputMessage.getHeaders().setContentType(MediaType.TEXT_EVENT_STREAM); message.getHeaders().setContentType(MediaType.TEXT_EVENT_STREAM);
DataBufferFactory bufferFactory = outputMessage.bufferFactory(); DataBufferFactory bufferFactory = message.bufferFactory();
Flux<Publisher<DataBuffer>> body = encode(inputStream, bufferFactory, elementType, hints); Flux<Publisher<DataBuffer>> body = encode(inputStream, bufferFactory, elementType, hints);
return outputMessage.writeAndFlushWith(body); return message.writeAndFlushWith(body);
} }
private Flux<Publisher<DataBuffer>> encode(Publisher<?> inputStream, DataBufferFactory bufferFactory, private Flux<Publisher<DataBuffer>> encode(Publisher<?> inputStream, DataBufferFactory bufferFactory,
@ -164,14 +164,14 @@ public class ServerSentEventHttpMessageWriter implements ServerHttpMessageWriter
} }
@Override @Override
public Mono<Void> write(Publisher<?> inputStream, ResolvableType streamType, ResolvableType elementType, public Mono<Void> write(Publisher<?> inputStream, ResolvableType actualType, ResolvableType elementType,
MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response, MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response,
Map<String, Object> hints) { Map<String, Object> hints) {
Map<String, Object> allHints = this.dataEncoders.stream() Map<String, Object> allHints = this.dataEncoders.stream()
.filter(encoder -> encoder instanceof ServerHttpEncoder) .filter(encoder -> encoder instanceof ServerHttpEncoder)
.map(encoder -> (ServerHttpEncoder<?>) encoder) .map(encoder -> (ServerHttpEncoder<?>) encoder)
.map(encoder -> encoder.getEncodeHints(streamType, elementType, mediaType, request, response)) .map(encoder -> encoder.getEncodeHints(actualType, elementType, mediaType, request, response))
.reduce(new HashMap<>(), (t, u) -> { .reduce(new HashMap<>(), (t, u) -> {
t.putAll(u); t.putAll(u);
return t; return t;

View File

@ -97,7 +97,7 @@ public class ExchangeStrategiesTests {
@Override @Override
public Mono<Void> write(Publisher<?> inputStream, ResolvableType type, public Mono<Void> write(Publisher<?> inputStream, ResolvableType type,
MediaType contentType, MediaType contentType,
ReactiveHttpOutputMessage outputMessage, ReactiveHttpOutputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
return Mono.empty(); return Mono.empty();
} }
@ -117,13 +117,13 @@ public class ExchangeStrategiesTests {
} }
@Override @Override
public Flux<Object> read(ResolvableType type, ReactiveHttpInputMessage inputMessage, public Flux<Object> read(ResolvableType type, ReactiveHttpInputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
return Flux.empty(); return Flux.empty();
} }
@Override @Override
public Mono<Object> readMono(ResolvableType type, ReactiveHttpInputMessage inputMessage, public Mono<Object> readMono(ResolvableType type, ReactiveHttpInputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
return Mono.empty(); return Mono.empty();
} }

View File

@ -99,7 +99,7 @@ public class HandlerStrategiesTests {
@Override @Override
public Mono<Void> write(Publisher<?> inputStream, ResolvableType type, public Mono<Void> write(Publisher<?> inputStream, ResolvableType type,
MediaType contentType, MediaType contentType,
ReactiveHttpOutputMessage outputMessage, ReactiveHttpOutputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
return Mono.empty(); return Mono.empty();
} }
@ -119,13 +119,13 @@ public class HandlerStrategiesTests {
} }
@Override @Override
public Flux<Object> read(ResolvableType type, ReactiveHttpInputMessage inputMessage, public Flux<Object> read(ResolvableType type, ReactiveHttpInputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
return Flux.empty(); return Flux.empty();
} }
@Override @Override
public Mono<Object> readMono(ResolvableType type, ReactiveHttpInputMessage inputMessage, public Mono<Object> readMono(ResolvableType type, ReactiveHttpInputMessage message,
Map<String, Object> hints) { Map<String, Object> hints) {
return Mono.empty(); return Mono.empty();
} }