This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 91f8e7d3f1 [core] rest catalog options uri schema should start with
http (#5695)
91f8e7d3f1 is described below
commit 91f8e7d3f17a9df5f2426f88f80a3d683a7886fb
Author: jerry <[email protected]>
AuthorDate: Thu Jun 5 17:46:05 2025 +0800
[core] rest catalog options uri schema should start with http (#5695)
---
.../java/org/apache/paimon/rest/HttpClient.java | 33 +++++++++++++++-------
.../org/apache/paimon/rest/HttpClientTest.java | 15 +++++++---
2 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/paimon-api/src/main/java/org/apache/paimon/rest/HttpClient.java
b/paimon-api/src/main/java/org/apache/paimon/rest/HttpClient.java
index f3b6c6a685..8aba11d52c 100644
--- a/paimon-api/src/main/java/org/apache/paimon/rest/HttpClient.java
+++ b/paimon-api/src/main/java/org/apache/paimon/rest/HttpClient.java
@@ -68,11 +68,20 @@ public class HttpClient implements RESTClient {
private ErrorHandler errorHandler;
public HttpClient(String uri) {
- if (uri != null && uri.endsWith("/")) {
- this.uri = uri.substring(0, uri.length() - 1);
+ String serverUri;
+ if (StringUtils.isNotEmpty(uri)) {
+ if (uri.endsWith("/")) {
+ serverUri = uri.substring(0, uri.length() - 1);
+ } else {
+ serverUri = uri;
+ }
+ if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
+ serverUri = String.format("http://%s", serverUri);
+ }
} else {
- this.uri = uri;
+ throw new IllegalArgumentException("uri is empty which must be
defined.");
}
+ this.uri = serverUri;
this.errorHandler = DefaultErrorHandler.getInstance();
}
@@ -87,7 +96,7 @@ public class HttpClient implements RESTClient {
Map<String, String> authHeaders = getHeaders(path, "GET", "",
restAuthFunction);
Request request =
new Request.Builder()
- .url(getRequestUrl(uri, path, null))
+ .url(getRequestUrl(path, null))
.get()
.headers(Headers.of(authHeaders))
.build();
@@ -104,7 +113,7 @@ public class HttpClient implements RESTClient {
getHeaders(path, queryParams, "GET", "", restAuthFunction);
Request request =
new Request.Builder()
- .url(getRequestUrl(uri, path, queryParams))
+ .url(getRequestUrl(path, queryParams))
.get()
.headers(Headers.of(authHeaders))
.build();
@@ -129,7 +138,7 @@ public class HttpClient implements RESTClient {
RequestBody requestBody = buildRequestBody(bodyStr);
Request request =
new Request.Builder()
- .url(getRequestUrl(uri, path, null))
+ .url(getRequestUrl(path, null))
.post(requestBody)
.headers(Headers.of(authHeaders))
.build();
@@ -144,7 +153,7 @@ public class HttpClient implements RESTClient {
Map<String, String> authHeaders = getHeaders(path, "DELETE", "",
restAuthFunction);
Request request =
new Request.Builder()
- .url(getRequestUrl(uri, path, null))
+ .url(getRequestUrl(path, null))
.delete()
.headers(Headers.of(authHeaders))
.build();
@@ -160,7 +169,7 @@ public class HttpClient implements RESTClient {
RequestBody requestBody = buildRequestBody(bodyStr);
Request request =
new Request.Builder()
- .url(getRequestUrl(uri, path, null))
+ .url(getRequestUrl(path, null))
.delete(requestBody)
.headers(Headers.of(authHeaders))
.build();
@@ -171,8 +180,7 @@ public class HttpClient implements RESTClient {
}
@VisibleForTesting
- protected static String getRequestUrl(
- String uri, String path, Map<String, String> queryParams) {
+ protected String getRequestUrl(String path, Map<String, String>
queryParams) {
String fullPath = StringUtils.isNullOrWhitespaceOnly(path) ? uri : uri
+ path;
if (queryParams != null && !queryParams.isEmpty()) {
HttpUrl httpUrl = HttpUrl.parse(fullPath);
@@ -183,6 +191,11 @@ public class HttpClient implements RESTClient {
return fullPath;
}
+ @VisibleForTesting
+ public String uri() {
+ return uri;
+ }
+
private <T extends RESTResponse> T exec(Request request, Class<T>
responseType) {
try (Response response = HTTP_CLIENT.newCall(request).execute()) {
String responseBodyStr = response.body() != null ?
response.body().string() : null;
diff --git
a/paimon-core/src/test/java/org/apache/paimon/rest/HttpClientTest.java
b/paimon-core/src/test/java/org/apache/paimon/rest/HttpClientTest.java
index c80ae3fde0..370da8b63f 100644
--- a/paimon-core/src/test/java/org/apache/paimon/rest/HttpClientTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/rest/HttpClientTest.java
@@ -81,6 +81,13 @@ public class HttpClientTest {
server.stop();
}
+ @Test
+ public void testServerUriSchema() {
+ assertEquals("http://localhost", (new HttpClient("localhost")).uri());
+ assertEquals("http://localhost", (new
HttpClient("http://localhost")).uri());
+ assertEquals("https://localhost", (new
HttpClient("https://localhost")).uri());
+ }
+
@Test
public void testGetSuccess() {
server.enqueueResponse(mockResponseDataStr, 200);
@@ -189,10 +196,10 @@ public class HttpClientTest {
"GET",
"");
String url =
- HttpClient.getRequestUrl(
- "http://a.b.c:8080",
- "/api/v1/tables/my_table$schemas",
- ImmutableMap.of("pageToken", "dt=20230101"));
+ (new HttpClient("http://a.b.c:8080"))
+ .getRequestUrl(
+ "/api/v1/tables/my_table$schemas",
+ ImmutableMap.of("pageToken", "dt=20230101"));
assertEquals(
"http://a.b.c:8080/api/v1/tables/my_table$schemas?pageToken=dt%3D20230101",
url);
Map<String, String> queryParameters = getParameters(url);