Skip to content

Commit 222972a

Browse files
chore:use Endpoint
1 parent 8e478a5 commit 222972a

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

volcengine-java-sdk-core/src/main/java/com/volcengine/feature/rds/auth/ConnectUtils.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,8 @@ public static String buildAuthToken(ApiClient apiClient, String dbUser, String i
5858
expires = DEFAULT_EXPIRES_SECONDS;
5959
}
6060

61-
// Use StandardEndpointProvider to resolve endpoint (handles regionalization + dual-stack)
62-
StandardEndpointProvider endpointProvider = new StandardEndpointProvider();
63-
ResolveEndpointOption option = new ResolveEndpointOption();
64-
option.setService(SERVICE_NAME);
65-
option.setRegion(apiClient.getRegion());
66-
option.setUseDualStack(apiClient.getUseDualStack());
67-
ResolvedEndpoint resolved = endpointProvider.endpointFor(option);
68-
String endpoint = resolved.getEndpoint();
61+
// Resolve endpoint: prefer user-configured endpoint, fallback to StandardEndpointProvider
62+
String endpoint = getEndpoint(apiClient);
6963

7064
// SSL handling, ResolveEndpointInterceptor dose not support this
7165
String schema = apiClient.getDisableSSL() ? "http" : "https";
@@ -95,4 +89,32 @@ public static String buildAuthToken(ApiClient apiClient, String dbUser, String i
9589

9690
return reqCtx.getPresignedUrl();
9791
}
92+
93+
/**
94+
* Resolve endpoint host from ApiClient.
95+
* If the user has configured a custom endpoint (via apiClient.setEndpoint), it takes priority.
96+
* Strips schema prefix if present to return pure host.
97+
* Falls back to StandardEndpointProvider for region-based resolution when no custom endpoint is set.
98+
*
99+
* @return endpoint host without schema
100+
*/
101+
private static String getEndpoint(ApiClient apiClient) {
102+
if (StringUtils.isNotEmpty(apiClient.getEndpoint())) {
103+
String ep = apiClient.getEndpoint();
104+
if (ep.startsWith("https://")) {
105+
return ep.substring("https://".length());
106+
}
107+
if (ep.startsWith("http://")) {
108+
return ep.substring("http://".length());
109+
}
110+
return ep;
111+
}
112+
StandardEndpointProvider endpointProvider = new StandardEndpointProvider();
113+
ResolveEndpointOption option = new ResolveEndpointOption();
114+
option.setService(SERVICE_NAME);
115+
option.setRegion(apiClient.getRegion());
116+
option.setUseDualStack(apiClient.getUseDualStack());
117+
ResolvedEndpoint resolved = endpointProvider.endpointFor(option);
118+
return resolved.getEndpoint();
119+
}
98120
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public InterceptorContext intercept(InterceptorContext context) throws ApiExcept
6565
throw new RuntimeException("Region must set when ApiClient init");
6666
}
6767

68-
// Presigned branch: aligned with Go SDK's `if req.IsPresigned() { signedQuery := c1.SignUrl(...) }`
68+
// Presigned branch
6969
if (context.getRequestContext().isPresigned()) {
7070
Map<String, String> queryParamsMap = new HashMap<>();
7171
for (Pair p : queryParams) {
@@ -84,7 +84,7 @@ public InterceptorContext intercept(InterceptorContext context) throws ApiExcept
8484
return context;
8585
}
8686

87-
// Normal sign branch: aligned with Go SDK's `r := c1.Sign(req.HTTPRequest); req.HTTPRequest.Header = r.Header`
87+
// Normal sign branch
8888
final Buffer buffer = new Buffer();
8989
try {
9090
if (reqBody != null) {

0 commit comments

Comments
 (0)