influxdb-java icon indicating copy to clipboard operation
influxdb-java copied to clipboard

Support for HTTP write with Proxy.

Open atul555 opened this issue 7 years ago • 2 comments

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.

atul555 avatar Jun 08 '18 02:06 atul555

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} ...

majst01 avatar Jun 08 '18 05:06 majst01

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);

benjaminbauer avatar Dec 13 '18 15:12 benjaminbauer