From 6dd0e6bfac8600c02e9ff431baaa8532b7ac6201 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Thu, 9 Feb 2017 17:23:15 +0100 Subject: [PATCH] Reverse "Correct generic type in BodyExtractor for form data" This commit reverses 9efa976d31a3d91cec8745a473aba89c6539135c, 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. --- .../web/reactive/function/BodyExtractor.java | 3 ++- .../web/reactive/function/BodyExtractors.java | 5 ++++- .../web/reactive/function/BodyInserter.java | 4 +++- .../web/reactive/function/BodyInserters.java | 9 +++++++++ .../web/reactive/function/BodyExtractorsTests.java | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractor.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractor.java index acce1c5dd9..699648cc83 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractor.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractor.java @@ -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 the type of data to extract + * @param the type of {@link ReactiveHttpInputMessage} this extractor can be applied to * @author Arjen Poutsma * @since 5.0 * @see BodyExtractors diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java index 28e5b7ab4c..2bc05c543a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java @@ -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>, 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>, ServerHttpRequest> toFormData() { return (serverRequest, context) -> { HttpMessageReader> messageReader = formMessageReader(context); return messageReader.readMono(FORM_TYPE, serverRequest, context.hints()); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserter.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserter.java index 1e5f85e66e..18c82e7eaa 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserter.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserter.java @@ -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 the type of data to insert + * @param the type of {@link ReactiveHttpOutputMessage} this inserter can be applied to * @author Arjen Poutsma * @since 5.0 * @see BodyInserters diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java index 2bccd10eeb..bb56868c93 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java @@ -143,6 +143,9 @@ public abstract class BodyInserters { * @return a {@code BodyInserter} that writes a {@code ServerSentEvent} publisher * @see Server-Sent Events W3C recommendation */ + // 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 >> BodyInserter fromServerSentEvents( S eventsPublisher) { @@ -165,6 +168,9 @@ public abstract class BodyInserters { * Server-Sent Events * @see Server-Sent Events W3C recommendation */ + // 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 > BodyInserter fromServerSentEvents(S eventsPublisher, Class eventClass) { @@ -183,6 +189,9 @@ public abstract class BodyInserters { * Server-Sent Events * @see Server-Sent Events W3C recommendation */ + // 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 > BodyInserter fromServerSentEvents(S eventsPublisher, ResolvableType eventType) { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java index a027258f23..a6f4b54ea2 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java @@ -207,7 +207,7 @@ public class BodyExtractorsTests { @Test public void toFormData() throws Exception { - BodyExtractor>, ReactiveHttpInputMessage> extractor = BodyExtractors.toFormData(); + BodyExtractor>, ServerHttpRequest> extractor = BodyExtractors.toFormData(); DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer =