Reverse "Correct generic type in BodyExtractor for form data"

This commit reverses 9efa976d31, and adds
code comments to highlight why some Body[Inserter|Extractor] instances
returned from Body[Inserters|Extractors] use
ServerHttp[Request|Response] instead of using
Reactive[Input|Output]Message.
This commit is contained in:
Arjen Poutsma 2017-02-09 17:23:15 +01:00
parent 11efbaead9
commit 6dd0e6bfac
5 changed files with 19 additions and 4 deletions

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");
* you may not use this file except in compliance with the License.
@ -27,6 +27,7 @@ import org.springframework.http.codec.HttpMessageReader;
* A function that can extract data from a {@link ReactiveHttpInputMessage} body.
*
* @param <T> the type of data to extract
* @param <M> the type of {@link ReactiveHttpInputMessage} this extractor can be applied to
* @author Arjen Poutsma
* @since 5.0
* @see BodyExtractors

View File

@ -102,7 +102,10 @@ public abstract class BodyExtractors {
* Return a {@code BodyExtractor} that reads form data into a {@link MultiValueMap}.
* @return a {@code BodyExtractor} that reads form data
*/
public static BodyExtractor<Mono<MultiValueMap<String, String>>, ReactiveHttpInputMessage> toFormData() {
// Note that the returned BodyExtractor is parameterized to ServerHttpRequest, not
// ReactiveHttpInputMessage like other methods, since reading form data only typically happens on
// the server-side
public static BodyExtractor<Mono<MultiValueMap<String, String>>, ServerHttpRequest> toFormData() {
return (serverRequest, context) -> {
HttpMessageReader<MultiValueMap<String, String>> messageReader = formMessageReader(context);
return messageReader.readMono(FORM_TYPE, serverRequest, context.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");
* you may not use this file except in compliance with the License.
@ -28,6 +28,8 @@ import org.springframework.http.codec.HttpMessageWriter;
/**
* A combination of functions that can populate a {@link ReactiveHttpOutputMessage} body.
*
* @param <T> the type of data to insert
* @param <M> the type of {@link ReactiveHttpOutputMessage} this inserter can be applied to
* @author Arjen Poutsma
* @since 5.0
* @see BodyInserters

View File

@ -143,6 +143,9 @@ public abstract class BodyInserters {
* @return a {@code BodyInserter} that writes a {@code ServerSentEvent} publisher
* @see <a href="https://www.w3.org/TR/eventsource/">Server-Sent Events W3C recommendation</a>
*/
// Note that the returned BodyInserter is parameterized to ServerHttpResponse, not
// ReactiveHttpOutputMessage like other methods, since sending SSEs only typically happens on
// the server-side
public static <T, S extends Publisher<ServerSentEvent<T>>> BodyInserter<S, ServerHttpResponse> fromServerSentEvents(
S eventsPublisher) {
@ -165,6 +168,9 @@ public abstract class BodyInserters {
* Server-Sent Events
* @see <a href="https://www.w3.org/TR/eventsource/">Server-Sent Events W3C recommendation</a>
*/
// Note that the returned BodyInserter is parameterized to ServerHttpResponse, not
// ReactiveHttpOutputMessage like other methods, since sending SSEs only typically happens on
// the server-side
public static <T, S extends Publisher<T>> BodyInserter<S, ServerHttpResponse> fromServerSentEvents(S eventsPublisher,
Class<T> eventClass) {
@ -183,6 +189,9 @@ public abstract class BodyInserters {
* Server-Sent Events
* @see <a href="https://www.w3.org/TR/eventsource/">Server-Sent Events W3C recommendation</a>
*/
// Note that the returned BodyInserter is parameterized to ServerHttpResponse, not
// ReactiveHttpOutputMessage like other methods, since sending SSEs only typically happens on
// the server-side
public static <T, S extends Publisher<T>> BodyInserter<S, ServerHttpResponse> fromServerSentEvents(S eventsPublisher,
ResolvableType eventType) {

View File

@ -207,7 +207,7 @@ public class BodyExtractorsTests {
@Test
public void toFormData() throws Exception {
BodyExtractor<Mono<MultiValueMap<String, String>>, ReactiveHttpInputMessage> extractor = BodyExtractors.toFormData();
BodyExtractor<Mono<MultiValueMap<String, String>>, ServerHttpRequest> extractor = BodyExtractors.toFormData();
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
DefaultDataBuffer dataBuffer =