changeset 7244:b702977e7212

5001942: Missings SOCKS support for direct connections Summary: Add support for socksNonProxyHosts Reviewed-by: chegar, khazra Contributed-by: Christos Zoulas <christos@zoulas.com>
author khazra
date Fri, 05 Apr 2013 12:12:34 -0700
parents b62a76763bf3
children ba231ac2890a
files src/share/classes/sun/net/spi/DefaultProxySelector.java test/java/net/Socks/SocksProxyVersion.java
diffstat 2 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/net/spi/DefaultProxySelector.java	Fri Apr 05 10:41:46 2013 -0700
+++ b/src/share/classes/sun/net/spi/DefaultProxySelector.java	Fri Apr 05 12:12:34 2013 -0700
@@ -124,6 +124,7 @@
         final String defaultVal;
         static NonProxyInfo ftpNonProxyInfo = new NonProxyInfo("ftp.nonProxyHosts", null, null, defStringVal);
         static NonProxyInfo httpNonProxyInfo = new NonProxyInfo("http.nonProxyHosts", null, null, defStringVal);
+        static NonProxyInfo socksNonProxyInfo = new NonProxyInfo("socksNonProxyHosts", null, null, defStringVal);
 
         NonProxyInfo(String p, String s, RegexpPool pool, String d) {
             property = p;
@@ -186,6 +187,8 @@
             pinfo = NonProxyInfo.httpNonProxyInfo;
         } else if ("ftp".equalsIgnoreCase(protocol)) {
             pinfo = NonProxyInfo.ftpNonProxyInfo;
+        } else if ("socket".equalsIgnoreCase(protocol)) {
+            pinfo = NonProxyInfo.socksNonProxyInfo;
         }
 
         /**
--- a/test/java/net/Socks/SocksProxyVersion.java	Fri Apr 05 10:41:46 2013 -0700
+++ b/test/java/net/Socks/SocksProxyVersion.java	Fri Apr 05 12:12:34 2013 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 6964547
+ * @bug 6964547 5001942
  * @run main/othervm SocksProxyVersion
  * @summary test socksProxyVersion system property
  */
@@ -34,6 +34,7 @@
 import java.net.SocketException;
 import java.io.DataInputStream;
 import java.io.IOException;
+import java.net.InetAddress;
 
 public class SocksProxyVersion implements Runnable {
     final ServerSocket ss;
@@ -56,13 +57,19 @@
         Thread serverThread = new Thread(this);
         serverThread.start();
 
-        System.setProperty("socksProxyHost", "localhost");
+        /*
+         * Retreving the IP Address of the machine
+         * since "localhost" is bypassed as a non-proxy host
+         */
+        String addr = InetAddress.getLocalHost().getHostAddress();
+
+        System.setProperty("socksProxyHost", addr);
         System.setProperty("socksProxyPort", Integer.toString(port));
 
         // SOCKS V4
         System.setProperty("socksProxyVersion", Integer.toString(4));
         try (Socket s = new Socket()) {
-            s.connect(new InetSocketAddress("localhost", port));
+            s.connect(new InetSocketAddress(addr, port));
         } catch (SocketException e) {
             // java.net.SocketException: Malformed reply from SOCKS server
             // This exception is OK, since the "server" does not implement
@@ -72,7 +79,7 @@
         // SOCKS V5
         System.setProperty("socksProxyVersion", Integer.toString(5));
         try (Socket s = new Socket()) {
-            s.connect(new InetSocketAddress("localhost", port));
+            s.connect(new InetSocketAddress(addr, port));
         } catch (SocketException e) { /* OK */ }
 
         serverThread.join();