You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2014/06/11 12:37:53 UTC

svn commit: r1601845 - in /chemistry/opencmis/trunk: chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/ chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apac...

Author: fmui
Date: Wed Jun 11 10:37:53 2014
New Revision: 1601845

URL: http://svn.apache.org/r1601845
Log:
CMIS-814: added HTTP Content-Range header

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/ContentStream.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/ContentRangesTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/ContentStream.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/ContentStream.java?rev=1601845&r1=1601844&r2=1601845&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/ContentStream.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/ContentStream.java Wed Jun 11 10:37:53 2014
@@ -27,14 +27,14 @@ import java.math.BigInteger;
 public interface ContentStream extends ExtensionsData {
 
     /**
-     * Returns the length of stream.
+     * Returns the length of the stream.
      * 
      * @return the length of the stream in bytes or -1 if the length is unknown
      */
     long getLength();
 
     /**
-     * Returns the length of stream.
+     * Returns the length of the stream.
      * 
      * @return the length of the stream in bytes or {@code null} if the length
      *         is unknown

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java?rev=1601845&r1=1601844&r2=1601845&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java Wed Jun 11 10:37:53 2014
@@ -528,6 +528,14 @@ public class ObjectService {
                 response.setStatus(HttpServletResponse.SC_OK);
             } else {
                 response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
+
+                if (content.getBigLength() != null && content.getBigLength().signum() == 1) {
+                    BigInteger firstBytePos = (offset == null ? BigInteger.ZERO : offset);
+                    BigInteger lastBytePos = firstBytePos.add(content.getBigLength().subtract(BigInteger.ONE));
+
+                    response.setHeader("Content-Range",
+                            "bytes " + firstBytePos.toString() + "-" + lastBytePos.toString() + "/*");
+                }
             }
             response.setContentType(contentType);
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java?rev=1601845&r1=1601844&r2=1601845&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java Wed Jun 11 10:37:53 2014
@@ -646,6 +646,14 @@ public class ObjectService {
                 response.setStatus(HttpServletResponse.SC_OK);
             } else {
                 setStatus(request, response, HttpServletResponse.SC_PARTIAL_CONTENT);
+
+                if (content.getBigLength() != null && content.getBigLength().signum() == 1) {
+                    BigInteger firstBytePos = (offset == null ? BigInteger.ZERO : offset);
+                    BigInteger lastBytePos = firstBytePos.add(content.getBigLength().subtract(BigInteger.ONE));
+
+                    response.setHeader("Content-Range",
+                            "bytes " + firstBytePos.toString() + "-" + lastBytePos.toString() + "/*");
+                }
             }
             response.setContentType(contentType);
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java?rev=1601845&r1=1601844&r2=1601845&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java Wed Jun 11 10:37:53 2014
@@ -440,6 +440,10 @@ public abstract class AbstractSessionTes
             f = createResult(FAILURE, "Document name does not match!", false);
             addResult(assertEquals(name, result.getName(), null, f));
 
+            // check content length
+            f = createResult(WARNING, "Content length does not match!", false);
+            addResult(assertEquals((long) contentBytes.length, result.getContentStreamLength(), null, f));
+
             // check the new document
             addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/ContentRangesTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/ContentRangesTest.java?rev=1601845&r1=1601844&r2=1601845&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/ContentRangesTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/ContentRangesTest.java Wed Jun 11 10:37:53 2014
@@ -60,12 +60,18 @@ public class ContentRangesTest extends A
 
             String excerpt;
             ContentStream content;
+            long contentLength = doc.getContentStreamLength();
 
             // no offset, no length -> full content
             try {
                 content = doc.getContentStream(null, null);
                 excerpt = getStringFromContentStream(content);
 
+                if (contentLength > -1 && content.getLength() > -1) {
+                    f = createResult(WARNING, "Content length does not match {offset=null, length=null}!", false);
+                    addResult(assertEquals(contentLength, content.getLength(), null, f));
+                }
+
                 if (CONTENT.equals(excerpt)) {
                     addResult(assertIsFalse(content instanceof PartialContentStream, null, createResult(FAILURE,
                             "Retrieved stream is marked as partial stream "
@@ -83,6 +89,11 @@ public class ContentRangesTest extends A
                 content = doc.getContentStream(BigInteger.ZERO, null);
                 excerpt = getStringFromContentStream(content);
 
+                if (contentLength > -1 && content.getLength() > -1) {
+                    f = createResult(WARNING, "Content length does not match {offset=0, length=null}!", false);
+                    addResult(assertEquals(contentLength, content.getLength(), null, f));
+                }
+
                 if (CONTENT.equals(excerpt)) {
                     addResult(assertIsFalse(content instanceof PartialContentStream, null, createResult(WARNING,
                             "Retrieved stream is marked as partial stream "
@@ -100,6 +111,11 @@ public class ContentRangesTest extends A
                 content = doc.getContentStream(BigInteger.valueOf(3), null);
                 excerpt = getStringFromContentStream(content);
 
+                if (contentLength > -1 && content.getLength() > -1) {
+                    f = createResult(WARNING, "Content length does not match {offset=3, length=null}!", false);
+                    addResult(assertEquals(contentLength - 3, content.getLength(), null, f));
+                }
+
                 if (CONTENT.equals(excerpt)) {
                     addResult(createResult(WARNING,
                             "Retrieved full stream instead of an excerpt {offset=3, length=null}! Content ranges supported?"));
@@ -122,6 +138,11 @@ public class ContentRangesTest extends A
                 content = doc.getContentStream(null, BigInteger.valueOf(12));
                 excerpt = getStringFromContentStream(content);
 
+                if (content.getLength() > -1) {
+                    f = createResult(WARNING, "Content length does not match {offset=null, length=12}!", false);
+                    addResult(assertEquals(12L, content.getLength(), null, f));
+                }
+
                 if (CONTENT.equals(excerpt)) {
                     addResult(createResult(WARNING,
                             "Retrieved full stream instead of an excerpt {offset=null, length=12}! Content ranges supported?"));
@@ -144,6 +165,11 @@ public class ContentRangesTest extends A
                 content = doc.getContentStream(BigInteger.valueOf(5), BigInteger.valueOf(17));
                 excerpt = getStringFromContentStream(content);
 
+                if (content.getLength() > -1) {
+                    f = createResult(WARNING, "Content length does not match {offset=5, length=17}!", false);
+                    addResult(assertEquals((long) (17 - 5), content.getLength(), null, f));
+                }
+
                 if (CONTENT.equals(excerpt)) {
                     addResult(createResult(WARNING,
                             "Retrieved full stream instead of an excerpt {offset=5, length=17}! Content ranges supported?"));
@@ -166,6 +192,11 @@ public class ContentRangesTest extends A
                 content = doc.getContentStream(BigInteger.valueOf(9), BigInteger.valueOf(123));
                 excerpt = getStringFromContentStream(content);
 
+                if (content.getLength() > -1) {
+                    f = createResult(WARNING, "Content length does not match {offset=9, length=123}!", false);
+                    addResult(assertEquals((long) (CONTENT.length() - 9), content.getLength(), null, f));
+                }
+
                 if (CONTENT.equals(excerpt)) {
                     addResult(createResult(WARNING,
                             "Retrieved full stream instead of an excerpt {offset=9, length=123}! Content ranges supported?"));