@ -143,8 +143,8 @@ public final class MultipartBodyBuilder {
@@ -143,8 +143,8 @@ public final class MultipartBodyBuilder {
Assert . notNull ( elementType , "'elementType' must not be null" ) ;
HttpHeaders partHeaders = new HttpHeaders ( ) ;
PublisherClass PartBuilder < T , P > builder =
new PublisherClass PartBuilder < > ( publisher , elementClass , partHeaders ) ;
PublisherPartBuilder < T , P > builder =
new PublisherPartBuilder < > ( publisher , elementClass , partHeaders ) ;
this . parts . add ( name , builder ) ;
return builder ;
@ -155,21 +155,21 @@ public final class MultipartBodyBuilder {
@@ -155,21 +155,21 @@ public final class MultipartBodyBuilder {
* the returned { @link PartBuilder } .
* @param name the name of the part to add ( may not be empty )
* @param publisher the contents of the part to add
* @param elementTyp e the type of elements contained in the publisher
* @param typeReferenc e the type of elements contained in the publisher
* @return a builder that allows for further header customization
* /
public < T , P extends Publisher < T > > PartBuilder asyncPart ( String name , P publisher ,
ParameterizedTypeReference < T > elementTyp e) {
ParameterizedTypeReference < T > typeReferenc e) {
Assert . notNull ( elementType , "'elementTyp e' must not be null") ;
ResolvableType elementType1 = ResolvableType . forType ( elementTyp e) ;
Assert . notNull ( typeReference , "'typeReferenc e' must not be null") ;
ResolvableType elementType1 = ResolvableType . forType ( typeReferenc e) ;
Assert . hasLength ( name , "'name' must not be empty" ) ;
Assert . notNull ( publisher , "'publisher' must not be null" ) ;
Assert . notNull ( elementType1 , "'elementTyp e' must not be null" ) ;
Assert . notNull ( elementType1 , "'typeReferenc e' must not be null" ) ;
HttpHeaders partHeaders = new HttpHeaders ( ) ;
PublisherTypReference PartBuilder < T , P > builder =
new PublisherTypReference PartBuilder < > ( publisher , elementTyp e, partHeaders ) ;
PublisherPartBuilder < T , P > builder =
new PublisherPartBuilder < > ( publisher , typeReferenc e, partHeaders ) ;
this . parts . add ( name , builder ) ;
return builder ;
}
@ -213,43 +213,57 @@ public final class MultipartBodyBuilder {
@@ -213,43 +213,57 @@ public final class MultipartBodyBuilder {
}
}
private static class PublisherClass PartBuilder < S , P extends Publisher < S > >
private static class PublisherPartBuilder < S , P extends Publisher < S > >
extends DefaultPartBuilder {
private final Class < S > body Type;
private final ResolvableType resolvable Type;
public PublisherClass PartBuilder ( P body , Class < S > bodyType , HttpHeaders headers ) {
public PublisherPartBuilder ( P body , Class < S > elementClass , HttpHeaders headers ) {
super ( body , headers ) ;
this . bodyType = bodyType ;
this . resolvableType = ResolvableType . forClass ( elementClass ) ;
}
public PublisherPartBuilder ( P body , ParameterizedTypeReference < S > typeReference ,
HttpHeaders headers ) {
super ( body , headers ) ;
this . resolvableType = ResolvableType . forType ( typeReference ) ;
}
@Override
@SuppressWarnings ( "unchecked" )
public HttpEntity < ? > build ( ) {
P body = ( P ) this . body ;
Assert . state ( body ! = null , "'body' must not be null" ) ;
return HttpEntity . fromPublisher ( body , this . body Type, this . headers ) ;
P publisher = ( P ) this . body ;
Assert . state ( publisher ! = null , "'publisher ' must not be null" ) ;
return new PublisherEntity < > ( publisher , this . resolvable Type, this . headers ) ;
}
}
private static class PublisherTypReferencePartBuilder < S , P extends Publisher < S > >
extends DefaultPartBuilder {
private final ParameterizedTypeReference < S > bodyType ;
/ * *
* Specific subtype of { @link HttpEntity } for containing { @link Publisher } s as body .
* Exposes the type contained in the publisher through { @link # getResolvableType ( ) } .
* @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 PublisherTypReferencePartBuilder ( P body , ParameterizedTypeReference < S > bodyType ,
HttpHeaders headers ) {
private final ResolvableType resolvableType ;
super ( body , headers ) ;
this . bodyType = bodyType ;
PublisherEntity ( P publisher , ResolvableType resolvableType ,
@Nullable MultiValueMap < String , String > headers ) {
super ( publisher , headers ) ;
Assert . notNull ( publisher , "'publisher' must not be null" ) ;
Assert . notNull ( resolvableType , "'resolvableType' must not be null" ) ;
this . resolvableType = resolvableType ;
}
@Override
@SuppressWarnings ( "unchecked" )
public HttpEntity < ? > build ( ) {
P body = ( P ) this . body ;
Assert . state ( body ! = null , "'body' must not be null" ) ;
return HttpEntity . fromPublisher ( body , this . bodyType , this . headers ) ;
/ * *
* Return the resolvable type for this entry .
* /
public ResolvableType getResolvableType ( ) {
return this . resolvableType ;
}
}