Skip to content

Commit 190b751

Browse files
committed
Support any HttpEntity implementing ResolvableTypeProvider
Closes gh-22931
1 parent c4a95c9 commit 190b751

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

spring-web/src/main/java/org/springframework/http/client/MultipartBodyBuilder.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,9 +25,11 @@
2525

2626
import org.springframework.core.ParameterizedTypeReference;
2727
import org.springframework.core.ResolvableType;
28+
import org.springframework.core.ResolvableTypeProvider;
2829
import org.springframework.http.HttpEntity;
2930
import org.springframework.http.HttpHeaders;
3031
import org.springframework.http.MediaType;
32+
import org.springframework.lang.NonNull;
3133
import org.springframework.lang.Nullable;
3234
import org.springframework.util.Assert;
3335
import org.springframework.util.LinkedMultiValueMap;
@@ -263,13 +265,13 @@ public HttpEntity<?> build() {
263265
* @param <T> the type contained in the publisher
264266
* @param <P> the publisher
265267
*/
266-
public static final class PublisherEntity<T, P extends Publisher<T>> extends HttpEntity<P> {
268+
public static final class PublisherEntity<T, P extends Publisher<T>> extends HttpEntity<P>
269+
implements ResolvableTypeProvider {
267270

268271
private final ResolvableType resolvableType;
269272

270-
271-
private PublisherEntity(@Nullable MultiValueMap<String, String> headers, P publisher,
272-
ResolvableType resolvableType) {
273+
PublisherEntity(
274+
@Nullable MultiValueMap<String, String> headers, P publisher, ResolvableType resolvableType) {
273275

274276
super(publisher, headers);
275277
Assert.notNull(publisher, "'publisher' must not be null");
@@ -280,6 +282,8 @@ private PublisherEntity(@Nullable MultiValueMap<String, String> headers, P publi
280282
/**
281283
* Return the element type for the {@code Publisher} body.
282284
*/
285+
@Override
286+
@NonNull
283287
public ResolvableType getResolvableType() {
284288
return this.resolvableType;
285289
}

spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import reactor.core.publisher.Mono;
3535

3636
import org.springframework.core.ResolvableType;
37+
import org.springframework.core.ResolvableTypeProvider;
3738
import org.springframework.core.codec.CharSequenceEncoder;
3839
import org.springframework.core.codec.CodecException;
3940
import org.springframework.core.codec.Hints;
@@ -46,7 +47,6 @@
4647
import org.springframework.http.HttpHeaders;
4748
import org.springframework.http.MediaType;
4849
import org.springframework.http.ReactiveHttpOutputMessage;
49-
import org.springframework.http.client.MultipartBodyBuilder;
5050
import org.springframework.http.codec.EncoderHttpMessageWriter;
5151
import org.springframework.http.codec.FormHttpMessageWriter;
5252
import org.springframework.http.codec.HttpMessageWriter;
@@ -265,11 +265,8 @@ private <T> Flux<DataBuffer> encodePart(byte[] boundary, String name, T value, D
265265
outputHeaders.putAll(httpEntity.getHeaders());
266266
body = httpEntity.getBody();
267267
Assert.state(body != null, "MultipartHttpMessageWriter only supports HttpEntity with body");
268-
269-
if (httpEntity instanceof MultipartBodyBuilder.PublisherEntity<?, ?>) {
270-
MultipartBodyBuilder.PublisherEntity<?, ?> publisherEntity =
271-
(MultipartBodyBuilder.PublisherEntity<?, ?>) httpEntity;
272-
resolvableType = publisherEntity.getResolvableType();
268+
if (httpEntity instanceof ResolvableTypeProvider) {
269+
resolvableType = ((ResolvableTypeProvider) httpEntity).getResolvableType();
273270
}
274271
}
275272
else {

0 commit comments

Comments
 (0)