How to configure HTTP proxy in Java client library



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.



Unfortunately this is not currently possible. I have raised a feature request on the DataSift-Java Github repo. This can be tracked here -


Thanks for cooperation on this!


You can give this a try:


Around line 127 of DefaultHttpClient client = new DefaultHttpClient();

Change to:

HttpHost proxy = new HttpHost("your proxy host",portnum);
DefaultHttpClient client = new DefaultHttpClient();

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


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 to compile CSDL filter through HTTP proxy, need to understand how to modify WebSocketsConnection.

Thank you in advance.


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.



Again thanks for your help!

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

  1. modified HttpClient inside to use HTTP proxy (as mentioned by victor.duan above);
  2. modified 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!



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.