Browse Source

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.
pull/1294/merge
Arjen Poutsma 8 years ago
parent
commit
6dd0e6bfac
  1. 3
      spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractor.java
  2. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java
  3. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserter.java
  4. 9
      spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java
  5. 2
      spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java

3
spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractor.java

@ -1,5 +1,5 @@ @@ -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; @@ -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

5
spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java

@ -102,7 +102,10 @@ public abstract class BodyExtractors { @@ -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());

4
spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserter.java

@ -1,5 +1,5 @@ @@ -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; @@ -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

9
spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java

@ -143,6 +143,9 @@ public abstract class BodyInserters { @@ -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 { @@ -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 { @@ -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) {

2
spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java

@ -207,7 +207,7 @@ public class BodyExtractorsTests { @@ -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 =

Loading…
Cancel
Save