Skip to content

Commit d1f3831

Browse files
author
Julien Eyraud
committed
Upgrade doc
1 parent e379f4b commit d1f3831

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

src/docs/asciidoc/web/webflux-webclient.adoc

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ support for the following:
1414
* https://github.com/reactor/reactor-netty[Reactor Netty]
1515
* https://github.com/jetty-project/jetty-reactive-httpclient[Jetty Reactive HttpClient]
1616
* 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]
1718
* Others can be plugged via `ClientHttpConnector`.
1819

1920

@@ -382,7 +383,7 @@ shows:
382383
383384
HttpClient httpClient = new HttpClient();
384385
// Further customizations...
385-
386+
386387
ClientHttpConnector connector =
387388
new JettyClientHttpConnector(httpClient, resourceFactory()); <1>
388389
@@ -403,7 +404,7 @@ shows:
403404
404405
val httpClient = HttpClient()
405406
// Further customizations...
406-
407+
407408
val connector = JettyClientHttpConnector(httpClient, resourceFactory()) // <1>
408409
409410
return WebClient.builder().clientConnector(connector).build() // <2>
@@ -439,6 +440,43 @@ The following example shows how to customize Apache HttpComponents `HttpClient`
439440
val webClient = WebClient.builder().clientConnector(connector).build()
440441
----
441442

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+
----
442480

443481
[[webflux-client-retrieve]]
444482
== `retrieve()`
@@ -761,9 +799,9 @@ multipart request. The following example shows how to create a `MultiValueMap<St
761799
part("fieldPart", "fieldValue")
762800
part("filePart1", new FileSystemResource("...logo.png"))
763801
part("jsonPart", new Person("Jason"))
764-
part("myPart", part) // Part from a server request
802+
part("myPart", part) // Part from a server request
765803
}
766-
804+
767805
val parts = builder.build()
768806
----
769807

@@ -1063,7 +1101,7 @@ apply to all operations. For example:
10631101
client.get().uri("/person/{id}", i).retrieve()
10641102
.awaitBody<Person>()
10651103
}
1066-
1104+
10671105
val persons = runBlocking {
10681106
client.get().uri("/persons").retrieve()
10691107
.bodyToFlow<Person>()
@@ -1118,7 +1156,7 @@ inter-dependent, without ever blocking until the end.
11181156
With `Flux` or `Mono`, you should never have to block in a Spring MVC or Spring WebFlux controller.
11191157
Simply return the resulting reactive type from the controller method. The same principle apply to
11201158
Kotlin Coroutines and Spring WebFlux, just use suspending function or return `Flow` in your
1121-
controller method .
1159+
controller method .
11221160
====
11231161

11241162

0 commit comments

Comments
 (0)