influxdata / influxdb-java

Java client for InfluxDB
MIT License
1.17k stars 476 forks source link

Support for HTTP write with Proxy. #455

Open atul555 opened 6 years ago

atul555 commented 6 years ago

Currently the code throws exception org.influxdb.InfluxDBIOException: java.net.UnknownHostException if the client sits behind the proxy and can not resolve the hostname. Hostname InetAddress is only used for UDP writes so IMHO, the constructor call in InfluxDBImpl this.hostAddress = parseHostAddress(url); can be moved to initialDatagramSocket() method. Which at least enables the HTTP traffic from behind firewall.

majst01 commented 6 years ago

Hi,

you need to set the proxy via property: https://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html

Example:

JAVA_FLAGS=-Dhttp.proxyHost=10.0.0.100 -Dhttp.proxyPort=8800
java ${JAVA_FLAGS} ...
benjaminbauer commented 5 years ago

I tried the approach with setting the JAVA flags, but no luck. What I tried is

final Proxy proxyTest = new Proxy( Proxy.Type.HTTP, new InetSocketAddress( "127.0.0.1", 3128 ) );

final OkHttpClient.Builder builder = new OkHttpClient.Builder()
            .proxy( proxyTest );

final InfluxDB influxDB = InfluxDBFactory.connect( url, influxUser, influxPassword, builder );

Which also fails, since InfluxDBImpl circumvents the OkHttpClient at a crucial point: https://github.com/influxdata/influxdb-java/blob/master/src/main/java/org/influxdb/impl/InfluxDBImpl.java#L232 InetAddress.getByName(hostName);