How to configure HTTP proxy in Java client library


#1

Hello,

Is it possible to configure host and port of HTTP proxy that should be used inside DataSift Java Client API?

It seems setting http.proxyHost and http.proxyPort system variables does not help as Java Client API uses HttpClient internally. I know that without proper configuration of proxy HTTP streaming and WebSockets will not work correctly but still.

Thanks,
Artsiom


#2

Unfortunately this is not currently possible. I have raised a feature request on the DataSift-Java Github repo. This can be tracked here - https://github.com/datasift/datasift-java/issues/30


#3

Thanks for cooperation on this!


#4

You can give this a try:

 

Around line 127 of HttpThread.java: DefaultHttpClient client = new DefaultHttpClient();

Change to:

HttpHost proxy = new HttpHost("your proxy host",portnum);
DefaultHttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);

In addition to that, you'll need to include:

import org.apache.http.HttpHost;
import org.apache.http.conn.params.ConnRoutePNames;

Let us know if that works


#5

Thanks for code snippet.

I am using WS consumer as previously we had issues with HTTP consumer when using through proxy (not possible to stop running streams). Is it possible to change java Client API so that WSConnection is done through HTTP proxy?

I already changed ApiClient.java to compile CSDL filter through HTTP proxy, need to understand how to modify WebSocketsConnection.

Thank you in advance.


#6

The Weberknecht WebSocket library we use does not currently support proxy authentication. Again, I will add this as a feature request on the DataSift Java Github repo.


#7

Hi,

Again thanks for your help!

Just a summary of my changes to make websockets consumer working through http proxy:

  1. modified HttpClient inside ApiClient.java to use HTTP proxy (as mentioned by victor.duan above);
  2. modified WebSocketsConnection.java to create socket via ProxyClient class:

ProxyClient proxyClient = new ProxyClient();
HttpHost target = new HttpHost(host, port);
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(“user”, “pwd”);
return proxyClient.tunnel(proxy, target, credentials);

Please note that to use ProxyClient class HttpComponents libraries should be upgraded to version 4.2.1

However it is not easy to maintain my own version of DataSift client library and it will require merging if I want to use latest features from your official library in future so I am looking forward to see these useful features in the official version on github. Thank you!

Regards,
Artsiom


#8

Thanks Artsiom, this is great news! If you would like to send a pull request to the official DataSift-Java library, we would be happy to review your changes, and potentially merge them into the library.