@@ -14,6 +14,7 @@ support for the following:
14
14
* https://github.com/reactor/reactor-netty[Reactor Netty]
15
15
* https://github.com/jetty-project/jetty-reactive-httpclient[Jetty Reactive HttpClient]
16
16
* https://hc.apache.org/index.html[Apache HttpComponents]
17
+ * https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html[JDK HttpClient]
17
18
* Others can be plugged via `ClientHttpConnector`.
18
19
19
20
@@ -382,7 +383,7 @@ shows:
382
383
383
384
HttpClient httpClient = new HttpClient();
384
385
// Further customizations...
385
-
386
+
386
387
ClientHttpConnector connector =
387
388
new JettyClientHttpConnector(httpClient, resourceFactory()); <1>
388
389
@@ -403,7 +404,7 @@ shows:
403
404
404
405
val httpClient = HttpClient()
405
406
// Further customizations...
406
-
407
+
407
408
val connector = JettyClientHttpConnector(httpClient, resourceFactory()) // <1>
408
409
409
410
return WebClient.builder().clientConnector(connector).build() // <2>
@@ -439,6 +440,43 @@ The following example shows how to customize Apache HttpComponents `HttpClient`
439
440
val webClient = WebClient.builder().clientConnector(connector).build()
440
441
----
441
442
443
+ [[webflux-client-builder-jdk-httpclient]]
444
+ === JDK
445
+ The following example shows how to customize JDK `HttpClient` settings:
446
+
447
+ [source,java,indent=0,subs="verbatim,quotes",role="primary"]
448
+ .Java
449
+ ----
450
+ @Bean
451
+ public WebClient webClient() {
452
+ HttpClient httpClient = HttpClient.newBuilder()
453
+ .executor(...)
454
+ .connectTimeout(...)
455
+ .build();
456
+ ClientHttpConnector connector =
457
+ new JdkClientHttpConnector(httpClient, new DefaultDataBufferFactory()); // <1>
458
+
459
+ return WebClient webClient = WebClient.builder().clientConnector(connector).build(); // <2>
460
+ }
461
+ ----
462
+ <1> Use the `JdkClientHttpConnector` constructor with customized `HttpClient` instance.
463
+ <2> Plug the connector into the `WebClient.Builder`.
464
+
465
+ [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
466
+ .Kotlin
467
+ ----
468
+ @Bean
469
+ fun webClient() : WebClient {
470
+ val httpClient = HttpClient.newBuilder()
471
+ .executor(...)
472
+ .connectTimeout(...)
473
+ .build()
474
+ val connector = JdkClientHttpConnector(httpClient, DefaultDataBufferFactory()) // <1>
475
+
476
+ return WebClient webClient = WebClient.builder()
477
+ .clientConnector(connector).build() // <2>
478
+ }
479
+ ----
442
480
443
481
[[webflux-client-retrieve]]
444
482
== `retrieve()`
@@ -761,9 +799,9 @@ multipart request. The following example shows how to create a `MultiValueMap<St
761
799
part("fieldPart", "fieldValue")
762
800
part("filePart1", new FileSystemResource("...logo.png"))
763
801
part("jsonPart", new Person("Jason"))
764
- part("myPart", part) // Part from a server request
802
+ part("myPart", part) // Part from a server request
765
803
}
766
-
804
+
767
805
val parts = builder.build()
768
806
----
769
807
@@ -1063,7 +1101,7 @@ apply to all operations. For example:
1063
1101
client.get().uri("/person/{id}", i).retrieve()
1064
1102
.awaitBody<Person>()
1065
1103
}
1066
-
1104
+
1067
1105
val persons = runBlocking {
1068
1106
client.get().uri("/persons").retrieve()
1069
1107
.bodyToFlow<Person>()
@@ -1118,7 +1156,7 @@ inter-dependent, without ever blocking until the end.
1118
1156
With `Flux` or `Mono`, you should never have to block in a Spring MVC or Spring WebFlux controller.
1119
1157
Simply return the resulting reactive type from the controller method. The same principle apply to
1120
1158
Kotlin Coroutines and Spring WebFlux, just use suspending function or return `Flow` in your
1121
- controller method .
1159
+ controller method .
1122
1160
====
1123
1161
1124
1162
0 commit comments