harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r477181 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLConnection.java test/java/tests/api/java/net/URLConnectionTest.java
Date Mon, 20 Nov 2006 14:08:59 GMT
Author: pyang
Date: Mon Nov 20 06:08:58 2006
New Revision: 477181

URL: http://svn.apache.org/viewvc?view=rev&rev=477181
Log:
Apply patch for HARMONY-2221 ([classlib][luni]method URLConnection.getRequestProperty should
throw IllegalStateException if already connected)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java?view=diff&rev=477181&r1=477180&r2=477181
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
Mon Nov 20 06:08:58 2006
@@ -648,14 +648,19 @@
 	 * @param field
 	 *            the field to get the property for
 	 * @return the field to look up
+	 * @throws IllegalStateException -
+	 *             if connection already established
 	 * 
 	 * @see #getDefaultRequestProperty
 	 * @see #setDefaultRequestProperty
 	 * @see #setRequestProperty
 	 */
-	public String getRequestProperty(String field) {
-		return null;
-	}
+    public String getRequestProperty(String field) {
+        if (this.connected == true) {
+            throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
+        }
+        return null;
+    }
 
 	/**
 	 * Answers the <code>URL</code> of this connection

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java?view=diff&rev=477181&r1=477180&r2=477181
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
Mon Nov 20 06:08:58 2006
@@ -34,6 +34,7 @@
 import java.net.SocketPermission;
 import java.net.URL;
 import java.net.URLConnection;
+import java.net.URLStreamHandler;
 import java.security.Permission;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
@@ -838,6 +839,43 @@
 		assertNull("Wrong property returned: " + uc.getRequestProperty("No"),
 				uc.getRequestProperty("No"));
 	}
+	
+	/**
+	 * @tests java.net.URLConnection#getRequestProperty(java.lang.String)
+	 */
+	public void test_getRequestProperty_LString_Exception() throws IOException {
+        class NewHandler extends URLStreamHandler {
+            protected URLConnection openConnection(URL u)
+                    throws java.io.IOException {
+                return new HttpURLConnection(u) {
+                    @Override
+                    public void disconnect() {
+                        // do nothing
+                    }
+                    @Override
+                    public boolean usingProxy() {
+                        return false;
+                    }
+                    @Override
+                    public void connect() throws IOException {
+                        connected = true;
+                    }
+                };
+            }
+        }
+        URL url = new URL("http", "test", 80, "index.html", new NewHandler());
+        URLConnection urlCon = url.openConnection();
+        urlCon.setRequestProperty("test", "testProperty");
+        assertNull(urlCon.getRequestProperty("test"));
+        
+        urlCon.connect();
+        try {
+            urlCon.getRequestProperty("test");
+            fail("should throw IllegalStateException");
+        } catch (IllegalStateException e) {
+            // expected
+        }
+    }
 
 	/**
 	 * @tests java.net.URLConnection#getURL()



Mime
View raw message