This is an automated email from the ASF dual-hosted git repository.
Technoboy- pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new 0c53ad97f73 [fix][client] Make ClientBuilder serializable (#25730)
(#25740)
0c53ad97f73 is described below
commit 0c53ad97f738a13bb6c643e14b98e59237cbdde9
Author: jiangpengcheng <[email protected]>
AuthorDate: Mon May 11 17:44:17 2026 +0800
[fix][client] Make ClientBuilder serializable (#25730) (#25740)
---
.../impl/auth/oauth2/ClientCredentialsFlow.java | 2 +-
.../pulsar/client/impl/auth/oauth2/FlowBase.java | 23 ++++++++++++++++++----
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/ClientCredentialsFlow.java
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/ClientCredentialsFlow.java
index fe7beb47ed2..f3c85ca5cdd 100644
---
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/ClientCredentialsFlow.java
+++
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/ClientCredentialsFlow.java
@@ -136,7 +136,7 @@ class ClientCredentialsFlow extends FlowBase {
assert this.metadata != null;
URL tokenUrl = this.metadata.getTokenEndpoint();
- this.exchanger = new TokenClient(tokenUrl, httpClient);
+ this.exchanger = new TokenClient(tokenUrl, getHttpClient());
initialized = true;
}
diff --git
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/FlowBase.java
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/FlowBase.java
index 9649d179031..63248e86051 100644
---
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/FlowBase.java
+++
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/FlowBase.java
@@ -55,16 +55,22 @@ abstract class FlowBase implements Flow {
private static final long serialVersionUID = 1L;
protected final URL issuerUrl;
- protected final AsyncHttpClient httpClient;
+ private final Duration connectTimeout;
+ private final Duration readTimeout;
+ private final String trustCertsFilePath;
protected final String wellKnownMetadataPath;
protected transient Metadata metadata;
+ private transient AsyncHttpClient httpClient;
protected FlowBase(URL issuerUrl, Duration connectTimeout, Duration
readTimeout, String trustCertsFilePath,
String wellKnownMetadataPath) {
this.issuerUrl = issuerUrl;
- this.httpClient = defaultHttpClient(readTimeout, connectTimeout,
trustCertsFilePath);
+ this.connectTimeout = connectTimeout;
+ this.readTimeout = readTimeout;
+ this.trustCertsFilePath = trustCertsFilePath;
this.wellKnownMetadataPath = wellKnownMetadataPath;
+ getHttpClient();
}
private AsyncHttpClient defaultHttpClient(Duration readTimeout, Duration
connectTimeout,
@@ -91,6 +97,13 @@ abstract class FlowBase implements Flow {
return new DefaultAsyncHttpClient(confBuilder.build());
}
+ protected synchronized AsyncHttpClient getHttpClient() {
+ if (httpClient == null) {
+ httpClient = defaultHttpClient(readTimeout, connectTimeout,
trustCertsFilePath);
+ }
+ return httpClient;
+ }
+
private int getParameterDurationToMillis(String name, Duration value,
Duration defaultValue) {
Duration duration;
if (value == null) {
@@ -118,7 +131,7 @@ abstract class FlowBase implements Flow {
}
protected MetadataResolver createMetadataResolver() {
- return DefaultMetadataResolver.fromIssuerUrl(issuerUrl, httpClient,
wellKnownMetadataPath);
+ return DefaultMetadataResolver.fromIssuerUrl(issuerUrl,
getHttpClient(), wellKnownMetadataPath);
}
static String parseParameterString(Map<String, String> params, String
name) {
@@ -155,6 +168,8 @@ abstract class FlowBase implements Flow {
@Override
public void close() throws Exception {
- httpClient.close();
+ if (httpClient != null) {
+ httpClient.close();
+ }
}
}