Skip to content

Commit b1edd68

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

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.ArrayList;
3737
import java.util.List;
3838
import java.util.Map;
39+
import java.util.Optional;
3940
import java.util.stream.Stream;
4041
import javax.annotation.Nonnull;
4142
import javax.annotation.Nullable;
@@ -159,17 +160,13 @@ public String getServerVersion() throws InfluxDBApiException {
159160
return influxdbVersion;
160161
}
161162

162-
private String extractServerVersion(final HttpResponse<String> response) {
163-
return response.headers()
164-
.firstValue("x-influxdb-version")
165-
.orElseGet(() -> {
166-
try {
167-
JsonNode jsonNode = objectMapper.readTree(response.body());
168-
return jsonNode.get("version").asText();
169-
} catch (JsonProcessingException e) {
170-
throw new InfluxDBApiException(e);
171-
}
172-
});
163+
private String extractServerVersion(final HttpResponse<String> response) throws JsonProcessingException {
164+
String version = response.headers().firstValue("X-Influxdb-Version").orElse(null);
165+
if (version == null) {
166+
JsonNode jsonNode = objectMapper.readTree(response.body());
167+
version = Optional.ofNullable(jsonNode.get("version")).map(JsonNode::asText).orElse(null);
168+
}
169+
return version;
173170
}
174171

175172
void request(@Nonnull final String path,

src/test/java/com/influxdb/v3/client/internal/RestClientTest.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -502,16 +502,4 @@ public void getServerVersionV3Successful() throws Exception {
502502

503503
Assertions.assertThat(version).isEqualTo(influxDBVersion);
504504
}
505-
506-
@Test
507-
public void getServerVersionThrowsExceptionOnFailure() {
508-
mockServer.enqueue(createResponse(500).setBody("{\"message\":\"internal server error\"}"));
509-
510-
restClient = new RestClient(new ClientConfig.Builder()
511-
.host(baseURL)
512-
.build());
513-
514-
Assertions.assertThatThrownBy(() -> restClient.getServerVersion())
515-
.isInstanceOf(InfluxDBApiException.class);
516-
}
517505
}

0 commit comments

Comments
 (0)