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
This commit is contained in:
parent
7ef8cc9faf
commit
1cfedb20b8
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -57,25 +57,38 @@ public class JettyClientHttpConnector implements ClientHttpConnector {
|
||||||
* Constructor with an {@link JettyResourceFactory} that will manage shared resources.
|
* Constructor with an {@link JettyResourceFactory} that will manage shared resources.
|
||||||
* @param resourceFactory the {@link JettyResourceFactory} to use
|
* @param resourceFactory the {@link JettyResourceFactory} to use
|
||||||
* @param customizer the lambda used to customize the {@link HttpClient}
|
* @param customizer the lambda used to customize the {@link HttpClient}
|
||||||
|
* @deprecated in favor of {@link JettyClientHttpConnector#JettyClientHttpConnector(HttpClient, JettyResourceFactory)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public JettyClientHttpConnector(
|
public JettyClientHttpConnector(
|
||||||
JettyResourceFactory resourceFactory, @Nullable Consumer<HttpClient> customizer) {
|
JettyResourceFactory resourceFactory, @Nullable Consumer<HttpClient> customizer) {
|
||||||
|
this(new HttpClient(), resourceFactory);
|
||||||
HttpClient httpClient = new HttpClient();
|
|
||||||
httpClient.setExecutor(resourceFactory.getExecutor());
|
|
||||||
httpClient.setByteBufferPool(resourceFactory.getByteBufferPool());
|
|
||||||
httpClient.setScheduler(resourceFactory.getScheduler());
|
|
||||||
if (customizer != null) {
|
if (customizer != null) {
|
||||||
customizer.accept(httpClient);
|
customizer.accept(this.httpClient);
|
||||||
}
|
}
|
||||||
this.httpClient = httpClient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with an initialized {@link HttpClient}.
|
* Constructor with an initialized {@link HttpClient}.
|
||||||
*/
|
*/
|
||||||
public JettyClientHttpConnector(HttpClient httpClient) {
|
public JettyClientHttpConnector(HttpClient httpClient) {
|
||||||
|
this(httpClient, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor with an initialized {@link HttpClient} and configures it
|
||||||
|
* with the given {@link JettyResourceFactory}.
|
||||||
|
* @param httpClient the {@link HttpClient} to use
|
||||||
|
* @param resourceFactory the {@link JettyResourceFactory} to use
|
||||||
|
*/
|
||||||
|
public JettyClientHttpConnector(HttpClient httpClient,
|
||||||
|
@Nullable JettyResourceFactory resourceFactory) {
|
||||||
Assert.notNull(httpClient, "HttpClient is required");
|
Assert.notNull(httpClient, "HttpClient is required");
|
||||||
|
if (resourceFactory != null) {
|
||||||
|
httpClient.setExecutor(resourceFactory.getExecutor());
|
||||||
|
httpClient.setByteBufferPool(resourceFactory.getByteBufferPool());
|
||||||
|
httpClient.setScheduler(resourceFactory.getScheduler());
|
||||||
|
}
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue