Browse Source

Merge branch '5.1.x'

pull/22935/head
Juergen Hoeller 6 years ago
parent
commit
8b08b6812a
  1. 12
      spring-web/src/main/java/org/springframework/http/client/MultipartBodyBuilder.java
  2. 9
      spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java

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

@ -26,11 +26,13 @@ import reactor.core.publisher.Mono; @@ -26,11 +26,13 @@ import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.ResolvableType;
import org.springframework.core.ResolvableTypeProvider;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.codec.multipart.Part;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
@ -272,13 +274,13 @@ public final class MultipartBodyBuilder { @@ -272,13 +274,13 @@ public final class MultipartBodyBuilder {
* @param <T> the type contained in the publisher
* @param <P> the publisher
*/
public static final class PublisherEntity<T, P extends Publisher<T>> extends HttpEntity<P> {
public static final class PublisherEntity<T, P extends Publisher<T>> extends HttpEntity<P>
implements ResolvableTypeProvider {
private final ResolvableType resolvableType;
private PublisherEntity(@Nullable MultiValueMap<String, String> headers, P publisher,
ResolvableType resolvableType) {
PublisherEntity(
@Nullable MultiValueMap<String, String> headers, P publisher, ResolvableType resolvableType) {
super(publisher, headers);
Assert.notNull(publisher, "'publisher' must not be null");
@ -289,6 +291,8 @@ public final class MultipartBodyBuilder { @@ -289,6 +291,8 @@ public final class MultipartBodyBuilder {
/**
* Return the element type for the {@code Publisher} body.
*/
@Override
@NonNull
public ResolvableType getResolvableType() {
return this.resolvableType;
}

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

@ -34,6 +34,7 @@ import reactor.core.publisher.Flux; @@ -34,6 +34,7 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ResolvableType;
import org.springframework.core.ResolvableTypeProvider;
import org.springframework.core.codec.CharSequenceEncoder;
import org.springframework.core.codec.CodecException;
import org.springframework.core.codec.Hints;
@ -46,7 +47,6 @@ import org.springframework.http.HttpEntity; @@ -46,7 +47,6 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ReactiveHttpOutputMessage;
import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.http.codec.EncoderHttpMessageWriter;
import org.springframework.http.codec.FormHttpMessageWriter;
import org.springframework.http.codec.HttpMessageWriter;
@ -265,11 +265,8 @@ public class MultipartHttpMessageWriter extends LoggingCodecSupport @@ -265,11 +265,8 @@ public class MultipartHttpMessageWriter extends LoggingCodecSupport
outputHeaders.putAll(httpEntity.getHeaders());
body = httpEntity.getBody();
Assert.state(body != null, "MultipartHttpMessageWriter only supports HttpEntity with body");
if (httpEntity instanceof MultipartBodyBuilder.PublisherEntity<?, ?>) {
MultipartBodyBuilder.PublisherEntity<?, ?> publisherEntity =
(MultipartBodyBuilder.PublisherEntity<?, ?>) httpEntity;
resolvableType = publisherEntity.getResolvableType();
if (httpEntity instanceof ResolvableTypeProvider) {
resolvableType = ((ResolvableTypeProvider) httpEntity).getResolvableType();
}
}
else {

Loading…
Cancel
Save