i also found it odd that reflection is being used to call
socket.shutdownOutput() ... why is this?

-kevin.

kevin seguin wrote:
> 
> i think i've found a problem in HttpClient that may be related to
> problems in the test case (TestMethods.java) with the java.sun.com url.
> 
> i was having the same problems with hitting an apache web server on my
> local machine as i saw when trying to hit the java.sun.com url, which is
> why i starting digging through the code.
> 
> anyway, the problem i found is HttpClient is determining whether or not
> to shutdown the socket's output by checking whether or not http 1.1. is
> being used, but it's checking to see if http 1.1 is being used before
> parsing the status line from the response, which tells the client
> whether http 1.1 should be used or not.  so, after it has shutdown the
> socket's output, then it tries to read the response.  this is what
> seemed to be causing my problems.
> 
> i'm not so sure i've explained this very well, so here's a step by step
> of what is happening:
> 
> 1) send request to server
> 2) look at http11 flag (default is false) to see if socket's output
> should be closed
> 3) if !http11, close output
> 4) read status line, which sets http11 flag.
> 
> i changed it so that 4) happens right after 1), and my problems appeared
> to go away.  also, i could use the java.sun.com url in the test.
> 
> attached is a patch.
> 
> -kevin.
> 
>   ------------------------------------------------------------------------
> Index: src/java/org/apache/commons/httpclient/HttpClient.java
> ===================================================================
> RCS file: 
>/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
> retrieving revision 1.13
> diff -u -r1.13 HttpClient.java
> --- src/java/org/apache/commons/httpclient/HttpClient.java      2001/05/17 23:58:51  
>   1.13
> +++ src/java/org/apache/commons/httpclient/HttpClient.java      2001/05/19 17:38:38
> @@ -427,8 +427,19 @@
>                      connectionInterceptor.sentRequest();
>                  }
> 
> +                // Parsing response
> +
> +                // Parse status line
> +                String statusLine = readLine(input);
> +                if (statusLine == null)
> +                    throw new IOException("Couldn't parse status line");
> +                parseStatusLine(statusLine, method);
> +
>                  boolean closeOutput = needToCloseOutput();
>                  if (closeOutput) {
> +                    if (debug > 0) {
> +                        System.out.println("closing output...");
> +                    }
>                      try {
>                          Class[] paramsClasses = new Class[0];
>                          Method shutdownOutput = socket.getClass().getMethod
> @@ -440,14 +451,6 @@
>                      }
>                  }
> 
> -                // Parsing response
> -
> -                // Parse status line
> -                String statusLine = readLine(input);
> -                if (statusLine == null)
> -                    throw new IOException("Couldn't parse status line");
> -                parseStatusLine(statusLine, method);
> -
>                  // Parse headers
>                  responseHeaders = parseHeaders(input);
> 
> @@ -947,6 +950,15 @@
>          StringBuffer sb = new StringBuffer();
>          while (true) {
>              int ch = input.read();
> +            if (debug > 10) {
> +                if (ch != -1) {
> +                    System.out.println("read " + (char)ch);
> +                    break;
> +                } else {
> +                    System.out.println("read EOF");
> +                }
> +            }
> +
>              if (ch < 0) {
>                  if (sb.length() == 0) {
>                      return (null);

Reply via email to