|
33 | 33 | import java.security.SecureRandom; |
34 | 34 | import java.security.cert.Certificate; |
35 | 35 | import java.security.cert.CertificateFactory; |
| 36 | +import java.security.cert.X509Certificate; |
36 | 37 | import java.util.ArrayList; |
37 | 38 | import java.util.List; |
38 | 39 | import java.util.Map; |
| 40 | +import java.util.Optional; |
39 | 41 | import java.util.stream.Stream; |
40 | 42 | import javax.annotation.Nonnull; |
41 | 43 | import javax.annotation.Nullable; |
@@ -63,16 +65,16 @@ final class RestClient implements AutoCloseable { |
63 | 65 |
|
64 | 66 | private static final TrustManager[] TRUST_ALL_CERTS = new TrustManager[]{ |
65 | 67 | new X509TrustManager() { |
66 | | - public java.security.cert.X509Certificate[] getAcceptedIssuers() { |
| 68 | + public X509Certificate[] getAcceptedIssuers() { |
67 | 69 | return null; |
68 | 70 | } |
69 | 71 |
|
70 | 72 | public void checkClientTrusted( |
71 | | - final java.security.cert.X509Certificate[] certs, final String authType) { |
| 73 | + final X509Certificate[] certs, final String authType) { |
72 | 74 | } |
73 | 75 |
|
74 | 76 | public void checkServerTrusted( |
75 | | - final java.security.cert.X509Certificate[] certs, final String authType) { |
| 77 | + final X509Certificate[] certs, final String authType) { |
76 | 78 | } |
77 | 79 | } |
78 | 80 | }; |
@@ -140,11 +142,27 @@ public void checkServerTrusted( |
140 | 142 | this.client = builder.build(); |
141 | 143 | } |
142 | 144 |
|
143 | | - void request(@Nonnull final String path, |
144 | | - @Nonnull final HttpMethod method, |
145 | | - @Nullable final byte[] data, |
146 | | - @Nullable final Map<String, String> queryParams, |
147 | | - @Nullable final Map<String, String> headers) { |
| 145 | + public String getServerVersion() { |
| 146 | + String influxdbVersion; |
| 147 | + HttpResponse<String> response = request("ping", HttpMethod.GET, null, null, null); |
| 148 | + try { |
| 149 | + influxdbVersion = response.headers().firstValue("X-Influxdb-Version").orElse(null); |
| 150 | + if (influxdbVersion == null) { |
| 151 | + JsonNode jsonNode = objectMapper.readTree(response.body()); |
| 152 | + influxdbVersion = Optional.ofNullable(jsonNode.get("version")).map(JsonNode::asText).orElse(null); |
| 153 | + } |
| 154 | + } catch (JsonProcessingException e) { |
| 155 | + return null; |
| 156 | + } |
| 157 | + |
| 158 | + return influxdbVersion; |
| 159 | + } |
| 160 | + |
| 161 | + HttpResponse<String> request(@Nonnull final String path, |
| 162 | + @Nonnull final HttpMethod method, |
| 163 | + @Nullable final byte[] data, |
| 164 | + @Nullable final Map<String, String> queryParams, |
| 165 | + @Nullable final Map<String, String> headers) { |
148 | 166 |
|
149 | 167 | QueryStringEncoder uriEncoder = new QueryStringEncoder(String.format("%s%s", baseUrl, path)); |
150 | 168 | if (queryParams != null) { |
@@ -235,6 +253,8 @@ void request(@Nonnull final String path, |
235 | 253 | String message = String.format("HTTP status code: %d; Message: %s", statusCode, reason); |
236 | 254 | throw new InfluxDBApiHttpException(message, response.headers(), response.statusCode()); |
237 | 255 | } |
| 256 | + |
| 257 | + return response; |
238 | 258 | } |
239 | 259 |
|
240 | 260 | private X509TrustManager getX509TrustManagerFromFile(@Nonnull final String filePath) { |
|
0 commit comments