Proxy Server for innogy SmartHome Binding

Tags: #<Tag:0x00007f6181dc7550> #<Tag:0x00007f6181dc6dd0> #<Tag:0x00007f6181dc66a0>

Hi,

I have tried to configure a proxy server by using the EXTRA_JAVA_OPTS in /etc/default/openhab2 as suggested in [1] and [2].

EXTRA_JAVA_OPTS="-Dhttp.proxySet=true -Dhttps.proxyHost=proxy.xxx.org -Dhttps.proxyPort=8080 -Dhttp.proxyHost=proxy.xxx.org -Dhttp.proxyPort=8080 -Dhttp.nonProxyHosts='localhost|127.0.0.1'"

But I think the InnogyWebSocket isn’t picking up these proxy settings:

10:05:45.859 [ERROR] [gysmarthome.internal.InnogyWebSocket] - innogy WebSocket onError() - Connect Timeout
2018-10-08 10:05:46.587 [ERROR] [marthome.handler.InnogyBridgeHandler] - Error starting websocket.
java.util.concurrent.ExecutionException: java.net.SocketTimeoutException: Connect Timeout
        at org.eclipse.jetty.util.FuturePromise.get(FuturePromise.java:123) [87:org.eclipse.jetty.util:9.3.21.v20170918]
        at org.openhab.binding.innogysmarthome.internal.InnogyWebSocket.start(InnogyWebSocket.java:79) [196:org.openhab.binding.innogysmarthome:2.3.0]
        at org.openhab.binding.innogysmarthome.handler.InnogyBridgeHandler$WebSocketRunner.run(InnogyBridgeHandler.java:191) [196:org.openhab.binding.innogysmarthome:2.3.0]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.net.SocketTimeoutException: Connect Timeout
        at org.eclipse.jetty.io.ManagedSelector$ConnectTimeout.run(ManagedSelector.java:683) ~[?:?]

May it be possible that the proxy has to be explicitly set in the WebSocketClient constructor by using the HttpClient?

This might be a possible solution:

SslContextFactory sslContextFactory = new SslContextFactory();
// sslContextFactory.setTrustAll(true); // The magic

HttpClient httpClient = new HttpClient(sslContextFactory);

// Optional add proxy to httpClient
if (StringUtils.isNotEmpty(config.getProxyHost()) && StringUtils.isNotEmpty(config.getProxyPort())) {
	LOGGER.debug("Use Proxy for Websocket: " + config.getProxyHost() + ":" + config.getProxyPort());
	ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
	HttpProxy proxy = new HttpProxy(config.getProxyHost(), Integer.parseInt(config.getProxyPort()));
	proxyConfig.getProxies().add(proxy);
}
// Start HttpClient
httpClient.start();

// Create WebSocketClient
client = new WebSocketClient(httpClient);

Or is there another fix to get the innogy SmartHome binding working with a proxy server?

Thanks!

[1] Proxy Server for HTTP Binding
[2] Set up HTTP Bindings when openHAB runs behind a HTTP proxy