Hi Tim,

Could you provide some more specifics regarding the two bugs that you mention? In particular, sample code, stack traces, and either a URL or a wire log <http://jakarta.apache.org/commons/httpclient/logging.html>.

Thanks,

Mike

On Wednesday, October 15, 2003, at 05:28 PM, Tim McCune wrote:

This patch is against 2.0rc2.
I ran into a problem where the HttpClient kept thinking that the
connection was closed while talking to an IIS 5.0 server, even though my
web browser could load the page fine. Turns out that the server was
sending a line feed as the first byte of the response, which HttpClient
treats as a closed connection due to a bug in HttpParser. This patch
also contains a fix in HttpMethodBase.java for a NullPointerException
that happens when responseConnection is null, as well as an enhancement
that someone else in our organization submitted a while back but
apparently never got accepted.
Index: src/java/org/apache/commons/httpclient/HttpMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/ commons/httpclient/HttpMethod.java,v
retrieving revision 1.23.2.3
diff -u -r1.23.2.3 HttpMethod.java
--- src/java/org/apache/commons/httpclient/HttpMethod.java 12 Aug 2003 02:39:41 -0000 1.23.2.3
+++ src/java/org/apache/commons/httpclient/HttpMethod.java 15 Oct 2003 21:18:45 -0000
@@ -1,5 +1,5 @@
/*
- * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/ commons/httpclient/HttpMethod.java,v 1.23.2.3 2003/08/12 02:39:41 mbecke Exp $
+ * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/ httpclient/HttpMethod.java,v 1.23.2.3 2003/08/12 02:39:41 mbecke Exp $
* $Revision: 1.23.2.3 $
* $Date: 2003/08/12 02:39:41 $
*
@@ -245,6 +245,22 @@
* <tt>false</tt> otherwise
*/
void setFollowRedirects(boolean followRedirects);
+
+ /**
+ * Whether connections should be reinitialized across redirects.
+ *
+ * @param reinitializeConnectionOnRetry true to close and reopen a
+ * connection, false otherwise.
+ */
+ public void setReinitializeConnectionOnRetry(boolean reinitializeConnectionOnRetry);
+
+ /**
+ * Whether or not I should reconnect before following HTTP redirects
+ * (status code 302, etc.)
+ *
+ * @return <tt>true</tt> if I will reconnect before follow HTTP redirects
+ */
+ public boolean getReinitializeConnectionOnRetry();


/**
* Sets the query string of the HTTP method.
Index: src/java/org/apache/commons/httpclient/HttpMethodBase.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/ commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.159.2.14
diff -u -r1.159.2.14 HttpMethodBase.java
--- src/java/org/apache/commons/httpclient/HttpMethodBase.java 13 Oct 2003 12:19:22 -0000 1.159.2.14
+++ src/java/org/apache/commons/httpclient/HttpMethodBase.java 15 Oct 2003 21:18:46 -0000
@@ -1,5 +1,5 @@
/*
- * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/ commons/httpclient/HttpMethodBase.java,v 1.159.2.14 2003/10/13 12:19:22 mbecke Exp $
+ * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/ httpclient/HttpMethodBase.java,v 1.159.2.14 2003/10/13 12:19:22 mbecke Exp $
* $Revision: 1.159.2.14 $
* $Date: 2003/10/13 12:19:22 $
*
@@ -242,6 +242,8 @@
/** True if this HTTP method is finished with the connection */
private boolean doneWithConnection = false;


+    private boolean reinitializeConnectionOnRetry = false;
+
     /** True if the connection must be closed when no longer needed */
     private boolean connectionCloseForced = false;

@@ -373,8 +375,27 @@
public boolean getFollowRedirects() {
return this.followRedirects;
}
+
+ /**
+ * Whether connections should be reinitialized across redirects.
+ *
+ * @param reinitializeConnectionOnRetry true to close and reopen a
+ * connection, false otherwise.
+ */
+ public void setReinitializeConnectionOnRetry(boolean reinitializeConnectionOnRetry) {
+ this.reinitializeConnectionOnRetry = reinitializeConnectionOnRetry;
+ }


/**
+ * Whether or not I should reconnect before following HTTP redirects
+ * (status code 302, etc.)
+ *
+ * @return <tt>true</tt> if I will reconnect before follow HTTP redirects
+ */
+ public boolean getReinitializeConnectionOnRetry() {
+ return this.reinitializeConnectionOnRetry;
+ }
+
/** Sets whether version 1.1 of the HTTP protocol should be used per default.
*
* @param http11 <tt>true</tt> to use HTTP/1.1, <tt>false</tt> to use 1.0
@@ -1089,12 +1110,17 @@
break;
}


+ if (reinitializeConnectionOnRetry) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Closing the connection");
+ }
+ conn.close();
+ }
+
// retry - close previous stream. Caution - this causes
// responseBodyConsumed to be called, which may also close the
// connection.
- if (responseStream != null) {
- responseStream.close();
- }
+ releaseConnection();


} //end of retry loop

@@ -2739,10 +2765,12 @@
// make sure this is the initial invocation of the notification,
// ignore subsequent ones.
responseStream = null;
- responseConnection.setLastResponseInputStream(null);
+ if (responseConnection != null) {
+ responseConnection.setLastResponseInputStream(null);


-        if (shouldCloseConnection(responseConnection)) {
-            responseConnection.close();
+          if (shouldCloseConnection(responseConnection)) {
+              responseConnection.close();
+          }
         }

doneWithConnection = true;
Index: src/java/org/apache/commons/httpclient/HttpParser.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/ commons/httpclient/HttpParser.java,v
retrieving revision 1.7
diff -u -r1.7 HttpParser.java
--- src/java/org/apache/commons/httpclient/HttpParser.java 26 May 2003 21:51:37 -0000 1.7
+++ src/java/org/apache/commons/httpclient/HttpParser.java 15 Oct 2003 21:18:46 -0000
@@ -104,15 +104,17 @@
public static byte[] readRawLine(InputStream inputStream) throws IOException {
LOG.trace("enter HttpParser.readRawLine()");


+        boolean eos = true;
         ByteArrayOutputStream buf = new ByteArrayOutputStream();
         int ch;
         while ((ch = inputStream.read()) >= 0) {
+            eos = false;
             buf.write(ch);
             if (ch == '\n') {
                 break;
             }
         }
-        if (buf.size() == 0) {
+        if (eos) {
             return null;
         }
         return buf.toByteArray();

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to