Skip to content

Commit b2c9045

Browse files
feat: get server version
1 parent b1edd68 commit b2c9045

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/main/java/com/influxdb/v3/client/InfluxDBClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,10 @@ Stream<VectorSchemaRoot> queryBatches(@Nonnull final String query,
452452
/**
453453
* Get InfluxDB server version.
454454
*
455-
* @return a string representing the server version. Can be null.
455+
* @return a string representing the server version.
456+
* Returns <code>null</code> if the server version can't be determined.
456457
*/
458+
@Nullable
457459
String getServerVersion();
458460

459461
/**

src/main/java/com/influxdb/v3/client/internal/RestClient.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,11 @@ public void checkServerTrusted(
141141
this.client = builder.build();
142142
}
143143

144-
@Nonnull
145144
public String getServerVersion() throws InfluxDBApiException {
146-
HttpRequest request = HttpRequest.newBuilder()
147-
.uri(URI.create(this.baseUrl + "ping"))
148-
.GET()
149-
.build();
150-
151145
HttpResponse<String> response;
152146
String influxdbVersion;
153147
try {
154-
response = client.send(request, HttpResponse.BodyHandlers.ofString());
148+
response = request("ping", HttpMethod.GET, null, null, null);
155149
influxdbVersion = extractServerVersion(response);
156150
} catch (Exception e) {
157151
throw new InfluxDBApiException(e);
@@ -169,7 +163,7 @@ private String extractServerVersion(final HttpResponse<String> response) throws
169163
return version;
170164
}
171165

172-
void request(@Nonnull final String path,
166+
HttpResponse<String> request(@Nonnull final String path,
173167
@Nonnull final HttpMethod method,
174168
@Nullable final byte[] data,
175169
@Nullable final Map<String, String> queryParams,
@@ -264,6 +258,8 @@ void request(@Nonnull final String path,
264258
String message = String.format("HTTP status code: %d; Message: %s", statusCode, reason);
265259
throw new InfluxDBApiHttpException(message, response.headers(), response.statusCode());
266260
}
261+
262+
return response;
267263
}
268264

269265
private X509TrustManager getX509TrustManagerFromFile(@Nonnull final String filePath) {

0 commit comments

Comments
 (0)