Skip to content

Commit 1cfedb2

Browse files
committed
Add new constructor to JettyClientHttpConnector
This commit adds a new constructor to `JettyClientHttpConnector` and deprecates another one. Jetty is not creating `HttpClient` instances using a builder API, but rather setting immutable configuration at constructor time and using setters for the rest. This commit addresses that by deprecating the constructor variant accepting a `Consumer` and just delegating to Spring's implementation for setting the client resources as needed. Closes gh-22977
1 parent 7ef8cc9 commit 1cfedb2

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,25 +57,38 @@ public JettyClientHttpConnector() {
5757
* Constructor with an {@link JettyResourceFactory} that will manage shared resources.
5858
* @param resourceFactory the {@link JettyResourceFactory} to use
5959
* @param customizer the lambda used to customize the {@link HttpClient}
60+
* @deprecated in favor of {@link JettyClientHttpConnector#JettyClientHttpConnector(HttpClient, JettyResourceFactory)}
6061
*/
62+
@Deprecated
6163
public JettyClientHttpConnector(
6264
JettyResourceFactory resourceFactory, @Nullable Consumer<HttpClient> customizer) {
63-
64-
HttpClient httpClient = new HttpClient();
65-
httpClient.setExecutor(resourceFactory.getExecutor());
66-
httpClient.setByteBufferPool(resourceFactory.getByteBufferPool());
67-
httpClient.setScheduler(resourceFactory.getScheduler());
65+
this(new HttpClient(), resourceFactory);
6866
if (customizer != null) {
69-
customizer.accept(httpClient);
67+
customizer.accept(this.httpClient);
7068
}
71-
this.httpClient = httpClient;
7269
}
7370

7471
/**
7572
* Constructor with an initialized {@link HttpClient}.
7673
*/
7774
public JettyClientHttpConnector(HttpClient httpClient) {
75+
this(httpClient, null);
76+
}
77+
78+
/**
79+
* Constructor with an initialized {@link HttpClient} and configures it
80+
* with the given {@link JettyResourceFactory}.
81+
* @param httpClient the {@link HttpClient} to use
82+
* @param resourceFactory the {@link JettyResourceFactory} to use
83+
*/
84+
public JettyClientHttpConnector(HttpClient httpClient,
85+
@Nullable JettyResourceFactory resourceFactory) {
7886
Assert.notNull(httpClient, "HttpClient is required");
87+
if (resourceFactory != null) {
88+
httpClient.setExecutor(resourceFactory.getExecutor());
89+
httpClient.setByteBufferPool(resourceFactory.getByteBufferPool());
90+
httpClient.setScheduler(resourceFactory.getScheduler());
91+
}
7992
this.httpClient = httpClient;
8093
}
8194

0 commit comments

Comments
 (0)