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 oz...@apache.org on 2004/10/30 10:45:21 UTC

cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method GetMethod.java

ozeigermann    2004/10/30 01:45:21

  Modified:    src/webdav/server/org/apache/slide/webdav WebdavServlet.java
               src/webdav/server/org/apache/slide/webdav/util
                        DirectoryIndexGenerator.java
               src/webdav/server/org/apache/slide/webdav/method
                        GetMethod.java
  Log:
  Moved check and display of collections as HTML pages
  into the GET method to assure all access is done from inside transactions
  and then inside THE SAME transaction per request.
  
  Revision  Changes    Path
  1.65      +53 -63    jakarta-slide/src/webdav/server/org/apache/slide/webdav/WebdavServlet.java
  
  Index: WebdavServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/WebdavServlet.java,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- WebdavServlet.java	29 Oct 2004 14:41:12 -0000	1.64
  +++ WebdavServlet.java	30 Oct 2004 08:45:21 -0000	1.65
  @@ -63,7 +63,6 @@
    */
   public class WebdavServlet extends HttpServlet {
       
  -    
       // -------------------------------------------------------------- Constants
       
       
  @@ -149,20 +148,11 @@
               resp.setStatus(WebdavStatus.SC_OK);
               
               String methodName = req.getMethod();
  -            if (!isExtTx(req) && 
  -                (methodName.equalsIgnoreCase("GET") || methodName.equalsIgnoreCase("POST")) &&
  -                isCollection(req)) {
  -                // let the standard doGet() / doPost() methods handle
  -                // GET/POST requests on collections (to display a directory
  -                // index pag or something similar)
  -                super.service(req, resp);
  +            WebdavMethod method = methodFactory.createMethod(methodName);
  +            if (method == null) {
  +                throw new WebdavException(WebdavStatus.SC_METHOD_NOT_ALLOWED);
               } else {
  -                WebdavMethod method = methodFactory.createMethod(methodName);
  -                if (method == null) {
  -                    throw new WebdavException(WebdavStatus.SC_METHOD_NOT_ALLOWED);
  -                } else {
  -                    method.run(req, resp);
  -                }
  +                method.run(req, resp);
               }
           } catch (WebdavException e) {
               // There has been an error somewhere ...
  @@ -299,23 +289,23 @@
           
           // Check whether directory browsing is enabled, and how it should be
           // accomplished
  -        value = getInitParameter("directory-browsing");
  -        if (value != null) {
  -            if (value.startsWith("/")) {
  -                directoryBrowsingTemplate =
  -                    getServletContext().getRequestDispatcher(value);
  -                if (directoryBrowsingTemplate == null) {
  -                    directoryBrowsing = false;
  -                }
  -            } else {
  -                directoryBrowsing = Boolean.valueOf(value).booleanValue();
  -            }
  -        }
  -        if (directoryBrowsing) {
  -            directoryIndexGenerator =
  -                new DirectoryIndexGenerator
  -                (token, (WebdavServletConfig)getServletConfig());
  -        }
  +//        value = getInitParameter("directory-browsing");
  +//        if (value != null) {
  +//            if (value.startsWith("/")) {
  +//                directoryBrowsingTemplate =
  +//                    getServletContext().getRequestDispatcher(value);
  +//                if (directoryBrowsingTemplate == null) {
  +//                    directoryBrowsing = false;
  +//                }
  +//            } else {
  +//                directoryBrowsing = Boolean.valueOf(value).booleanValue();
  +//            }
  +//        }
  +//        if (directoryBrowsing) {
  +//            directoryIndexGenerator =
  +//                new DirectoryIndexGenerator
  +//                (token, (WebdavServletConfig)getServletConfig());
  +//        }
       }
       
       
  @@ -339,34 +329,34 @@
       /**
        * Handle a GET request on a collection resource.
        */
  -    protected void doGet(HttpServletRequest req, HttpServletResponse res)
  -        throws ServletException, IOException {
  -        
  -        if (directoryBrowsing) {
  -            if (directoryBrowsingTemplate != null) {
  -                // attributes used by the tag library
  -                req.setAttribute("org.apache.slide.NamespaceName",
  -                                 token.getName());
  -                // attributes for general use
  -                req.setAttribute("slide_namespace", token.getName());
  -                directoryBrowsingTemplate.forward(req, res);
  -            } else {
  -                try {
  -                    directoryIndexGenerator.generate(req, res);
  -                } catch (AccessDeniedException e) {
  -                    res.sendError(WebdavStatus.SC_FORBIDDEN);
  -                } catch (ObjectNotFoundException e) {
  -                    res.sendError(WebdavStatus.SC_NOT_FOUND);
  -                } catch (LinkedObjectNotFoundException e) {
  -                    res.sendError(WebdavStatus.SC_NOT_FOUND);
  -                } catch (SlideException e) {
  -                    res.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  -                }
  -            }
  -        } else {
  -            res.sendError(WebdavStatus.SC_FORBIDDEN);
  -        }
  -    }
  +//    protected void doGet(HttpServletRequest req, HttpServletResponse res)
  +//        throws ServletException, IOException {
  +//        
  +//        if (directoryBrowsing) {
  +//            if (directoryBrowsingTemplate != null) {
  +//                // attributes used by the tag library
  +//                req.setAttribute("org.apache.slide.NamespaceName",
  +//                                 token.getName());
  +//                // attributes for general use
  +//                req.setAttribute("slide_namespace", token.getName());
  +//                directoryBrowsingTemplate.forward(req, res);
  +//            } else {
  +//                try {
  +//                    directoryIndexGenerator.generate(req, res);
  +//                } catch (AccessDeniedException e) {
  +//                    res.sendError(WebdavStatus.SC_FORBIDDEN);
  +//                } catch (ObjectNotFoundException e) {
  +//                    res.sendError(WebdavStatus.SC_NOT_FOUND);
  +//                } catch (LinkedObjectNotFoundException e) {
  +//                    res.sendError(WebdavStatus.SC_NOT_FOUND);
  +//                } catch (SlideException e) {
  +//                    res.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +//                }
  +//            }
  +//        } else {
  +//            res.sendError(WebdavStatus.SC_FORBIDDEN);
  +//        }
  +//    }
       
       static boolean isDomLevel2Parser() {
           try {
  
  
  
  1.10      +6 -6      jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/DirectoryIndexGenerator.java
  
  Index: DirectoryIndexGenerator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/DirectoryIndexGenerator.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DirectoryIndexGenerator.java	20 Aug 2004 16:22:05 -0000	1.9
  +++ DirectoryIndexGenerator.java	30 Oct 2004 08:45:21 -0000	1.10
  @@ -139,7 +139,7 @@
        *                          response
        * @throw SlideException    if an exception occurrs accessing Slide
        */
  -    public void generate(HttpServletRequest req, HttpServletResponse res)
  +    public void generate(HttpServletRequest req, HttpServletResponse res, SlideToken slideToken)
           throws IOException, SlideException {
           
           res.setContentType("text/html; charset=\"UTF-8\"");
  @@ -150,7 +150,7 @@
           Security security = nat.getSecurityHelper();
           Structure structure = nat.getStructureHelper();
           
  -        SlideToken slideToken = WebdavUtils.getSlideToken(req);
  +//        SlideToken slideToken = WebdavUtils.getSlideToken(req);
           String resourcePath = WebdavUtils.getRelativePath(req, config);
           ObjectNode object = structure.retrieve(slideToken, resourcePath);
           String name = object.getUri();
  
  
  
  1.54      +105 -70   jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/GetMethod.java
  
  Index: GetMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/GetMethod.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- GetMethod.java	25 Oct 2004 21:13:28 -0000	1.53
  +++ GetMethod.java	30 Oct 2004 08:45:21 -0000	1.54
  @@ -44,12 +44,15 @@
   import org.apache.slide.content.RevisionDescriptorNotFoundException;
   import org.apache.slide.content.RevisionNotFoundException;
   import org.apache.slide.event.EventDispatcher;
  +import org.apache.slide.security.AccessDeniedException;
   import org.apache.slide.structure.LinkedObjectNotFoundException;
  +import org.apache.slide.structure.ObjectNotFoundException;
   import org.apache.slide.util.Configuration;
   import org.apache.slide.webdav.WebdavException;
   import org.apache.slide.webdav.WebdavServletConfig;
   import org.apache.slide.webdav.event.WebdavEvent;
   import org.apache.slide.webdav.util.DeltavConstants;
  +import org.apache.slide.webdav.util.DirectoryIndexGenerator;
   import org.apache.slide.webdav.util.LabeledRevisionNotFoundException;
   import org.apache.slide.webdav.util.PreconditionViolationException;
   import org.apache.slide.webdav.util.VersioningHelper;
  @@ -132,6 +135,28 @@
       // ------------------------------------------------------ Protected Methods
   
   
  +    protected void displayDirectory() throws IOException {
  +        String directoryBrowsing = config.getInitParameter( "directory-browsing" );
  +        if( "true".equalsIgnoreCase(directoryBrowsing) ) {
  +                try {
  +                    DirectoryIndexGenerator directoryIndexGenerator =
  +                        new DirectoryIndexGenerator
  +                        (token, config);
  +                    directoryIndexGenerator.generate(req, resp, slideToken);
  +                } catch (AccessDeniedException e) {
  +                    resp.sendError(WebdavStatus.SC_FORBIDDEN);
  +                } catch (ObjectNotFoundException e) {
  +                    resp.sendError(WebdavStatus.SC_NOT_FOUND);
  +                } catch (LinkedObjectNotFoundException e) {
  +                    resp.sendError(WebdavStatus.SC_NOT_FOUND);
  +                } catch (SlideException e) {
  +                    resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                }
  +        } else {
  +            resp.sendError(WebdavStatus.SC_FORBIDDEN);
  +        }
  +    }
  +
       /**
        * Parse XML request.
        */
  @@ -170,7 +195,6 @@
   
       }
   
  -
       /**
        * Execute request.
        *
  @@ -211,86 +235,97 @@
   
                   if (revisionDescriptor != null) {
   
  -                    ResourceInfo resourceInfo =
  -                        new ResourceInfo(resourcePath, revisionDescriptor);
  -
  -                    // Checking If headers
  -                    if (!checkIfHeaders(req, resp, resourceInfo))
  -                        return;
  -
  -                    ServletOutputStream os = resp.getOutputStream();
  -                    InputStream         is = null;
  -
  -                    if (printContent) {
  -                        is = content.retrieve
  -                            (slideToken, revisionDescriptors,
  -                             revisionDescriptor).streamContent();
  -                    }
  -
  -                    Vector ranges = parseRange(req, resp, resourceInfo);
  -
  -                    // ETag header (tag must be quoted)
  -                    resp.setHeader("ETag", getETag(resourceInfo, true) );
  -                    resp.setHeader
  -                        ("Content-Language", revisionDescriptor.getContentLanguage());
  -                    resp.addHeader
  -                        ("Last-Modified",
  -                         revisionDescriptor.getLastModified().toString());
  -
  -                    if ( ((ranges == null) || (ranges.isEmpty())) ) {
  -                        // full content response
  -                        resp.setContentType
  -                            (revisionDescriptor.getContentType());
  -                        resp.setContentLength
  -                            ((int) revisionDescriptor.getContentLength());
  -
  -                        // Copy the input stream to our output stream
  -                        // (if requested)
  +                    if (revisionDescriptor.propertyValueContains(
  +                            NodeRevisionDescriptor.RESOURCE_TYPE,
  +                            NodeRevisionDescriptor.COLLECTION_TYPE)) {
  +                        displayDirectory();
  +                    } else {
  +                    
  +                        ResourceInfo resourceInfo =
  +                            new ResourceInfo(resourcePath, revisionDescriptor);
  +    
  +                        // Checking If headers
  +                        if (!checkIfHeaders(req, resp, resourceInfo))
  +                            return;
  +    
  +                        ServletOutputStream os = resp.getOutputStream();
  +                        InputStream         is = null;
  +    
                           if (printContent) {
  -                            resp.setBufferSize(output);
  -                            copy(resourceInfo, is, os);
  +                            is = content.retrieve
  +                                (slideToken, revisionDescriptors,
  +                                 revisionDescriptor).streamContent();
                           }
  -
  -                    } else {
  -                        // Partial content response.
  -
  -                        resp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
  -
  -                        if (ranges.size() == 1) {
  -
  -                            Range range = (Range) ranges.elementAt(0);
  -                            resp.addHeader("Content-Range", "bytes "
  -                                               + range.start
  -                                               + "-" + range.end + "/"
  -                                               + range.fileLength);
  -                            resp.setContentLength((int) range.length);
  +    
  +                        Vector ranges = parseRange(req, resp, resourceInfo);
  +    
  +                        // ETag header (tag must be quoted)
  +                        resp.setHeader("ETag", getETag(resourceInfo, true) );
  +                        resp.setHeader
  +                            ("Content-Language", revisionDescriptor.getContentLanguage());
  +                        resp.addHeader
  +                            ("Last-Modified",
  +                             revisionDescriptor.getLastModified().toString());
  +    
  +                        if ( ((ranges == null) || (ranges.isEmpty())) ) {
  +                            // full content response
                               resp.setContentType
                                   (revisionDescriptor.getContentType());
  -
  +                            resp.setContentLength
  +                                ((int) revisionDescriptor.getContentLength());
  +    
  +                            // Copy the input stream to our output stream
  +                            // (if requested)
                               if (printContent) {
                                   resp.setBufferSize(output);
  -                                copy(resourceInfo, is, os, range);
  +                                copy(resourceInfo, is, os);
                               }
  -
  +    
                           } else {
  -
  -                            resp.setContentType
  -                                ("multipart/byteranges; boundary="
  -                                     + mimeSeparation);
  -
  -                            if (printContent) {
  -                                resp.setBufferSize(output);
  -                                copy(resourceInfo, is, os,
  -                                     ranges.elements(),
  -                                     revisionDescriptor.getContentType());
  +                            // Partial content response.
  +    
  +                            resp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
  +    
  +                            if (ranges.size() == 1) {
  +    
  +                                Range range = (Range) ranges.elementAt(0);
  +                                resp.addHeader("Content-Range", "bytes "
  +                                                   + range.start
  +                                                   + "-" + range.end + "/"
  +                                                   + range.fileLength);
  +                                resp.setContentLength((int) range.length);
  +                                resp.setContentType
  +                                    (revisionDescriptor.getContentType());
  +    
  +                                if (printContent) {
  +                                    resp.setBufferSize(output);
  +                                    copy(resourceInfo, is, os, range);
  +                                }
  +    
  +                            } else {
  +    
  +                                resp.setContentType
  +                                    ("multipart/byteranges; boundary="
  +                                         + mimeSeparation);
  +    
  +                                if (printContent) {
  +                                    resp.setBufferSize(output);
  +                                    copy(resourceInfo, is, os,
  +                                         ranges.elements(),
  +                                         revisionDescriptor.getContentType());
  +                                }
                               }
                           }
                       }
                   } else {
  -                    resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
  +                    // XXX if there is no revision descriptor, this should be a directory
  +                    displayDirectory();
  +                    // resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
                   }
               } else {
  -                resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
  +                // XXX if there is no revisions, this should be a directory
  +                displayDirectory();
  +                // resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
               }
           } catch (Exception e) {
               int statusCode;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method GetMethod.java

Posted by Oliver Zeigermann <ol...@gmail.com>.
Committed it to the release branch as well.

Oliver


On Sat, 30 Oct 2004 15:38:14 +0200, Unico Hommes <un...@hippo.nl> wrote:
> Nice! I've thought about doing something similar some time ago as well.
> I think the way it was implemented also created some overhead when the
> request wasn't even GET at all?
> 
> Anyway, I have no problem with having another beta. Apart from this
> particular change I think perhaps it is good idea anyway to flush out
> some more bugs.
> 
> --
> Unico
> 
> 
> 
> On 30-okt-04, at 10:58, Oliver Zeigermann wrote:
> 
> > Folks,
> >
> > I have moved display of collections as HTML pages from WebDAV servlet
> > into the GET method. This allows for all accesses to the stores to be
> > done inside one and a single transaction. In effect there are no
> > chances for deadlocks from inside a single request. Additionally, no
> > mix of global requests with local ones in a transaction from inside a
> > single request causing inconsistent states inside Slide are no longer
> > possible.
> >
> > This is quite some change and maybe introduces new bugs, but I highly
> > recommend to take this over into the 2.1 release branch as it at fixes
> > and prevents many problems.
> >
> > What do you people think? Shall I take it over? This is likely to
> > require a third beta release...
> >
> > Oliver
> >
> >
> > On 30 Oct 2004 08:45:21 -0000, ozeigermann@apache.org
> > <oz...@apache.org> wrote:
> >> ozeigermann    2004/10/30 01:45:21
> >>
> >>   Modified:    src/webdav/server/org/apache/slide/webdav
> >> WebdavServlet.java
> >>                src/webdav/server/org/apache/slide/webdav/util
> >>                         DirectoryIndexGenerator.java
> >>                src/webdav/server/org/apache/slide/webdav/method
> >>                         GetMethod.java
> >>   Log:
> >>   Moved check and display of collections as HTML pages
> >>   into the GET method to assure all access is done from inside
> >> transactions
> >>   and then inside THE SAME transaction per request.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: slide-dev-help@jakarta.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: slide-dev-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method GetMethod.java

Posted by Unico Hommes <un...@hippo.nl>.
Nice! I've thought about doing something similar some time ago as well. 
I think the way it was implemented also created some overhead when the 
request wasn't even GET at all?

Anyway, I have no problem with having another beta. Apart from this 
particular change I think perhaps it is good idea anyway to flush out 
some more bugs.

--
Unico

On 30-okt-04, at 10:58, Oliver Zeigermann wrote:

> Folks,
>
> I have moved display of collections as HTML pages from WebDAV servlet
> into the GET method. This allows for all accesses to the stores to be
> done inside one and a single transaction. In effect there are no
> chances for deadlocks from inside a single request. Additionally, no
> mix of global requests with local ones in a transaction from inside a
> single request causing inconsistent states inside Slide are no longer
> possible.
>
> This is quite some change and maybe introduces new bugs, but I highly
> recommend to take this over into the 2.1 release branch as it at fixes
> and prevents many problems.
>
> What do you people think? Shall I take it over? This is likely to
> require a third beta release...
>
> Oliver
>
>
> On 30 Oct 2004 08:45:21 -0000, ozeigermann@apache.org
> <oz...@apache.org> wrote:
>> ozeigermann    2004/10/30 01:45:21
>>
>>   Modified:    src/webdav/server/org/apache/slide/webdav 
>> WebdavServlet.java
>>                src/webdav/server/org/apache/slide/webdav/util
>>                         DirectoryIndexGenerator.java
>>                src/webdav/server/org/apache/slide/webdav/method
>>                         GetMethod.java
>>   Log:
>>   Moved check and display of collections as HTML pages
>>   into the GET method to assure all access is done from inside 
>> transactions
>>   and then inside THE SAME transaction per request.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: slide-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method GetMethod.java

Posted by Oliver Zeigermann <ol...@gmail.com>.
Folks,

I have moved display of collections as HTML pages from WebDAV servlet
into the GET method. This allows for all accesses to the stores to be
done inside one and a single transaction. In effect there are no
chances for deadlocks from inside a single request. Additionally, no
mix of global requests with local ones in a transaction from inside a
single request causing inconsistent states inside Slide are no longer
possible.

This is quite some change and maybe introduces new bugs, but I highly
recommend to take this over into the 2.1 release branch as it at fixes
and prevents many problems.

What do you people think? Shall I take it over? This is likely to
require a third beta release...

Oliver 


On 30 Oct 2004 08:45:21 -0000, ozeigermann@apache.org
<oz...@apache.org> wrote:
> ozeigermann    2004/10/30 01:45:21
> 
>   Modified:    src/webdav/server/org/apache/slide/webdav WebdavServlet.java
>                src/webdav/server/org/apache/slide/webdav/util
>                         DirectoryIndexGenerator.java
>                src/webdav/server/org/apache/slide/webdav/method
>                         GetMethod.java
>   Log:
>   Moved check and display of collections as HTML pages
>   into the GET method to assure all access is done from inside transactions
>   and then inside THE SAME transaction per request.

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org