Skip to content

Commit 7d7ab18

Browse files
committed
refactor: support jdk8
Signed-off-by: moxiaoying <1159230165@qq.com>
1 parent c9fb5ae commit 7d7ab18

File tree

17 files changed

+100
-82
lines changed

17 files changed

+100
-82
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
![License](https://img.shields.io/badge/license-Apache2.0-green) ![Language](https://img.shields.io/badge/language-Java-blue.svg) [![version](https://img.shields.io/github/v/tag/protocol-laboratory/pulsar-admin-java?label=release&color=blue)](https://github.com/protocol-laboratory/pulsar-admin-java/releases) [![codecov](https://codecov.io/gh/protocol-laboratory/pulsar-admin-java/branch/main/graph/badge.svg)](https://codecov.io/gh/protocol-laboratory/pulsar-admin-java)
44

5-
This is a simple alternative to pulsar-admin built using the built-in HTTP client of the JDK. It minimizes project dependencies and requires a minimum of JDK 17.
5+
This is a simple alternative to pulsar-admin built using the built-in HTTP client of the JDK. It minimizes project dependencies and requires a minimum of JDK 8.
66

77
Features:
88
- Basic functionality for managing Pulsar clusters
99
- Built on top of the built-in HTTP client of the JDK
1010
- Minimizes project dependencies to provide a lightweight solution
11-
- Requires a minimum of JDK 17
11+
- Requires a minimum of JDK 8
1212

1313
Notices:
1414
- currently disable hostname verification is not available. if you want to disable it ,please set property like : **System.setProperty("jdk.internal.httpclient.disableHostnameVerification", "true")**, but it's better to provide valid certificates.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</modules>
1919

2020
<properties>
21-
<maven.compiler.source>17</maven.compiler.source>
22-
<maven.compiler.target>17</maven.compiler.target>
21+
<maven.compiler.source>8</maven.compiler.source>
22+
<maven.compiler.target>8</maven.compiler.target>
2323
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2424
<src.dir>src/main/java</src.dir>
2525
<!-- dependency -->

pulsar-admin-common/src/main/java/io/github/protocol/pulsar/admin/common/JacksonService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.jetbrains.annotations.Nullable;
1212

1313
import java.io.IOException;
14+
import java.util.ArrayList;
1415
import java.util.List;
1516

1617
public class JacksonService {
@@ -41,7 +42,7 @@ public static <T> T toRefer(byte[] json, TypeReference<T> ref) throws IOExceptio
4142

4243
public static <T> List<T> toList(byte[] json, TypeReference<List<T>> typeRef) throws IOException {
4344
if (json == null || json.length == 0) {
44-
return List.of();
45+
return new ArrayList<>();
4546
}
4647
return MAPPER.readValue(json, typeRef);
4748
}

pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/BaseTopicsImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public List getList(String tenant, String namespace, String bundle, boolean incl
164164
+ "under namespace %s/%s, status code %s, body : %s",
165165
tenant, namespace, response.statusCode(), response.bodyAsString()));
166166
}
167-
return JacksonService.toRefer(response.body(), new TypeReference<>() {
167+
return JacksonService.toRefer(response.body(), new TypeReference<List<String>>() {
168168
});
169169
} catch (IOException | InterruptedException | ExecutionException e) {
170170
throw new PulsarAdminException(e);
@@ -183,7 +183,7 @@ public List getPartitionedTopicList(String tenant, String namespace, boolean inc
183183
+ "status code %s, body : %s",
184184
tenant, namespace, response.statusCode(), response.bodyAsString()));
185185
}
186-
return JacksonService.toRefer(response.body(), new TypeReference<>() {
186+
return JacksonService.toRefer(response.body(), new TypeReference<List<String>>() {
187187
});
188188
} catch (IOException | InterruptedException | ExecutionException e) {
189189
throw new PulsarAdminException(e);

pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Brokers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void healthcheck(TopicVersion topicVersion) throws PulsarAdminException {
2121
httpResponse.statusCode());
2222
}
2323
if (!httpResponse.bodyAsString().equals("ok")) {
24-
throw new PulsarAdminException("healthcheck failed, body: " + httpResponse.body());
24+
throw new PulsarAdminException("healthcheck failed, body: " + httpResponse.bodyAsString());
2525
}
2626
} catch (Exception e) {
2727
throw new PulsarAdminException(e);

pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Clusters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public List<String> getClusters() throws PulsarAdminException {
2424
String.format("failed to get list of clusters, "
2525
+ "status code %s, body : %s", response.statusCode(), response.body()));
2626
}
27-
return JacksonService.toRefer(response.body(), new TypeReference<>() {});
27+
return JacksonService.toRefer(response.body(), new TypeReference<List<String>>() {});
2828
} catch (IOException | InterruptedException | ExecutionException e) {
2929
throw new PulsarAdminException(e);
3030
}

pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/InnerHttpClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.io.IOException;
1818
import java.util.ArrayList;
19+
import java.util.Arrays;
1920
import java.util.HashMap;
2021
import java.util.List;
2122
import java.util.Map;
@@ -61,7 +62,7 @@ public HttpResponse post(String url, Object body, String... params)
6162
private HttpResponse innerPost(String url, byte[] body, String... params)
6263
throws InterruptedException, ExecutionException {
6364
Map<String, List<String>> headers = new HashMap<>();
64-
headers.put("Content-Type", List.of("application/json"));
65+
headers.put("Content-Type", Arrays.asList("application/json"));
6566
HttpRequest request = new HttpRequest(concatUrlWithParams(url, params), HttpMethod.POST, headers, body);
6667
return client.send(request).get();
6768
}
@@ -82,7 +83,7 @@ public HttpResponse put(String url, Object body, String... params)
8283
private HttpResponse innerPut(String url, byte[] body, String... params)
8384
throws InterruptedException, ExecutionException {
8485
Map<String, List<String>> headers = new HashMap<>();
85-
headers.put("Content-Type", List.of("application/json"));
86+
headers.put("Content-Type", Arrays.asList("application/json"));
8687
HttpRequest request = new HttpRequest(concatUrlWithParams(url, params), HttpMethod.PUT, headers, body);
8788
return client.send(request).get();
8889
}

pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Namespaces.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public List<String> getTenantNamespaces(String tenant) throws PulsarAdminExcepti
2525
String.format("failed to get namespaces of tenant %s, status code %s, body : %s",
2626
tenant, response.statusCode(), response.bodyAsString()));
2727
}
28-
return JacksonService.toList(response.body(), new TypeReference<>() {
28+
return JacksonService.toList(response.body(), new TypeReference<List<String>>() {
2929
});
3030
} catch (IOException | InterruptedException | ExecutionException e) {
3131
throw new PulsarAdminException(e);
@@ -43,7 +43,7 @@ public List<String> getTopics(String tenant, String namespace, Mode mode, boolea
4343
String.format("failed to get topics of namespace %s/%s, status code %s, body : %s",
4444
tenant, namespace, response.statusCode(), response.bodyAsString()));
4545
}
46-
return JacksonService.toList(response.body(), new TypeReference<>() {
46+
return JacksonService.toList(response.body(), new TypeReference<List<String>>() {
4747
});
4848
} catch (IOException | InterruptedException | ExecutionException e) {
4949
throw new PulsarAdminException(e);
@@ -90,7 +90,7 @@ public Map<BacklogQuotaType, BacklogQuota> getBacklogQuotaMap(String tenant, Str
9090
"failed to get backlog quota map of namespace %s/%s, status code %s, body : %s",
9191
tenant, namespace, response.statusCode(), response.bodyAsString()));
9292
}
93-
return JacksonService.toRefer(response.body(), new TypeReference<>() {
93+
return JacksonService.toRefer(response.body(), new TypeReference<Map<BacklogQuotaType, BacklogQuota>>() {
9494
});
9595
} catch (IOException | InterruptedException | ExecutionException e) {
9696
throw new PulsarAdminException(e);

pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Tenants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public List<String> getTenants() throws PulsarAdminException {
7676
throw new PulsarAdminException(String.format("failed to get list of tenant, status code %s, body : %s",
7777
response.statusCode(), response.bodyAsString()));
7878
}
79-
return JacksonService.toList(response.body(), new TypeReference<>() {});
79+
return JacksonService.toList(response.body(), new TypeReference<List<String>>() {});
8080
} catch (IOException | InterruptedException | ExecutionException e) {
8181
throw new PulsarAdminException(e);
8282
}

pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/ClustersTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.junit.jupiter.api.BeforeAll;
77
import org.junit.jupiter.api.Test;
88

9-
import java.util.List;
9+
import java.util.Arrays;
1010

1111
public class ClustersTest {
1212

@@ -24,7 +24,7 @@ public static void teardown() throws Exception {
2424

2525
@Test
2626
public void getClustersTest() throws PulsarAdminException {
27-
Assertions.assertEquals(List.of("standalone"),
27+
Assertions.assertEquals(Arrays.asList("standalone"),
2828
PulsarAdmin.builder().port(SERVER.getWebPort()).build().clusters().getClusters());
2929
}
3030

0 commit comments

Comments
 (0)