harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r931940 - in /harmony/enhanced/java/trunk/classlib/modules/luni/src: main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
Date Thu, 08 Apr 2010 13:42:28 GMT
Author: regisxu
Date: Thu Apr  8 13:42:28 2010
New Revision: 931940

URL: http://svn.apache.org/viewvc?rev=931940&view=rev
Log:
Apply patch for HARMONY-6494: [classlib][luni] OutputStream of HttpURLConnection should not
throw IOExecption

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java?rev=931940&r1=931939&r2=931940&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
Thu Apr  8 13:42:28 2010
@@ -359,6 +359,8 @@ public class HttpURLConnectionImpl exten
         boolean closed;
 
         int limit;
+        
+        boolean fixedMod = false;
 
         public HttpOutputStream() {
             cacheLength = defaultCacheSize;
@@ -366,9 +368,10 @@ public class HttpURLConnectionImpl exten
             limit = -1;
         }
 
-        public HttpOutputStream(int limit) {
+        public HttpOutputStream(int limit, boolean fixedMode) {
             writeToSocket = true;
             this.limit = limit;
+            this.fixedMod = fixedMode;
             if (limit > 0) {
                 cacheLength = limit;
             } else {
@@ -445,7 +448,10 @@ public class HttpURLConnectionImpl exten
                 return;
             }
             closed = true;
-            if (writeToSocket) {
+            //Only with such situation when the fixedContentLength field of HttpURLConnection
+            //is set by HttpURLConnection.setFixedLengthStreamingMode and larger than 0,
the
+            //IOException will be throwed
+            if (writeToSocket && fixedMod) {
                 if (limit > 0) {
                     throw new IOException(Messages.getString("luni.25")); //$NON-NLS-1$
                 }
@@ -952,11 +958,14 @@ public class HttpURLConnectionImpl exten
             sendChunked = true;
             limit = -1;
         }
+        
+        boolean fixedMode = false;
         if (fixedContentLength >= 0) {
             limit = fixedContentLength;
+            fixedMode = true;
         }
         if ((httpVersion > 0 && sendChunked) || limit >= 0) {
-            os = new HttpOutputStream(limit);
+            os = new HttpOutputStream(limit, fixedMode);
             doRequest();
             return os;
         }

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java?rev=931940&r1=931939&r2=931940&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
Thu Apr  8 13:42:28 2010
@@ -317,6 +317,34 @@ public class HttpURLConnectionTest exten
             // correct, too many bytes written
         }
     }
+    
+    /**
+     * When an OutputStream of HtttpURLConnection is closed with below
+     * situation: fixed-length mod is disable and the content-length of the
+     * HtttpURLConnection is larger than 0, it should not throw IOExeption which
+     * indicates there are more bytes need be written into the underlying
+     * Socket.
+     * 
+     * @throws IOException
+     */
+    public void test_closeWithFixedLengthDisableMod() throws IOException {
+        String posted = "just a test";
+        java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url
+                .openConnection();
+        conn.setDoOutput(true);
+        conn.setRequestMethod("POST");
+        conn.setRequestProperty("Content-Length", "" + (888));
+
+        OutputStream out = conn.getOutputStream();
+        out.write(posted.getBytes());
+
+        try {
+            out.close();
+            // expected
+        } catch (IOException e) {
+            fail("should not throw IOException");
+        }
+    }
 
     /**
      * @tests java.net.HttpURLConnection#setChunkedStreamingMode_I()



Mime
View raw message