You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@locus.apache.org on 2000/11/27 23:56:14 UTC

cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods GetMethod.java HeadMethod.java WebdavMethod.java WebdavMethodBase.java

remm        00/11/27 14:56:12

  Modified:    src/webdav/client/src/org/apache/webdav/lib
                        WebdavClient.java
               src/webdav/client/src/org/apache/webdav/lib/methods
                        GetMethod.java HeadMethod.java WebdavMethod.java
                        WebdavMethodBase.java
  Log:
  - Automatically redirects if a 302 status code is recieved for some methods
    (GET and HEAD only for now).
  
  Revision  Changes    Path
  1.2       +44 -17    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WebdavClient.java	2000/11/22 06:19:08	1.1
  +++ WebdavClient.java	2000/11/27 22:55:51	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java,v 1.1 2000/11/22 06:19:08 remm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/11/22 06:19:08 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java,v 1.2 2000/11/27 22:55:51 remm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/11/27 22:55:51 $
    *
    * ====================================================================
    *
  @@ -181,15 +181,18 @@
       public void executeMethod(WebdavMethod method) 
           throws IOException, WebdavException {
           
  -        int authRetries = 0;
  +        int retries = 0;
           
           Hashtable responseHeaders = null;
           
           openConnection();
           
  -        while ( (authRetries == 0) || 
  -                ((method.getStatusCode() == WebdavStatus.SC_UNAUTHORIZED)
  -                 && (authRetries < 3)) ) {
  +        while ( (retries == 0) 
  +                || ((method.getStatusCode() == WebdavStatus.SC_UNAUTHORIZED)
  +                    && (retries < 3)) 
  +                || ((method.getStatusCode() 
  +                     == WebdavStatus.SC_MOVED_TEMPORARILY)
  +                    && (retries < 3)) ) {
               
               sendRequest(method);
               
  @@ -201,21 +204,45 @@
               // Parse headers
               responseHeaders = parseHeaders(input);
               
  -            // Retrieve the authenticate challenge, if any 
  -            // (needed in case of a digest challenge, for which the header is 
  -            // not constant)
  -            Header authenticateChallenge = 
  -                (Header) responseHeaders.get("www-authenticate");
  -            if (authenticateChallenge != null) {
  -                state.setAuthenticateToken(authenticateChallenge.getValue());
  +            if (method.getStatusCode() == WebdavStatus.SC_UNAUTHORIZED) {
  +                // Retrieve the authenticate challenge, if any 
  +                // (needed in case of a digest challenge, for which the header
  +                // is not constant)
  +                Header authenticateChallenge = 
  +                    (Header) responseHeaders.get("www-authenticate");
  +                if (authenticateChallenge != null) {
  +                    state.setAuthenticateToken
  +                        (authenticateChallenge.getValue());
  +                }
  +            } else if ((method.getStatusCode() 
  +                        == WebdavStatus.SC_MOVED_TEMPORARILY) 
  +                       && (method.followRedirects())) {
  +                // Retrieve the location header
  +                // NOTE : Redirects across servers are not supported yet
  +                Header location = 
  +                    (Header) responseHeaders.get("location");
  +                if (location != null) {
  +                    String absolutePath = location.getValue();
  +                    if (absolutePath.startsWith("http://")) {
  +                        absolutePath = absolutePath.substring(7);
  +                    }
  +                    int slash = absolutePath.indexOf('/');
  +                    if (slash != -1) {
  +                        absolutePath = absolutePath.substring(slash);
  +                    }
  +                    if (absolutePath.equals("")) {
  +                        absolutePath = "/";
  +                    }
  +                    method.setPath(absolutePath);
  +                }
               }
               
  -            authRetries++;
  +            retries++;
               
           }
           
  -        if (authRetries == 3) {
  -            throw new WebdavException("Unable to authenticate");
  +        if (retries == 3) {
  +            throw new WebdavException("Unable to process request");
           }
           
           method.processResponseHeaders(responseHeaders);
  
  
  
  1.2       +13 -3     jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/GetMethod.java
  
  Index: GetMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/GetMethod.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GetMethod.java	2000/11/22 06:19:09	1.1
  +++ GetMethod.java	2000/11/27 22:55:56	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/GetMethod.java,v 1.1 2000/11/22 06:19:09 remm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/11/22 06:19:09 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/GetMethod.java,v 1.2 2000/11/27 22:55:56 remm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/11/27 22:55:56 $
    *
    * ====================================================================
    *
  @@ -142,6 +142,16 @@
        */
       public boolean getUseDisk() {
           return useDisk;
  +    }
  +    
  +    
  +    /**
  +     * True if this methods should automatically follow redirects.
  +     * 
  +     * @return boolean True if auto redirect should be used for this method
  +     */
  +    public boolean followRedirects() {
  +        return (true);
       }
       
       
  
  
  
  1.2       +16 -3     jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/HeadMethod.java
  
  Index: HeadMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/HeadMethod.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HeadMethod.java	2000/11/22 06:19:09	1.1
  +++ HeadMethod.java	2000/11/27 22:55:58	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/HeadMethod.java,v 1.1 2000/11/22 06:19:09 remm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/11/22 06:19:09 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/HeadMethod.java,v 1.2 2000/11/27 22:55:58 remm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/11/27 22:55:58 $
    *
    * ====================================================================
    *
  @@ -89,6 +89,19 @@
           
           name = "HEAD";
           
  +    }
  +    
  +    
  +    // ------------------------------------------------------------- Properties
  +    
  +    
  +    /**
  +     * True if this methods should automatically follow redirects.
  +     * 
  +     * @return boolean True if auto redirect should be used for this method
  +     */
  +    public boolean followRedirects() {
  +        return (true);
       }
       
       
  
  
  
  1.2       +11 -3     jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/WebdavMethod.java
  
  Index: WebdavMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/WebdavMethod.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WebdavMethod.java	2000/11/22 06:19:09	1.1
  +++ WebdavMethod.java	2000/11/27 22:56:00	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/WebdavMethod.java,v 1.1 2000/11/22 06:19:09 remm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/11/22 06:19:09 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/WebdavMethod.java,v 1.2 2000/11/27 22:56:00 remm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/11/27 22:56:00 $
    *
    * ====================================================================
    *
  @@ -183,6 +183,14 @@
        * @return boolean True if the method's instance has already been used
        */
       public boolean hasBeenUsed();
  +    
  +    
  +    /**
  +     * True if this methods should automatically follow redirects.
  +     * 
  +     * @return boolean True if auto redirect should be used for this method
  +     */
  +    public boolean followRedirects();
       
       
       // ------------------------------------------------------ Interface Methods
  
  
  
  1.2       +13 -3     jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/WebdavMethodBase.java
  
  Index: WebdavMethodBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/WebdavMethodBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WebdavMethodBase.java	2000/11/22 06:19:09	1.1
  +++ WebdavMethodBase.java	2000/11/27 22:56:02	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/WebdavMethodBase.java,v 1.1 2000/11/22 06:19:09 remm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/11/22 06:19:09 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/WebdavMethodBase.java,v 1.2 2000/11/27 22:56:02 remm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/11/27 22:56:02 $
    *
    * ====================================================================
    *
  @@ -257,6 +257,16 @@
        */
       public final boolean hasBeenUsed() {
           return (used);
  +    }
  +    
  +    
  +    /**
  +     * True if this methods should automatically follow redirects.
  +     * 
  +     * @return boolean True if auto redirect should be used for this method
  +     */
  +    public boolean followRedirects() {
  +        return (false);
       }
       
       
  
  
  

Re: cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods GetMethod.java HeadMethod.java WebdavMethod.java WebdavMethodBase.java

Posted by "B.C. Holmes" <bc...@roxton.com>.
remm@locus.apache.org wrote:
> 
>   - Automatically redirects if a 302 status code is recieved for some methods
>     (GET and HEAD only for now).

     <nod>  I'm guessing that we want to do this for all idempotent
methods.

BCing you
-- 
B.C. Holmes         \u2625           http://www.roxton.com/~bcholmes/
"Wherefore now, baby, time will tell/I chose my roads and I chose 
 them well/But will I go forth, or just go to hell/For I am a 
 terrible man."
         - Jory Nash, _Terrible Man_