Hi Regis/Deven,
This commit causes
org.apache.harmony.luni.tests.java.net.URLConnectionTest to hang for me
with the following output:
[junit] Running
org.apache.harmony.luni.tests.java.net.URLConnectionTest
[junit] 2010-04-13 15:01:02.250::INFO: Logging to STDERR via
org.mortbay.log.StdErrLog
[junit] 2010-04-13 15:01:02.281::INFO: jetty-6.0.x
[junit] 2010-04-13 15:01:02.343::INFO: Started SocketConnector @
0.0.0.0:4456
[junit] Wait timed out. Test HTTP Server shut down.
Reverting to the previous revision of HttpURLConnectionImpl.java fixes
the problem. Can you investigate what is causing this and either revert
the change or apply a fix please? Thanks.
Regards,
Oliver
On 08/04/2010 14:42, regi...@apache.org wrote:
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()
--
Oliver Deakin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU