[Cosmo-dev] bug 5078: read put request content into a tmp file and compare the]

Jared Rhine jared at wordzoo.com
Tue Oct 17 08:46:51 PDT 2006


As I read this, this change (use of a temp file to check content-length on
PUT) has a significant impact on Cosmo's operational profile, particularly
disk I/O.  It'd be nice to stick with an application which is CPU-bound.  I
dunno if there's a conclusion here, but damn, really, a temp file?  Ick.
Seems like a code smell[1] to me.  Is there no other reasonable way?

[1] http://c2.com/xp/CodeSmell.html

-------- Original Message --------
Subject: 	[commits-cosmo] (bcm) [2699] bug 5078: read put request
content into a tmp file and compare the
Date: 	Mon, 16 Oct 2006 18:42:17 -0700 (PDT)
From: 	svncheckin at osafoundation.org
To: 	commits-cosmo at osafoundation.org



Revision
    2699 <http://cvs.osafoundation.org/viewcvs.cgi?rev=2699&view=rev>
Author
    bcm
Date
    2006-10-16 18:42:17 -0700 (Mon, 16 Oct 2006)


      Log Message

bug 5078 <http://bugzilla.osafoundation.org/show_bug.cgi?id=5078>: read
put request content into a tmp file and compare the
number of bytes read with the specified content-length (assuming
chunked transfer encoding was not used). if they don't match, throw an
exception.


      Modified Paths

    * cosmo/trunk/src/main/java/org/osaf/cosmo/dav/impl/DavFile.java
      <#cosmotrunksrcmainjavaorgosafcosmodavimplDavFilejava>


      Diff


        Modified:
        cosmo/trunk/src/main/java/org/osaf/cosmo/dav/impl/DavFile.java
        (2698 => 2699)

--- cosmo/trunk/src/main/java/org/osaf/cosmo/dav/impl/DavFile.java
2006-10-17 01:09:34 UTC (rev 2698)
+++ cosmo/trunk/src/main/java/org/osaf/cosmo/dav/impl/DavFile.java
2006-10-17 01:42:17 UTC (rev 2699)
@@ -15,6 +15,8 @@
  */
 package org.osaf.cosmo.dav.impl;

+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.OutputStreamWriter;
@@ -220,17 +222,28 @@
         ContentItem content = (ContentItem) getItem();

         if (inputContext.hasStream()) {
+            // read to tmp file, checking bytes read against content
+            // length if we're not using chunked encoding
+            File tmp = null;
             try {
-                // XXX: read to tmp file, checking bytes read against
-                // content length
-                content.setContent(inputContext.getInputStream());
+                tmp = IOUtil.getTempFile(inputContext.getInputStream());
+                long contentLength = inputContext.getContentLength();
+                long readLength = tmp.length();
+                if (contentLength != IOUtil.UNDEFINED_LENGTH &&
+                    contentLength != readLength)
+                    throw new IOException("Read only " + readLength + " of
" + contentLength + " bytes");
+                content.setContent(new FileInputStream(tmp));
             } catch (IOException e) {
                 log.error("Cannot read resource content", e);
                 throw new
DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Cannot read
resource content: " + e.getMessage());
             } catch (DataSizeException e) {
                 throw new DavException(DavServletResponse.SC_FORBIDDEN,
"Cannot store resource content: " + e.getMessage());
+            } finally {
+                // XXX: assumes that content.setContent() consumes the
+                // stream so that the tmpfile is no longer needed
+                if (tmp != null)
+                    tmp.delete();
             }
-
         }

         try {

-------------- next part --------------
_______________________________________________
Commits-Cosmo mailing list
Commits-Cosmo at osafoundation.org
http://lists.osafoundation.org/cgi-bin/mailman/listinfo/commits-cosmo



More information about the cosmo-dev mailing list