This is an automated email from the ASF dual-hosted git repository.
Technoboy- pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new e2ca1dd23c8 [fix][client] Make ClientBuilder serializable (#25730)
(#25739)
e2ca1dd23c8 is described below
commit e2ca1dd23c8222f43c71b751dea16705405d16ce
Author: jiangpengcheng <[email protected]>
AuthorDate: Mon May 11 17:40:08 2026 +0800
[fix][client] Make ClientBuilder serializable (#25730) (#25739)
---
.../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 4975af3b796..d841010add8 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
@@ -138,7 +138,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();
+ }
}
}