jericho     01/02/26 05:38:32

  Modified:    src/webdav/client/src/org/apache/webdav/lib
                        WebdavClient.java
  Log:
  - Fix to parse the whole status line. Esp, status message.
  
  Revision  Changes    Path
  1.26      +31 -23    
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java
  
  Index: WebdavClient.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- WebdavClient.java 2001/02/26 06:35:57     1.25
  +++ WebdavClient.java 2001/02/26 13:38:31     1.26
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java,v
 1.25 2001/02/26 06:35:57 remm Exp $
  - * $Revision: 1.25 $
  - * $Date: 2001/02/26 06:35:57 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java,v
 1.26 2001/02/26 13:38:31 jericho Exp $
  + * $Revision: 1.26 $
  + * $Date: 2001/02/26 13:38:31 $
    *
    * ====================================================================
    *
  @@ -464,7 +464,7 @@
           try {
               if (socket == null) {
                   if (debug > 0)
  -                    System.out.println("Reopen connection : Host:" 
  +                    System.out.println("Reopen connection : Host:"
                                          + sessionHost + " Port:" + sessionPort);
                   socket = new Socket(this.sessionHost, this.sessionPort);
               }
  @@ -656,20 +656,20 @@
       protected void parseStatusLine(String statusLine, WebdavMethod method)
           throws IOException, WebdavException {
   
  +        statusLine = statusLine.trim();
           if (debug > 0)
               System.out.println("Response: " + statusLine);
   
  -        StringTokenizer st = new StringTokenizer(statusLine);
  +        int at = statusLine.indexOf(" ");
  +        if (at < 0)
  +            throw new WebdavException
  +                ("Error in parsing the response: " + statusLine);
  +
  +        String protocol = statusLine.substring(0, at);
  +        if ((!protocol.equals("HTTP/1.1") && !protocol.equals("HTTP/1.0")))
  +            throw new WebdavException
  +                ("Incorrect server protocol : " + protocol);
   
  -     String protocol = null;
  -     try {
  -         protocol = st.nextToken();
  -     } catch (NoSuchElementException e) {
  -     }
  -        if ((protocol == null) ||
  -            (!protocol.equals("HTTP/1.1") && !protocol.equals("HTTP/1.0")))
  -            throw new WebdavException("Incorrect server protocol : "
  -                                      + protocol);
           if (protocol.equals("HTTP/1.1")) {
               http11 = true;
           } else {
  @@ -677,23 +677,31 @@
           }
   
           int statusCode = -1;
  +
  +        int to = statusLine.indexOf(" ", at + 1);
  +        if (to < 0)
  +            throw new WebdavException
  +                ("Status not specified: " + statusLine);
           try {
  -            statusCode = Integer.parseInt(st.nextToken());
  -        } catch (Exception e) {
  +            statusCode = Integer.parseInt(statusLine.substring(at+1, to));
  +        } catch (NumberFormatException e) {
  +            throw new WebdavException
  +                ("Status not specified: " + statusLine);
           }
  -        if (statusCode == -1)
  -            throw new WebdavException("Status not specified");
   
           method.setStatusCode(statusCode);
   
  +
           String statusText = null;
  -     try {
  -         statusText = st.nextToken();
  -     } catch (NoSuchElementException e) {
  -     }
  +        try {
  +            statusText = statusLine.substring(to + 1);
  +        } catch (StringIndexOutOfBoundsException e) {
  +            throw new WebdavException
  +                ("Status not specified: " + statusLine);
  +        }
  +
           if (statusText != null)
               method.setStatusText(statusText);
  -
       }
   
   
  
  
  

Reply via email to