harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r416373 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/org/apache/harmony/luni/net/NetUtil.java main/java/org/apache/harmony/luni/net/PlainSocketImpl.java test/java/tests/api/java/net/ServerSocketTest.java
Date Thu, 22 Jun 2006 13:56:58 GMT
Author: gharley
Date: Thu Jun 22 06:56:57 2006
New Revision: 416373

URL: http://svn.apache.org/viewvc?rev=416373&view=rev
Log:
HARMONY 623 : java.net.ServerSocket constructor should not throw IOException if "socksProxyHost"
property is set

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/NetUtil.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ServerSocketTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/NetUtil.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/NetUtil.java?rev=416373&r1=416372&r2=416373&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/NetUtil.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/NetUtil.java
Thu Jun 22 06:56:57 2006
@@ -24,35 +24,20 @@
 
 public class NetUtil {
     
-    /*
-     * FIXME: enhance performance to cache the values
-     */
-    
     /**
-	 * Answer whether to use a SOCKS proxy.
-	 * 
-	 * @param proxy
-	 *            java.net.Proxy, may be <code>null</code> in which case the 
-     *            return value is determined from the values of the 
-     *            "socksProxySet" and "socksProxyHost" system properties.
-	 * @return true if SOCKS proxy is set by <code>proxy</code> parameter or
-     *         else "socksProxySet" system property is set and has the value
-     *         of "true" or if "socksProxyHost" is set in system properties.
-	 */
+     * Answers whether to use a SOCKS proxy.
+     * 
+     * @param proxy
+     *            java.net.Proxy <code>proxy</code> is used to determine
+     *            whether using SOCKS proxy.
+     * @return true if only the type of <code>proxy</code> is
+     *         Proxy.Type.SOCKS.
+     */
     public static boolean usingSocks(Proxy proxy) {
-    	if(null != proxy && Proxy.NO_PROXY == proxy){
-    		return false;
-    	}
     	if(null != proxy && Proxy.Type.SOCKS == proxy.type()){
     		return true;
     	}
-        String proxySet = AccessController
-                .doPrivileged(new PriviAction<String>("socksProxySet")); //$NON-NLS-1$
-        if (proxySet != null) {
-            return proxySet.toLowerCase().equals("true"); //$NON-NLS-1$
-        }
-        return AccessController.doPrivileged(new PriviAction<String>(
-                "socksProxyHost")) != null; //$NON-NLS-1$
+        return false;
     }
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java?rev=416373&r1=416372&r2=416373&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
Thu Jun 22 06:56:57 2006
@@ -30,12 +30,10 @@
 import java.net.SocketOptions;
 import java.net.SocketTimeoutException;
 import java.net.UnknownHostException;
-import java.security.AccessController;
 
 import org.apache.harmony.luni.platform.INetworkSystem;
 import org.apache.harmony.luni.platform.Platform;
 import org.apache.harmony.luni.util.Msg;
-import org.apache.harmony.luni.util.PriviAction;
 
 /**
  * A concrete connected-socket implementation.
@@ -392,52 +390,36 @@
 		}
 	}
 
-	/**
-	 * Get the SOCKS proxy server port.
-	 */
-	private int socksGetServerPort() {
-		int portValue = -1;
-		
-		if(null != proxy && Proxy.Type.SOCKS == proxy.type()){
-			// get from proxy first
-			InetSocketAddress addr = (InetSocketAddress)proxy.address();
-			return addr.getPort();
-		}
-		
-		String proxyPort = AccessController
-				.doPrivileged(new PriviAction<String>("socksProxyPort"));
-
-		if (proxyPort != null) {
-			portValue = Integer.parseInt(proxyPort);
-		}
-		if (portValue < 0) {
-			portValue = 1080;
-		}
-
-		return portValue;
-	}
-
-	/**
-	 * Get the InetAddress of the SOCKS proxy server.
-	 */
-	private InetAddress socksGetServerAddress() throws UnknownHostException {
-		String proxyName;
-		if(null != proxy && Proxy.Type.SOCKS == proxy.type()){
-			// get from proxy first
-			InetSocketAddress addr = (InetSocketAddress)proxy.address();
-			proxyName = addr.getHostName();
-			if(null == proxyName){
-				proxyName = addr.getAddress().getHostAddress();
-			}
-		}else{
-			// get from system properties
-			proxyName = AccessController
-				.doPrivileged(new PriviAction<String>("socksProxyHost"));
-		}
-		InetAddress anAddr = netImpl.getHostByName(proxyName,
-                NetUtil.preferIPv6Addresses());
-		return anAddr;
-	}
+    /**
+     * Gets the SOCKS proxy server port.
+     */
+    private int socksGetServerPort() {
+        // get socks server port from proxy. It is unneccessary to check
+        // "socksProxyPort" property, since proxy setting should only be
+        // determined by ProxySelector.
+        InetSocketAddress addr = (InetSocketAddress) proxy.address();
+        return addr.getPort();
+
+    }
+
+    /**
+     * Gets the InetAddress of the SOCKS proxy server.
+     */
+    private InetAddress socksGetServerAddress() throws UnknownHostException {
+        String proxyName;
+        // get socks server address from proxy. It is unneccessary to check
+        // "socksProxyHost" property, since all proxy setting should be
+        // determined by ProxySelector.
+        InetSocketAddress addr = (InetSocketAddress) proxy.address();
+        proxyName = addr.getHostName();
+        if (null == proxyName) {
+            proxyName = addr.getAddress().getHostAddress();
+        }
+
+        InetAddress anAddr = netImpl.getHostByName(proxyName, NetUtil
+                .preferIPv6Addresses());
+        return anAddr;
+    }
 
 	/**
 	 * Connect using a SOCKS server.

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ServerSocketTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ServerSocketTest.java?rev=416373&r1=416372&r2=416373&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ServerSocketTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ServerSocketTest.java
Thu Jun 22 06:56:57 2006
@@ -25,6 +25,7 @@
 import java.net.SocketAddress;
 import java.net.SocketException;
 import java.util.Date;
+import java.util.Properties;
 
 import tests.support.Support_Configuration;
 import tests.support.Support_PortManager;
@@ -87,6 +88,25 @@
 		assertTrue("Used during tests", true);
 	}
 
+    /**
+     * @tests java.net.ServerSocket#ServerSocket(int)
+     */
+    public void test_ConstructorI_SocksSet() throws IOException {
+        //Harmony-623 regression test
+        ServerSocket ss = null;
+        Properties props = (Properties) System.getProperties().clone();
+        try {
+            System.setProperty("socksProxyHost", "127.0.0.1");
+            System.setProperty("socksProxyPort", "12345");
+            ss = new ServerSocket(Support_PortManager.getNextPort());
+        } finally {
+            System.setProperties(props);
+            if (null != ss) {
+                ss.close();
+            }
+        }
+    }
+    
 	/**
 	 * @tests java.net.ServerSocket#ServerSocket(int, int)
 	 */
@@ -360,9 +380,8 @@
 			fail("Exception during toString test : " + e.getMessage());
 		}
 
-		assertTrue("Returned incorrect string", s.toString().equals(
-				"ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport="
-						+ portNumber + "]"));
+        assertEquals("ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport="
+                        + portNumber + "]", s);
 	}
 
 	/**



Mime
View raw message