Skip to content

Commit

Permalink
fix:incorrect HTTP method
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiheng123 committed Apr 9, 2024
1 parent 55a81e5 commit a89c7d1
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public CompletableFuture<List<String>> showDatabases() {
String command = "SHOW DATABASES";
Query query = new Query(command);
String queryUrl = getQueryUrl(query);
return httpExcute(queryUrl, QueryResult.class, UrlConst.POST)
return httpExcute(queryUrl, QueryResult.class)
.thenApply(rsp -> rsp.getResults().get(0).getSeries().get(0).getValues().stream()
.map(x -> String.valueOf(x.get(0))).toList());
}
Expand All @@ -75,11 +75,15 @@ private <T> CompletableFuture<T> httpExcute(String url, Class<T> type) {
}

private <T> CompletableFuture<T> httpExcute(String url, Class<T> type, String method) {
return httpExcute(url, type, method, HttpRequest.BodyPublishers.noBody());
}

private <T> CompletableFuture<T> httpExcute(String url, Class<T> type, String method, HttpRequest.BodyPublisher bodyPublisher) {
CompletableFuture<HttpResponse<String>> future;
if (UrlConst.GET.equals(method)) {
future = get(url);
} else if (UrlConst.POST.equals(method)) {
future = post(url);
future = post(url, bodyPublisher);
} else {
Exception e = new RuntimeException("not support method:" + method);
return CompletableFuture.failedFuture(e);
Expand Down Expand Up @@ -109,10 +113,10 @@ public CompletableFuture<HttpResponse<String>> get(String url) {
return client.sendAsync(request, HttpResponse.BodyHandlers.ofString());
}

public CompletableFuture<HttpResponse<String>> post(String url) {
public CompletableFuture<HttpResponse<String>> post(String url, HttpRequest.BodyPublisher bodyPublisher) {
HttpRequest request = HttpRequest.newBuilder()
.uri(buildUri(url))
.POST(HttpRequest.BodyPublishers.noBody())
.POST(bodyPublisher)
.timeout(this.conf.getTimeout())
.build();
return client.sendAsync(request, HttpResponse.BodyHandlers.ofString());
Expand Down

0 comments on commit a89c7d1

Please sign in to comment.