You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2006/11/20 15:08:59 UTC
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
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()