remm        00/11/08 23:22:24

  Modified:    catalina/src/share/org/apache/catalina/servlets
                        DefaultServlet.java WebdavServlet.java
  Log:
  - Add a debug method in the DefaultServlet, which will output to System.out
    all the info about the request. It should be useful to debug conditional
    requests and ranged requests.
  - In the WebDAV servlet, one of the XMLWriters I was using wasn't
    properly initialized. As a result, the XML header wasn't present in the
    XML sent back to the client, which may have caused various problems with some
    clients.
  - Now use ISO date format for the creationdate property.
  - Fixes one or two cosmetic issues in the code layout.
  - The displayname property now have a more "friendly" value (the '/' are
    replaced by '_')
  - The JSP include fix intrduced a bug : The response stream was not opened at
    the right time, so chunking was enabled all the time (it seems).
    Note : We should decide if we chunk or not in a more robust way. It will be
    addressed in a future patch.
  
  Revision  Changes    Path
  1.12      +141 -23   
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java
  
  Index: DefaultServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultServlet.java       2000/10/17 19:45:27     1.11
  +++ DefaultServlet.java       2000/11/09 07:22:22     1.12
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java,v
 1.11 2000/10/17 19:45:27 craigmcc Exp $
  - * $Revision: 1.11 $
  - * $Date: 2000/10/17 19:45:27 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java,v
 1.12 2000/11/09 07:22:22 remm Exp $
  + * $Revision: 1.12 $
  + * $Date: 2000/11/09 07:22:22 $
    *
    * ====================================================================
    *
  @@ -112,7 +112,7 @@
    *
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.11 $ $Date: 2000/10/17 19:45:27 $
  + * @version $Revision: 1.12 $ $Date: 2000/11/09 07:22:22 $
    */
   
   public class DefaultServlet
  @@ -280,6 +280,93 @@
   
   
       /**
  +     * Show HTTP header information.
  +     */
  +    protected void showRequestInfo(HttpServletRequest req) {
  +     
  +     System.out.println();
  +     System.out.println("SlideDAV Request Info");
  +     System.out.println();
  +     
  +     // Show generic info
  +     System.out.println("Encoding : " + req.getCharacterEncoding());
  +     System.out.println("Length : " + req.getContentLength());
  +     System.out.println("Type : " + req.getContentType());
  +     
  +     System.out.println();
  +     System.out.println("Parameters");
  +     
  +     Enumeration parameters = req.getParameterNames();
  +     
  +     while (parameters.hasMoreElements()) {
  +         String paramName = (String) parameters.nextElement();
  +         String[] values = req.getParameterValues(paramName);
  +         System.out.print(paramName + " : ");
  +         for (int i = 0; i < values.length; i++) {
  +             System.out.print(values[i] + ", ");
  +         }
  +         System.out.println();
  +     }
  +     
  +     System.out.println();
  +     
  +     System.out.println("Protocol : " + req.getProtocol());
  +     System.out.println("Address : " + req.getRemoteAddr());
  +     System.out.println("Host : " + req.getRemoteHost());
  +     System.out.println("Scheme : " + req.getScheme());
  +     System.out.println("Server Name : " + req.getServerName());
  +     System.out.println("Server Port : " + req.getServerPort());
  +     
  +     System.out.println();
  +     System.out.println("Attributes");
  +     
  +     Enumeration attributes = req.getAttributeNames();
  +     
  +     while (attributes.hasMoreElements()) {
  +         String attributeName = (String) attributes.nextElement();
  +         System.out.print(attributeName + " : ");
  +         System.out.println(req.getAttribute(attributeName).toString());
  +     }
  +     
  +     System.out.println();
  +     
  +     // Show HTTP info
  +     System.out.println();
  +     System.out.println("HTTP Header Info");
  +     System.out.println();
  +     
  +     System.out.println("Authentication Type : " + req.getAuthType());
  +     System.out.println("HTTP Method : " + req.getMethod());
  +     System.out.println("Path Info : " + req.getPathInfo());
  +     System.out.println("Path translated : " + req.getPathTranslated());
  +     System.out.println("Query string : " + req.getQueryString());
  +     System.out.println("Remote user : " + req.getRemoteUser());
  +     System.out.println("Requested session id : " 
  +                           + req.getRequestedSessionId());
  +     System.out.println("Request URI : " + req.getRequestURI());
  +     System.out.println("Context path : " + req.getContextPath());
  +        System.out.println("Servlet path : " + req.getServletPath());
  +        System.out.println("User principal : " + req.getUserPrincipal());
  +        
  +     
  +     System.out.println();
  +     System.out.println("Headers : ");
  +     
  +     Enumeration headers = req.getHeaderNames();
  +     
  +     while (headers.hasMoreElements()) {
  +         String headerName = (String) headers.nextElement();
  +         System.out.print(headerName + " : ");
  +         System.out.println(req.getHeader(headerName));
  +     }
  +     
  +     System.out.println();
  +     System.out.println();
  +     
  +    }
  +
  +
  +    /**
        * Return the relative path associated with this servlet.
        *
        * @param request The servlet request we are processing
  @@ -324,6 +411,9 @@
                            HttpServletResponse response)
        throws IOException, ServletException {
   
  +        if (debug > 999)
  +            showRequestInfo(request);
  +
        // Serve the requested resource, including the data content
        serveResource(request, response, true);
   
  @@ -1226,25 +1316,6 @@
           ServletOutputStream ostream = null;
           PrintWriter writer = null;
           
  -        if (content) {
  -            
  -            // Trying to retrieve the servlet output stream
  -            
  -            try {
  -                ostream = response.getOutputStream();
  -            } catch (IllegalStateException e) {
  -                // If it fails, we try to get a Writer instead if we're 
  -                // trying to serve a text file
  -                if ( (contentType != null) 
  -                     && (contentType.startsWith("text")) ) {
  -                    writer = response.getWriter();
  -                } else {
  -                    throw e;
  -                }
  -            }
  -            
  -        }
  -        
           if ( ((ranges == null) || (ranges.isEmpty())) 
                && (request.getHeader("Range") == null) ) {
               
  @@ -1263,6 +1334,21 @@
                   response.setContentLength((int) contentLength);
               }
               
  +            // Trying to retrieve the servlet output stream
  +            
  +            try {
  +                ostream = response.getOutputStream();
  +            } catch (IllegalStateException e) {
  +                // If it fails, we try to get a Writer instead if we're 
  +                // trying to serve a text file
  +                if ( (contentType != null) 
  +                     && (contentType.startsWith("text")) ) {
  +                    writer = response.getWriter();
  +                } else {
  +                    throw e;
  +                }
  +            }
  +
               // Copy the input stream to our output stream (if requested)
               if (content) {
                   response.setBufferSize(output);
  @@ -1299,6 +1385,22 @@
                   
                   if (content) {
                       response.setBufferSize(output);
  +
  +                    // Trying to retrieve the servlet output stream
  +                    
  +                    try {
  +                        ostream = response.getOutputStream();
  +                    } catch (IllegalStateException e) {
  +                        // If it fails, we try to get a Writer instead if 
  +                        // we're trying to serve a text file
  +                        if ( (contentType != null) 
  +                             && (contentType.startsWith("text")) ) {
  +                            writer = response.getWriter();
  +                        } else {
  +                            throw e;
  +                        }
  +                    }
  +                    
                       if (ostream != null) {
                           copy(resourceInfo, ostream, range);
                       } else {
  @@ -1313,6 +1415,22 @@
                   
                   if (content) {
                       response.setBufferSize(output);
  +                    
  +                    // Trying to retrieve the servlet output stream
  +                    
  +                    try {
  +                        ostream = response.getOutputStream();
  +                    } catch (IllegalStateException e) {
  +                        // If it fails, we try to get a Writer instead if 
  +                        // we're trying to serve a text file
  +                        if ( (contentType != null) 
  +                             && (contentType.startsWith("text")) ) {
  +                            writer = response.getWriter();
  +                        } else {
  +                            throw e;
  +                        }
  +                    }
  +                    
                       if (ostream != null) {
                           copy(resourceInfo, ostream, ranges.elements(), 
                                contentType);
  
  
  
  1.5       +95 -37    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java
  
  Index: WebdavServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- WebdavServlet.java        2000/10/10 17:21:41     1.4
  +++ WebdavServlet.java        2000/11/09 07:22:22     1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java,v
 1.4 2000/10/10 17:21:41 remm Exp $
  - * $Revision: 1.4 $
  - * $Date: 2000/10/10 17:21:41 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java,v
 1.5 2000/11/09 07:22:22 remm Exp $
  + * $Revision: 1.5 $
  + * $Date: 2000/11/09 07:22:22 $
    *
    * ====================================================================
    *
  @@ -83,6 +83,7 @@
   import java.util.StringTokenizer;
   import java.util.Locale;
   import java.util.Hashtable;
  +import java.util.Calendar;
   import java.text.ParseException;
   import java.text.SimpleDateFormat;
   import java.security.MessageDigest;
  @@ -120,7 +121,7 @@
    * are handled by the DefaultServlet.
    *
    * @author Remy Maucherat
  - * @version $Revision: 1.4 $ $Date: 2000/10/10 17:21:41 $
  + * @version $Revision: 1.5 $ $Date: 2000/11/09 07:22:22 $
    */
   
   public class WebdavServlet
  @@ -194,6 +195,13 @@
       protected static final String DEFAULT_NAMESPACE = "DAV:";
       
       
  +    /**
  +     * Simple date format for the creation date ISO representation (partial).
  +     */
  +    protected static final SimpleDateFormat creationDateFormat = 
  +        new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
  +
  +
       // ----------------------------------------------------- Instance Variables
   
   
  @@ -473,6 +481,7 @@
   
           // Create multistatus object
           XMLWriter generatedXML = new XMLWriter();
  +        generatedXML.writeXMLHeader();
           
           generatedXML.writeElement(null, "multistatus" 
                                     + generateNamespaceDeclarations(), 
  @@ -1735,16 +1744,17 @@
               generatedXML.writeElement(null, "propstat", XMLWriter.OPENING);
               generatedXML.writeElement(null, "prop", XMLWriter.OPENING);
               
  -            generatedXML.writeProperty(null, "creationdate", 
  -                                       formats[0].format(new Date
  -                                           (resourceInfo.creationDate)));
  -            generatedXML.writeProperty(null, "displayname", resourceInfo.path);
  +            generatedXML.writeProperty
  +                (null, "creationdate", 
  +                 getISOCreationDate(resourceInfo.creationDate));
  +            generatedXML.writeProperty(null, "displayname", 
  +                                       resourceInfo.path.replace('/', '_'));
               generatedXML.writeProperty(null, "getcontentlanguage", 
                                          Locale.getDefault().toString());
  -            generatedXML.writeProperty(null, "getlastmodified", 
  -                                       resourceInfo.httpDate);
               if (!resourceInfo.collection) {
                   generatedXML.writeProperty
  +                    (null, "getlastmodified", resourceInfo.httpDate);
  +                generatedXML.writeProperty
                       (null, "getcontentlength", 
                        String.valueOf(resourceInfo.length));
                   generatedXML.writeProperty
  @@ -1832,11 +1842,12 @@
                   
                   if (property.equals("creationdate")) {
                       generatedXML.writeProperty
  -                        (null, "creationdate", formats[0].format
  -                         (new Date(resourceInfo.creationDate)));
  +                        (null, "creationdate", 
  +                         getISOCreationDate(resourceInfo.creationDate));
                   } else if (property.equals("displayname")) {
  -                    generatedXML.writeProperty(null, "displayname", 
  -                                               resourceInfo.path);
  +                    generatedXML.writeProperty
  +                        (null, "displayname", 
  +                         resourceInfo.path.replace('/', '_'));
                   } else if (property.equals("getcontentlanguage")) {
                       if (resourceInfo.collection) {
                           propertiesNotFound.addElement(property);
  @@ -1874,9 +1885,8 @@
                       if (resourceInfo.collection) {
                           propertiesNotFound.addElement(property);
                       } else {
  -                        generatedXML.writeProperty(null, 
  -                                                   "getlastmodified", 
  -                                                   resourceInfo.httpDate);
  +                        generatedXML.writeProperty
  +                            (null, "getlastmodified", resourceInfo.httpDate);
                       }
                   } else if (property.equals("resourcetype")) {
                       if (resourceInfo.collection) {
  @@ -1903,7 +1913,8 @@
                       generatedXML.writeProperty(null, "supportedlock",
                                                  supportedLocks);
                   } else if (property.equals("lockdiscovery")) {
  -                    generateLockDiscovery(path, generatedXML);
  +                    if (!generateLockDiscovery(path, generatedXML))
  +                        propertiesNotFound.addElement(property);
                   } else {
                       propertiesNotFound.addElement(property);
                   }
  @@ -1998,9 +2009,11 @@
               generatedXML.writeElement(null, "propstat", XMLWriter.OPENING);
               generatedXML.writeElement(null, "prop", XMLWriter.OPENING);
               
  -            generatedXML.writeProperty(null, "creationdate", 
  -                                       formats[0].format(lock.creationDate));
  -            generatedXML.writeProperty(null, "displayname", path);
  +            generatedXML.writeProperty
  +                (null, "creationdate", 
  +                 getISOCreationDate(lock.creationDate.getTime()));
  +            generatedXML.writeProperty(null, "displayname", 
  +                                       path.replace('/', '_'));
               generatedXML.writeProperty(null, "getcontentlanguage", 
                                          Locale.getDefault().toString());
               generatedXML.writeProperty(null, "getlastmodified", 
  @@ -2085,9 +2098,10 @@
                   if (property.equals("creationdate")) {
                       generatedXML.writeProperty
                           (null, "creationdate", 
  -                         formats[0].format(lock.creationDate));
  +                         getISOCreationDate(lock.creationDate.getTime()));
                   } else if (property.equals("displayname")) {
  -                    generatedXML.writeProperty(null, "displayname", path);
  +                    generatedXML.writeProperty(null, "displayname", 
  +                                               path.replace('/', '_'));
                   } else if (property.equals("getcontentlanguage")) {
                       generatedXML.writeProperty
                           (null, "getcontentlanguage", 
  @@ -2124,7 +2138,8 @@
                       generatedXML.writeProperty(null, "supportedlock",
                                                  supportedLocks);
                   } else if (property.equals("lockdiscovery")) {
  -                    generateLockDiscovery(path, generatedXML);
  +                    if (!generateLockDiscovery(path, generatedXML))
  +                        propertiesNotFound.addElement(property);
                   } else {
                       propertiesNotFound.addElement(property);
                   }
  @@ -2172,28 +2187,71 @@
        * 
        * @param path Path
        * @param generatedXML XML data to which the locks info will be appended
  +     * @return true if at least one lock was displayed
        */
  -    private void generateLockDiscovery(String path, XMLWriter generatedXML) {
  -        
  -        generatedXML.writeElement(null, "lockdiscovery", 
  -                                  XMLWriter.OPENING);
  -        
  +    private boolean generateLockDiscovery
  +        (String path, XMLWriter generatedXML) {
  +
           LockInfo resourceLock = (LockInfo) resourceLocks.get(path);
  +        Enumeration collectionLocksList = collectionLocks.elements();
  +
  +        boolean wroteStart = false;
  +
           if (resourceLock != null) {
  +            wroteStart = true;
  +            generatedXML.writeElement(null, "lockdiscovery", 
  +                                      XMLWriter.OPENING);
               resourceLock.toXML(generatedXML);
           }
           
  -        Enumeration collectionLocksList = collectionLocks.elements();
           while (collectionLocksList.hasMoreElements()) {
  -            LockInfo currentLock = (LockInfo) collectionLocksList.nextElement();
  +            LockInfo currentLock = 
  +                (LockInfo) collectionLocksList.nextElement();
               if (path.startsWith(currentLock.path)) {
  +                if (!wroteStart) {
  +                    wroteStart = true;
  +                    generatedXML.writeElement(null, "lockdiscovery", 
  +                                              XMLWriter.OPENING);
  +                }
                   currentLock.toXML(generatedXML);
               }
           }
           
  -        generatedXML.writeElement(null, "lockdiscovery", 
  -                                  XMLWriter.CLOSING);
  -        
  +        if (wroteStart) {
  +            generatedXML.writeElement(null, "lockdiscovery", 
  +                                      XMLWriter.CLOSING);
  +        } else {
  +            return false;
  +        }
  +
  +        return true;
  +
  +    }
  +
  +    
  +    /**
  +     * Get creation date in ISO format.
  +     */
  +    private String getISOCreationDate(long creationDate) {
  +        StringBuffer creationDateValue = new StringBuffer
  +            (creationDateFormat.format
  +             (new Date(creationDate)));
  +        int offset = Calendar.getInstance().getTimeZone().getRawOffset()
  +            / 3600000; // FIXME ?
  +        if (offset < 0) {
  +            creationDateValue.append("-");
  +            offset = -offset;
  +        } else if (offset > 0) {
  +            creationDateValue.append("+");
  +        }
  +        if (offset != 0) {
  +            if (offset < 10)
  +                creationDateValue.append("0");
  +            creationDateValue.append(offset + ":00");
  +        } else {
  +            creationDateValue.append("Z");
  +        }
  +        return creationDateValue.toString();
       }
   
   
  @@ -2206,7 +2264,7 @@
       private class LockInfo {
   
   
  -        // --------------------------------------------------------- Constructor
  +        // -------------------------------------------------------- Constructor
   
   
           /**
  @@ -2219,7 +2277,7 @@
           }
   
   
  -        // -------------------------------------------------- Instance Variables
  +        // ------------------------------------------------- Instance Variables
   
   
           String path = "/";
  @@ -2232,7 +2290,7 @@
           Date creationDate = new Date();
           
           
  -        // ------------------------------------------------------ Public Methods
  +        // ----------------------------------------------------- Public Methods
   
   
           /**
  
  
  

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

Reply via email to