Skip to content

Commit 2909de8

Browse files
committed
Remove ServerWebExchange::getParts and ServerRequest::parts
Revert to state before DefaultMultipartMessageReader
1 parent 09572e7 commit 2909de8

File tree

11 files changed

+26
-116
lines changed

11 files changed

+26
-116
lines changed

spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,6 @@ public Mono<MultiValueMap<String, Part>> multipartData() {
249249
return (Mono<MultiValueMap<String, Part>>) this.body;
250250
}
251251

252-
@Override
253-
@SuppressWarnings("unchecked")
254-
public Flux<Part> parts() {
255-
Assert.state(this.body != null, "No body");
256-
return (Flux<Part>) this.body;
257-
}
258-
259252
@Override
260253
public ServerWebExchange exchange() {
261254
Assert.state(this.exchange != null, "No exchange");

spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.function.Consumer;
2323
import java.util.function.Function;
2424

25-
import reactor.core.publisher.Flux;
2625
import reactor.core.publisher.Mono;
2726

2827
import org.springframework.context.ApplicationContext;
@@ -139,23 +138,9 @@ default <T> T getAttributeOrDefault(String name, T defaultValue) {
139138
* cached so that this method is safe to call more than once.
140139
* <p><strong>Note:</strong>the {@linkplain Part#content() contents} of each
141140
* part is not cached, and can only be read once.
142-
* @see #getParts()
143141
*/
144142
Mono<MultiValueMap<String, Part>> getMultipartData();
145143

146-
/**
147-
* Return the parts of a multipart request if the Content-Type is
148-
* {@code "multipart/form-data"} or an empty flux otherwise.
149-
* <p><strong>Note:</strong> calling this method causes the request body to
150-
* be read and parsed in full and the resulting {@code Flux} is
151-
* cached so that this method is safe to call more than once.
152-
* <p><strong>Note:</strong>the {@linkplain Part#content() contents} of each
153-
* part is not cached, and can only be read once.
154-
* @since 5.2
155-
* @see #getMultipartData()
156-
*/
157-
Flux<Part> getParts();
158-
159144
/**
160145
* Return the {@link LocaleContext} using the configured
161146
* {@link org.springframework.web.server.i18n.LocaleContextResolver}.

spring-web/src/main/java/org/springframework/web/server/ServerWebExchangeDecorator.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Map;
2121
import java.util.function.Function;
2222

23-
import reactor.core.publisher.Flux;
2423
import reactor.core.publisher.Mono;
2524

2625
import org.springframework.context.ApplicationContext;
@@ -108,11 +107,6 @@ public Mono<MultiValueMap<String, Part>> getMultipartData() {
108107
return getDelegate().getMultipartData();
109108
}
110109

111-
@Override
112-
public Flux<Part> getParts() {
113-
return getDelegate().getParts();
114-
}
115-
116110
@Override
117111
public boolean isNotModified() {
118112
return getDelegate().isNotModified();

spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.concurrent.ConcurrentHashMap;
2626
import java.util.function.Function;
2727

28-
import reactor.core.publisher.Flux;
2928
import reactor.core.publisher.Mono;
3029

3130
import org.springframework.context.ApplicationContext;
@@ -66,7 +65,8 @@ public class DefaultServerWebExchange implements ServerWebExchange {
6665
private static final ResolvableType FORM_DATA_TYPE =
6766
ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, String.class);
6867

69-
private static final ResolvableType PARTS_DATA_TYPE = ResolvableType.forClass(Part.class);
68+
private static final ResolvableType MULTIPART_DATA_TYPE = ResolvableType.forClassWithGenerics(
69+
MultiValueMap.class, String.class, Part.class);
7070

7171
private static final Mono<MultiValueMap<String, String>> EMPTY_FORM_DATA =
7272
Mono.just(CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<String, String>(0)))
@@ -91,8 +91,6 @@ public class DefaultServerWebExchange implements ServerWebExchange {
9191

9292
private final Mono<MultiValueMap<String, Part>> multipartDataMono;
9393

94-
private final Flux<Part> partFlux;
95-
9694
@Nullable
9795
private final ApplicationContext applicationContext;
9896

@@ -131,8 +129,7 @@ public DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse re
131129
this.sessionMono = sessionManager.getSession(this).cache();
132130
this.localeContextResolver = localeContextResolver;
133131
this.formDataMono = initFormData(request, codecConfigurer, getLogPrefix());
134-
this.partFlux = initParts(request, codecConfigurer, getLogPrefix());
135-
this.multipartDataMono = initMultipartData(this.partFlux);
132+
this.multipartDataMono = initMultipartData(request, codecConfigurer, getLogPrefix());
136133
this.applicationContext = applicationContext;
137134
}
138135

@@ -159,34 +156,28 @@ private static Mono<MultiValueMap<String, String>> initFormData(ServerHttpReques
159156
}
160157

161158
@SuppressWarnings("unchecked")
162-
private static Flux<Part> initParts(ServerHttpRequest request, ServerCodecConfigurer configurer, String logPrefix) {
159+
private static Mono<MultiValueMap<String, Part>> initMultipartData(ServerHttpRequest request,
160+
ServerCodecConfigurer configurer, String logPrefix) {
161+
163162
try {
164163
MediaType contentType = request.getHeaders().getContentType();
165164
if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType)) {
166-
return ((HttpMessageReader<Part>)configurer.getReaders().stream()
167-
.filter(reader -> reader.canRead(PARTS_DATA_TYPE, MediaType.MULTIPART_FORM_DATA))
165+
return ((HttpMessageReader<MultiValueMap<String, Part>>) configurer.getReaders().stream()
166+
.filter(reader -> reader.canRead(MULTIPART_DATA_TYPE, MediaType.MULTIPART_FORM_DATA))
168167
.findFirst()
169168
.orElseThrow(() -> new IllegalStateException("No multipart HttpMessageReader.")))
170-
.read(PARTS_DATA_TYPE, request, Hints.from(Hints.LOG_PREFIX_HINT, logPrefix))
169+
.readMono(MULTIPART_DATA_TYPE, request, Hints.from(Hints.LOG_PREFIX_HINT, logPrefix))
170+
.switchIfEmpty(EMPTY_MULTIPART_DATA)
171171
.cache();
172172
}
173173
}
174174
catch (InvalidMediaTypeException ex) {
175175
// Ignore
176176
}
177-
return Flux.empty();
178-
}
179-
180-
private static Mono<MultiValueMap<String, Part>> initMultipartData(Flux<Part> parts) {
181-
return parts.collect(
182-
() -> (MultiValueMap<String, Part>) new LinkedMultiValueMap<String, Part>(),
183-
(map, part) -> map.add(part.name(), part))
184-
.switchIfEmpty(EMPTY_MULTIPART_DATA)
185-
.cache();
177+
return EMPTY_MULTIPART_DATA;
186178
}
187179

188180

189-
190181
@Override
191182
public ServerHttpRequest getRequest() {
192183
return this.request;
@@ -230,11 +221,6 @@ public Mono<MultiValueMap<String, Part>> getMultipartData() {
230221
return this.multipartDataMono;
231222
}
232223

233-
@Override
234-
public Flux<Part> getParts() {
235-
return this.partFlux;
236-
}
237-
238224
@Override
239225
public LocaleContext getLocaleContext() {
240226
return this.localeContextResolver.resolveLocaleContext(this);

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,6 @@ public Mono<MultiValueMap<String, Part>> multipartData() {
220220
return this.exchange.getMultipartData();
221221
}
222222

223-
@Override
224-
public Flux<Part> parts() {
225-
return this.exchange.getParts();
226-
}
227-
228223
private ServerHttpRequest request() {
229224
return this.exchange.getRequest();
230225
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequestBuilder.java

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ private static class DelegatingServerWebExchange implements ServerWebExchange {
290290
private static final ResolvableType FORM_DATA_TYPE =
291291
ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, String.class);
292292

293-
private static final ResolvableType PARTS_DATA_TYPE = ResolvableType.forClass(Part.class);
293+
private static final ResolvableType MULTIPART_DATA_TYPE = ResolvableType.forClassWithGenerics(
294+
MultiValueMap.class, String.class, Part.class);
294295

295296
private static final Mono<MultiValueMap<String, String>> EMPTY_FORM_DATA =
296297
Mono.just(CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<String, String>(0))).cache();
@@ -306,16 +307,13 @@ private static class DelegatingServerWebExchange implements ServerWebExchange {
306307

307308
private final Mono<MultiValueMap<String, Part>> multipartDataMono;
308309

309-
private final Flux<Part> parts;
310-
311310
public DelegatingServerWebExchange(
312311
ServerHttpRequest request, ServerWebExchange delegate, List<HttpMessageReader<?>> messageReaders) {
313312

314313
this.request = request;
315314
this.delegate = delegate;
316315
this.formDataMono = initFormData(request, messageReaders);
317-
this.parts = initParts(request, messageReaders);
318-
this.multipartDataMono = initMultipartData(this.parts);
316+
this.multipartDataMono = initMultipartData(request, messageReaders);
319317
}
320318

321319
@SuppressWarnings("unchecked")
@@ -341,32 +339,26 @@ private static Mono<MultiValueMap<String, String>> initFormData(ServerHttpReques
341339
}
342340

343341
@SuppressWarnings("unchecked")
344-
private static Flux<Part> initParts(ServerHttpRequest request, List<HttpMessageReader<?>> readers) {
342+
private static Mono<MultiValueMap<String, Part>> initMultipartData(ServerHttpRequest request,
343+
List<HttpMessageReader<?>> readers) {
345344

346345
try {
347346
MediaType contentType = request.getHeaders().getContentType();
348347
if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType)) {
349-
return ((HttpMessageReader<Part>)readers.stream()
350-
.filter(reader -> reader.canRead(PARTS_DATA_TYPE, MediaType.MULTIPART_FORM_DATA))
348+
return ((HttpMessageReader<MultiValueMap<String, Part>>) readers.stream()
349+
.filter(reader -> reader.canRead(MULTIPART_DATA_TYPE, MediaType.MULTIPART_FORM_DATA))
351350
.findFirst()
352351
.orElseThrow(() -> new IllegalStateException("No multipart HttpMessageReader.")))
353-
.read(PARTS_DATA_TYPE, request, Hints.none());
352+
.readMono(MULTIPART_DATA_TYPE, request, Hints.none())
353+
.switchIfEmpty(EMPTY_MULTIPART_DATA)
354+
.cache();
354355
}
355356
}
356357
catch (InvalidMediaTypeException ex) {
357358
// Ignore
358359
}
359-
return Flux.empty();
360-
}
361-
362-
private static Mono<MultiValueMap<String, Part>> initMultipartData(Flux<Part> parts) {
363-
return parts.collect(
364-
() -> (MultiValueMap<String, Part>) new LinkedMultiValueMap<String, Part>(),
365-
(map, part) -> map.add(part.name(), part))
366-
.switchIfEmpty(EMPTY_MULTIPART_DATA)
367-
.cache();
360+
return EMPTY_MULTIPART_DATA;
368361
}
369-
370362
@Override
371363
public ServerHttpRequest getRequest() {
372364
return this.request;
@@ -382,11 +374,6 @@ public Mono<MultiValueMap<String, Part>> getMultipartData() {
382374
return this.multipartDataMono;
383375
}
384376

385-
@Override
386-
public Flux<Part> getParts() {
387-
return this.parts;
388-
}
389-
390377
// Delegating methods
391378

392379
@Override

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,11 +1025,6 @@ public Mono<MultiValueMap<String, Part>> multipartData() {
10251025
return this.request.multipartData();
10261026
}
10271027

1028-
@Override
1029-
public Flux<Part> parts() {
1030-
return this.request.parts();
1031-
}
1032-
10331028
@Override
10341029
public ServerWebExchange exchange() {
10351030
return this.request.exchange();

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -270,23 +270,9 @@ default String pathVariable(String name) {
270270
* <p><strong>Note:</strong> calling this method causes the request body to
271271
* be read and parsed in full, and the resulting {@code MultiValueMap} is
272272
* cached so that this method is safe to call more than once.
273-
* <p><strong>Note:</strong>the {@linkplain Part#content() contents} of each
274-
* part is not cached, and can only be read once.
275273
*/
276274
Mono<MultiValueMap<String, Part>> multipartData();
277275

278-
/**
279-
* Get the parts of a multipart request if the Content-Type is
280-
* {@code "multipart/form-data"} or an empty flux otherwise.
281-
* <p><strong>Note:</strong> calling this method causes the request body to
282-
* be read and parsed in full and the resulting {@code Flux} is
283-
* cached so that this method is safe to call more than once.
284-
* <p><strong>Note:</strong>the {@linkplain Part#content() contents} of each
285-
* part is not cached, and can only be read once.
286-
* @since 5.2
287-
*/
288-
Flux<Part> parts();
289-
290276
/**
291277
* Get the web exchange that this request is based on.
292278
* <p>Note: Manipulating the exchange directly (instead of using the methods provided on

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,6 @@ public Mono<MultiValueMap<String, Part>> multipartData() {
208208
return this.delegate.multipartData();
209209
}
210210

211-
@Override
212-
public Flux<Part> parts() {
213-
return this.delegate.parts();
214-
}
215-
216211
@Override
217212
public ServerWebExchange exchange() {
218213
return this.delegate.exchange();

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ protected RouterFunction<ServerResponse> routerFunction() {
129129
private static class MultipartHandler {
130130

131131
public Mono<ServerResponse> multipartData(ServerRequest request) {
132-
return request.multipartData()
132+
return request
133+
.body(BodyExtractors.toMultipartData())
133134
.flatMap(map -> {
134135
Map<String, Part> parts = map.toSingleValueMap();
135136
try {
@@ -145,7 +146,7 @@ public Mono<ServerResponse> multipartData(ServerRequest request) {
145146
}
146147

147148
public Mono<ServerResponse> parts(ServerRequest request) {
148-
return request.parts().collectList()
149+
return request.body(BodyExtractors.toParts()).collectList()
149150
.flatMap(parts -> {
150151
try {
151152
assertThat(parts.size()).isEqualTo(2);
@@ -160,7 +161,7 @@ public Mono<ServerResponse> parts(ServerRequest request) {
160161
}
161162

162163
public Mono<ServerResponse> transferTo(ServerRequest request) {
163-
return request.parts()
164+
return request.body(BodyExtractors.toParts())
164165
.filter(part -> part instanceof FilePart)
165166
.next()
166167
.cast(FilePart.class)

spring-webflux/src/test/java/org/springframework/web/reactive/function/server/MockServerRequest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,6 @@ public Mono<MultiValueMap<String, Part>> multipartData() {
247247
return (Mono<MultiValueMap<String, Part>>) this.body;
248248
}
249249

250-
@Override
251-
@SuppressWarnings("unchecked")
252-
public Flux<Part> parts() {
253-
Assert.state(this.body != null, "No body");
254-
return (Flux<Part>) this.body;
255-
}
256-
257250
@Override
258251
public ServerWebExchange exchange() {
259252
Assert.state(this.exchange != null, "No exchange");

0 commit comments

Comments
 (0)