Skip to content

Commit 11d7b42

Browse files
committed
fix(core): add custom boot strap region in api client
1 parent 2c153ff commit 11d7b42

2 files changed

Lines changed: 36 additions & 16 deletions

File tree

volcengine-java-sdk-core/src/main/java/com/volcengine/ApiClient.java

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,13 @@ public class ApiClient {
101101

102102
private Integer keepAliveDurationMs = 5 * 60 * 1000;
103103

104+
private Set<String> customBootstrapRegion;
104105

105106
/*
106107
* Constructor for ApiClient
107108
*/
108109
public ApiClient() {
109-
ConnectionPool connectionPool=new ConnectionPool(maxIdleConns,keepAliveDurationMs);
110+
ConnectionPool connectionPool = new ConnectionPool(maxIdleConns, keepAliveDurationMs);
110111
httpClient = new OkHttpClient();
111112
httpClient.setConnectionPool(connectionPool);
112113

@@ -147,6 +148,17 @@ private static String getUserAgent() {
147148
return String.format(format, Version.SDK_NAME, Version.SDK_VERSION, jdkInfo, osInfo, arch);
148149
}
149150

151+
/**
152+
* Set the User-Agent header's value (by adding to the default header map).
153+
*
154+
* @param userAgent HTTP request's user agent
155+
* @return ApiClient
156+
*/
157+
public ApiClient setUserAgent(String userAgent) {
158+
addDefaultHeader("User-Agent", userAgent);
159+
return this;
160+
}
161+
150162
/**
151163
* Get base path
152164
*
@@ -237,7 +249,6 @@ public ApiClient setCredentials(Credentials credentials) {
237249
return this;
238250
}
239251

240-
241252
/**
242253
* Get HTTP client
243254
*
@@ -388,18 +399,6 @@ public Authentication getAuthentication(String authName) {
388399
return authentications.get(authName);
389400
}
390401

391-
392-
/**
393-
* Set the User-Agent header's value (by adding to the default header map).
394-
*
395-
* @param userAgent HTTP request's user agent
396-
* @return ApiClient
397-
*/
398-
public ApiClient setUserAgent(String userAgent) {
399-
addDefaultHeader("User-Agent", userAgent);
400-
return this;
401-
}
402-
403402
/**
404403
* Add a default header.
405404
*
@@ -530,6 +529,26 @@ public ApiClient setWriteTimeout(int writeTimeout) {
530529
return this;
531530
}
532531

532+
/**
533+
* Get the custom bootstrapping regions.
534+
*
535+
* @return Set of custom bootstrapping regions
536+
*/
537+
public Set<String> getCustomBootstrapRegion() {
538+
return this.customBootstrapRegion;
539+
}
540+
541+
/**
542+
* Set the custom bootstrapping regions.
543+
*
544+
* @param customBootstrapRegion Set of custom bootstrapping regions
545+
* @return Api client
546+
*/
547+
public ApiClient setCustomBootstrapRegion(Set<String> customBootstrapRegion) {
548+
this.customBootstrapRegion = customBootstrapRegion;
549+
return this;
550+
}
551+
533552
/**
534553
* Format the given parameter object into string.
535554
*
@@ -1656,7 +1675,7 @@ public Integer getMaxIdleConns() {
16561675

16571676
public ApiClient setMaxIdleConns(Integer maxIdleConns) {
16581677
this.maxIdleConns = maxIdleConns;
1659-
this.httpClient.setConnectionPool(new ConnectionPool(maxIdleConns,keepAliveDurationMs));
1678+
this.httpClient.setConnectionPool(new ConnectionPool(maxIdleConns, keepAliveDurationMs));
16601679
return this;
16611680
}
16621681

@@ -1666,7 +1685,7 @@ public Integer getKeepAliveDurationMs() {
16661685

16671686
public ApiClient setKeepAliveDurationMs(Integer keepAliveDurationMs) {
16681687
this.keepAliveDurationMs = keepAliveDurationMs;
1669-
this.httpClient.setConnectionPool(new ConnectionPool(maxIdleConns,keepAliveDurationMs));
1688+
this.httpClient.setConnectionPool(new ConnectionPool(maxIdleConns, keepAliveDurationMs));
16701689
return this;
16711690
}
16721691
}

volcengine-java-sdk-core/src/main/java/com/volcengine/interceptor/ResolveEndpointInterceptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public InterceptorContext intercept(InterceptorContext context) throws ApiExcept
4141
ResolveEndpointOption option = new ResolveEndpointOption();
4242
option.setService(service);
4343
option.setRegion(context.getApiClient().getRegion());
44+
option.setCustomBootstrapRegion(context.getApiClient().getCustomBootstrapRegion());
4445
ResolvedEndpoint resolvedEndpoint = endpointResolver.endpointFor(option);
4546
context.getRequestContext().setHost(resolvedEndpoint.getEndpoint());
4647
}

0 commit comments

Comments
 (0)