diff --git a/pom.xml b/pom.xml
index 01ba12d..7fa85b4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,6 +49,7 @@
1.7.0
4.8.6.2
2.43.0
+ 0.3.0
@@ -97,6 +98,11 @@
${embedded-pulsar.version}
test
+
+ io.github.openfacade
+ http-facade
+ ${http-facade.version}
+
diff --git a/pulsar-admin-common/src/main/java/io/github/protocol/pulsar/admin/common/JacksonService.java b/pulsar-admin-common/src/main/java/io/github/protocol/pulsar/admin/common/JacksonService.java
index d6830aa..9bd4bd1 100644
--- a/pulsar-admin-common/src/main/java/io/github/protocol/pulsar/admin/common/JacksonService.java
+++ b/pulsar-admin-common/src/main/java/io/github/protocol/pulsar/admin/common/JacksonService.java
@@ -8,6 +8,7 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.IOException;
import java.util.List;
public class JacksonService {
@@ -19,25 +20,29 @@ public class JacksonService {
}
public static String toJson(Object o) throws JsonProcessingException {
- return MAPPER.writeValueAsString(o);
+ return o == null ? null : MAPPER.writeValueAsString(o);
}
- public static T toObject(String json, Class type) throws JsonProcessingException {
- if (json == null || json.isEmpty()) {
+ public static byte[] toBytes(Object o) throws JsonProcessingException {
+ return o == null ? null : MAPPER.writeValueAsBytes(o);
+ }
+
+ public static T toObject(byte[] json, Class type) throws IOException {
+ if (json == null || json.length == 0) {
return null;
}
return MAPPER.readValue(json, type);
}
- public static T toRefer(String json, TypeReference ref) throws JsonProcessingException {
- if (json == null || json.isEmpty()) {
+ public static T toRefer(byte[] json, TypeReference ref) throws IOException {
+ if (json == null || json.length == 0) {
return null;
}
return MAPPER.readValue(json, ref);
}
- public static List toList(String json, TypeReference> typeRef) throws JsonProcessingException {
- if (json == null || json.isEmpty()) {
+ public static List toList(byte[] json, TypeReference> typeRef) throws IOException {
+ if (json == null || json.length == 0) {
return List.of();
}
return MAPPER.readValue(json, typeRef);
diff --git a/pulsar-admin-jdk/src/main/java/io/github/protocol/pulsar/admin/jdk/BaseTopicsImpl.java b/pulsar-admin-jdk/src/main/java/io/github/protocol/pulsar/admin/jdk/BaseTopicsImpl.java
index f32da0c..534d1e8 100644
--- a/pulsar-admin-jdk/src/main/java/io/github/protocol/pulsar/admin/jdk/BaseTopicsImpl.java
+++ b/pulsar-admin-jdk/src/main/java/io/github/protocol/pulsar/admin/jdk/BaseTopicsImpl.java
@@ -1,13 +1,14 @@
package io.github.protocol.pulsar.admin.jdk;
import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.openfacade.http.HttpResponse;
import io.github.protocol.pulsar.admin.common.JacksonService;
import java.io.IOException;
-import java.net.http.HttpResponse;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
public abstract class BaseTopicsImpl {
@@ -23,14 +24,14 @@ public void createPartitionedTopic(String tenant, String namespace, String encod
boolean createLocalTopicOnly) throws PulsarAdminException {
String url = String.format("%s/%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace, encodedTopic, "/partitions");
try {
- HttpResponse response = httpClient.put(url, numPartitions, "createLocalTopicOnly",
+ HttpResponse response = httpClient.put(url, numPartitions, "createLocalTopicOnly",
String.valueOf(createLocalTopicOnly));
if (response.statusCode() != 204) {
throw new PulsarAdminException(
String.format("failed to create partitioned topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
@@ -39,14 +40,14 @@ public void deletePartitionedTopic(String tenant, String namespace, String encod
boolean authoritative) throws PulsarAdminException {
String url = String.format("%s/%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace, encodedTopic, "/partitions");
try {
- HttpResponse response = httpClient.delete(url, "force", String.valueOf(force),
+ HttpResponse response = httpClient.delete(url, "force", String.valueOf(force),
"authoritative", String.valueOf(authoritative));
if (response.statusCode() != 204) {
throw new PulsarAdminException(
String.format("failed to delete partitioned topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
@@ -56,16 +57,16 @@ public void updatePartitionedTopic(String tenant, String namespace, String encod
boolean force, int numPartitions) throws PulsarAdminException {
String url = String.format("%s/%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace, encodedTopic, "/partitions");
try {
- HttpResponse response = httpClient.post(url, numPartitions, "updateLocalTopicOnly",
+ HttpResponse response = httpClient.post(url, numPartitions, "updateLocalTopicOnly",
String.valueOf(updateLocalTopicOnly),
"authoritative", String.valueOf(authoritative),
"force", String.valueOf(force));
if (response.statusCode() != 204) {
throw new PulsarAdminException(
String.format("failed to update partitioned topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
@@ -76,7 +77,7 @@ public PartitionedTopicStats getPartitionedStats(String tenant, String namespace
String url = String.format("%s/%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace,
encodedTopic, "/partitioned-stats");
try {
- HttpResponse response = httpClient.get(url, "perPartition",
+ HttpResponse response = httpClient.get(url, "perPartition",
Arrays.toString(new Object[] {perPartition}), "getPreciseBacklog",
Arrays.toString(new Object[] {false}), "subscriptionBacklogSize",
Arrays.toString(new Object[] {false}),
@@ -84,10 +85,10 @@ public PartitionedTopicStats getPartitionedStats(String tenant, String namespace
if (response.statusCode() != 200) {
throw new PulsarAdminException(
String.format("failed to get partitioned stats of topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
return JacksonService.toObject(response.body(), PartitionedTopicStats.class);
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
@@ -97,16 +98,16 @@ public PartitionedTopicMetadata getPartitionedMetadata(String tenant, String nam
throws PulsarAdminException {
String url = String.format("%s/%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace, encodedTopic, "/partitions");
try {
- HttpResponse response = httpClient.get(url,
+ HttpResponse response = httpClient.get(url,
"checkAllowAutoCreation", String.valueOf(checkAllowAutoCreation),
"authoritative", String.valueOf(authoritative));
if (response.statusCode() != 200) {
throw new PulsarAdminException(
String.format("failed to update partitioned topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
return JacksonService.toObject(response.body(), PartitionedTopicMetadata.class);
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
@@ -115,14 +116,14 @@ public void createNonPartitionedTopic(String tenant, String namespace, String en
Map properties) throws PulsarAdminException {
String url = String.format("%s/%s/%s/%s", getDomainBaseUrl(), tenant, namespace, encodedTopic);
try {
- HttpResponse response = httpClient.put(url, properties,
+ HttpResponse response = httpClient.put(url, properties,
"authoritative", String.valueOf(authoritative));
if (response.statusCode() != 204) {
throw new PulsarAdminException(
String.format("failed to create non-partitioned topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
@@ -131,24 +132,24 @@ public void deleteTopic(String tenant, String namespace, String encodedTopic, bo
throws PulsarAdminException {
String url = String.format("%s/%s/%s/%s", getDomainBaseUrl(), tenant, namespace, encodedTopic);
try {
- HttpResponse response = httpClient.delete(url,
+ HttpResponse response = httpClient.delete(url,
"force", String.valueOf(force),
"authoritative", String.valueOf(authoritative));
if (response.statusCode() != 204) {
throw new PulsarAdminException(
String.format("failed to delete non-partitioned topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
- public List getList(String tenant, String namespace, String bundle, boolean includeSystemTopic)
+ public List getList(String tenant, String namespace, String bundle, boolean includeSystemTopic)
throws PulsarAdminException {
String url = String.format("%s/%s/%s", getDomainBaseUrl(), tenant, namespace);
try {
- HttpResponse response;
+ HttpResponse response;
if (bundle != null) {
response = httpClient.get(url,
"bundle", bundle,
@@ -161,30 +162,30 @@ public List getList(String tenant, String namespace, String bundle, bool
throw new PulsarAdminException(
String.format("failed to get list of non-partitioned-topics "
+ "under namespace %s/%s, status code %s, body : %s",
- tenant, namespace, response.statusCode(), response.body()));
+ tenant, namespace, response.statusCode(), response.bodyAsString()));
}
- return JacksonService.toRefer(response.body(), new TypeReference>() {
+ return JacksonService.toRefer(response.body(), new TypeReference<>() {
});
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
- public List getPartitionedTopicList(String tenant, String namespace, boolean includeSystemTopic)
+ public List getPartitionedTopicList(String tenant, String namespace, boolean includeSystemTopic)
throws PulsarAdminException {
String url = String.format("%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace, UrlConst.PARTITIONED);
try {
- HttpResponse response = httpClient.get(url, "includeSystemTopic",
+ HttpResponse response = httpClient.get(url, "includeSystemTopic",
String.valueOf(includeSystemTopic));
if (response.statusCode() != 200) {
throw new PulsarAdminException(
String.format("failed to get list of partitioned-topics under namespace %s/%s, "
+ "status code %s, body : %s",
- tenant, namespace, response.statusCode(), response.body()));
+ tenant, namespace, response.statusCode(), response.bodyAsString()));
}
- return JacksonService.toRefer(response.body(), new TypeReference>() {
+ return JacksonService.toRefer(response.body(), new TypeReference<>() {
});
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
@@ -194,14 +195,14 @@ public void createMissedPartitions(String tenant, String namespace, String encod
String url = String.format("%s/%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace, encodedTopic,
UrlConst.CREATE_MISSED_PARTITIONS);
try {
- HttpResponse response = httpClient.post(url);
+ HttpResponse response = httpClient.post(url);
if (response.statusCode() != 204) {
throw new PulsarAdminException(
String.format("failed to create missing partitions for topic %s/%s/%s, "
+ "status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
@@ -211,14 +212,14 @@ public MessageIdImpl getLastMessageId(String tenant, String namespace, String en
String url = String.format("%s/%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace, encodedTopic,
UrlConst.LAST_MESSAGE_ID);
try {
- HttpResponse response = httpClient.get(url, "authoritative", String.valueOf(authoritative));
+ HttpResponse response = httpClient.get(url, "authoritative", String.valueOf(authoritative));
if (response.statusCode() != 200) {
throw new PulsarAdminException(
String.format("failed to get last message id of topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
return JacksonService.toObject(response.body(), MessageIdImpl.class);
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
@@ -228,17 +229,17 @@ public RetentionPolicies getRetention(String tenant, String namespace, String en
String url = String.format("%s/%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace, encodedTopic,
UrlConst.RETENTION);
try {
- HttpResponse response = httpClient.get(url,
+ HttpResponse response = httpClient.get(url,
"isGlobal", String.valueOf(isGlobal),
"applied", String.valueOf(applied),
"authoritative", String.valueOf(authoritative));
if (response.statusCode() != 200) {
throw new PulsarAdminException(
String.format("failed to get retention of topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
return JacksonService.toObject(response.body(), RetentionPolicies.class);
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
@@ -248,15 +249,15 @@ public void setRetention(String tenant, String namespace, String encodedTopic, b
String url = String.format("%s/%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace, encodedTopic,
UrlConst.RETENTION);
try {
- HttpResponse response = httpClient.post(url, retention,
+ HttpResponse response = httpClient.post(url, retention,
"authoritative", String.valueOf(authoritative),
"isGlobal", String.valueOf(isGlobal));
if (response.statusCode() != 204) {
throw new PulsarAdminException(
String.format("failed to set retention for topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
@@ -266,13 +267,13 @@ public void removeRetention(String tenant, String namespace, String encodedTopic
String url = String.format("%s/%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace, encodedTopic,
UrlConst.RETENTION);
try {
- HttpResponse response = httpClient.delete(url, "authoritative", String.valueOf(authoritative));
+ HttpResponse response = httpClient.delete(url, "authoritative", String.valueOf(authoritative));
if (response.statusCode() != 204) {
throw new PulsarAdminException(
String.format("failed to delete retention of topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
- } catch (IOException | InterruptedException e) {
+ } catch (IOException | InterruptedException | ExecutionException e) {
throw new PulsarAdminException(e);
}
}
@@ -284,18 +285,18 @@ public Map getBacklogQuotaMap(String tenant, Str
String url = String.format("%s/%s/%s/%s%s", getDomainBaseUrl(), tenant, namespace, encodedTopic,
UrlConst.BACKLOG_QUOTA_MAP);
try {
- HttpResponse response = httpClient.get(url,
+ HttpResponse response = httpClient.get(url,
"applied", String.valueOf(applied),
"authoritative", String.valueOf(authoritative),
"isGlobal", String.valueOf(isGlobal));
if (response.statusCode() != 200) {
throw new PulsarAdminException(
String.format("failed to get backlog quota map of topic %s/%s/%s, status code %s, body : %s",
- tenant, namespace, encodedTopic, response.statusCode(), response.body()));
+ tenant, namespace, encodedTopic, response.statusCode(), response.bodyAsString()));
}
return JacksonService.toRefer(response.body(), new TypeReference