influxdata / influxdb-client-java

InfluxDB 2 JVM Based Clients
https://influxdata.github.io/influxdb-client-java/
MIT License
431 stars 129 forks source link

influxdb-client-java doesn't support https connection #757

Closed SimonDevHub closed 2 weeks ago

SimonDevHub commented 2 weeks ago

Steps to reproduce:

  1. Enable https with offcial docker image influxdb (2.X-alpine)
  2. Set https protocol in url parameter (java code)

Expected behavior: With certificate : OK Without certificate : SSL verification error

Actual behavior: With http protocol : OK Check with "curl -v https://influxdb_service:8086" : OK With https protocol : com.influxdb.exceptions.BadRequestException (with or without certificate)

Specifications:

SimonDevHub commented 2 weeks ago

I overloaded the influxdbclient with okhttp3 to add certificate and context in options to use https :

            var okHttpClient = new OkHttpClient.Builder()
                    .sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustManagers[0]);

            InfluxDBClientOptions options = InfluxDBClientOptions.builder()
                    .url(url)
                    .authenticateToken(token)
                    .org(org)
                    .bucket(bucket)
                    .okHttpClient(okHttpClient)
                    .build();

It may help some people.