What to include to make it work on multiple OSes?

53 views
Skip to first unread message

Adam Giemza

unread,
Sep 26, 2012, 6:16:01 AM9/26/12
to proxy...@googlegroups.com
Hi,

I am developing an application that needs to work on Windows, Linux and MacOS. When I download the binary package, I can only find two jars but no dlls, that are mentioned in the project description. Am I missing something or is it really just the one single jar (proxy-vole_20120920.jar) that needs to be added to the classpath when working with Java > 1.6?

I would also appreciate if this library would be available via a Maven repository :)

Thanks,
 Adam

Adam Giemza

unread,
Sep 26, 2012, 10:55:32 AM9/26/12
to proxy...@googlegroups.com
Okay, I figured it out myself. In this point the documentation could be improved.

You just need to add the jar mentioned above to your classpath (dlls are included) and this code helped me to configure the proxy stettings:

ProxySearch proxySearch = new ProxySearch();
proxySearch.addStrategy(Strategy.OS_DEFAULT); 
proxySearch.addStrategy(Strategy.JAVA); 
proxySearch.addStrategy(Strategy.BROWSER); 
ProxySelector proxySelector = proxySearch.getProxySelector(); 

ProxySelector.setDefault(proxySelector);
URI home = URI.create("http://mobilogue.collide.info"); 
System.out.println("ProxySelector: " + proxySelector); 
System.out.println("URI: " + home); 
List<Proxy> proxyList = proxySelector.select(home); 
if (proxyList != null && !proxyList.isEmpty()) {
 for (Proxy proxy : proxyList) { 
   System.out.println(proxy); 
   SocketAddress address = proxy.address(); 
   if (address instanceof InetSocketAddress) { 
     String host = ((InetSocketAddress) address).getHostName(); 
     String port = Integer.toString(((InetSocketAddress) address).getPort()); 
     System.setProperty("http.proxyHost", host); 
     System.setProperty("http.proxyPort", port); 
   } 
 } 
}

Hope that will help others :)

Rossi

unread,
Sep 26, 2012, 5:00:01 PM9/26/12
to proxy...@googlegroups.com
Hello Adam,

Yes you only need to add the JAR file to the classpath and the rest is done automatically. The dlls are included within the JAR file.

To use the library please have a look at the wiki page at

http://code.google.com/p/proxy-vole/wiki/UsageExamples

It explains how to use the library. Your example works but is not optimal. It will not work if for example the System uses a "dynamic proxy per URL" (PAC file).

The correct usage would look like this.

ProxySearch proxySearch = ProxySearch.getDefaultProxySearch();
ProxySelector myProxySelector = proxySearch.getProxySelector();
ProxySelector.setDefault(myProxySelector);

That is normally all that you need to do in your code.
This installs a Java VM global proxy selector that is used for all URLs.

A version in maven may come some day but at the moment I have no mood to learn how to release a library to a maven repository.

Have fun,
- Rossi

Reply all
Reply to author
Forward
0 new messages