@ -71,12 +71,14 @@ import org.springframework.http.HttpStatusCode;
@@ -71,12 +71,14 @@ import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType ;
import org.springframework.http.ResponseCookie ;
import org.springframework.http.ResponseEntity ;
import org.springframework.http.client.MultipartBodyBuilder ;
import org.springframework.http.client.reactive.ClientHttpConnector ;
import org.springframework.http.client.reactive.HttpComponentsClientHttpConnector ;
import org.springframework.http.client.reactive.JdkClientHttpConnector ;
import org.springframework.http.client.reactive.JettyClientHttpConnector ;
import org.springframework.http.client.reactive.ReactorClientHttpConnector ;
import org.springframework.web.reactive.function.BodyExtractors ;
import org.springframework.web.reactive.function.BodyInserters ;
import org.springframework.web.reactive.function.client.WebClient.ResponseSpec ;
import org.springframework.web.testfixture.xml.Pojo ;
@ -1320,6 +1322,34 @@ class WebClientIntegrationTests {
@@ -1320,6 +1322,34 @@ class WebClientIntegrationTests {
. verify ( Duration . ofSeconds ( 3 ) ) ;
}
@ParameterizedWebClientTest
void failWhileSendingMultipartRequest ( ClientHttpConnector connector ) throws IOException {
startServer ( connector ) ;
prepareResponse ( response - > response
. setHeader ( "Content-Type" , "text/plain" ) . body ( "Hello" ) ) ;
MultipartBodyBuilder data = new MultipartBodyBuilder ( ) ;
data . part ( "first" , "success" ) ;
data . asyncPart ( "second" ,
Mono . delay ( Duration . ofMillis ( 500 ) ) . then ( Mono . error ( new IllegalStateException ( "multipart client error" ) ) ) ,
String . class ) ;
Mono < ResponseEntity < String > > result = this . webClient . post ( )
. uri ( "/multipart" ) . accept ( MediaType . TEXT_PLAIN )
. body ( BodyInserters . fromMultipartData ( data . build ( ) ) )
. retrieve ( )
. toEntity ( String . class )
. log ( ) ;
StepVerifier . create ( result )
. expectErrorSatisfies ( error - > assertThat ( error )
. isInstanceOf ( WebClientRequestException . class )
. hasMessageContaining ( "multipart client error" ) )
. verify ( Duration . ofSeconds ( 5 ) ) ;
expectRequestCount ( 0 ) ;
}
private < T > Mono < T > doMalformedChunkedResponseTest (
ClientHttpConnector connector , Function < ResponseSpec , Mono < T > > handler ) {