influxdata / influxdb-client-java

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

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

Closed SimonDevHub closed 3 months ago

SimonDevHub commented 3 months 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 3 months 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.