chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1655702 - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src: main/java/org/apache/chemistry/opencmis/server/impl/webservices/ test/java/org/apache/chemistry/opencmis/server/impl/
Date Thu, 29 Jan 2015 15:18:01 GMT
Author: fmui
Date: Thu Jan 29 15:18:01 2015
New Revision: 1655702

URL: http://svn.apache.org/r1655702
Log:
Server: Web Services: reduced memory footprint

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/ProtectionRequestWrapper.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/CheckServletInputStreamTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/ProtectionRequestWrapper.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/webservices/ProtectionRequestWrapper.java?rev=1655702&r1=1655701&r2=1655702&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/ProtectionRequestWrapper.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/ProtectionRequestWrapper.java
Thu Jan 29 15:18:01 2015
@@ -86,7 +86,7 @@ public class ProtectionRequestWrapper ex
 
         public CheckServletInputStream() {
             streamMax = messageMax + 2 * (boundary.length + 6);
-            linebuffer = new byte[64 * 1024];
+            linebuffer = new byte[32 * 1024];
             pos = 0;
             count = 0;
             boundariesFound = 0;
@@ -160,29 +160,38 @@ public class ProtectionRequestWrapper ex
         }
 
         private void checkBoundary(int startPos) {
-            int lastStartPos = 0;
+            int lastLineFeed = -1;
             for (int i = startPos; i < pos; i++) {
                 if (linebuffer[i] == LF) {
-                    if (countBoundaries(lastStartPos, i)) {
+                    if (countBoundaries(i)) {
                         return;
                     }
-
-                    lastStartPos = i + 1;
+                    lastLineFeed = i;
                 }
             }
 
-            if (lastStartPos > 0) {
-                if (lastStartPos == pos) {
+            if (lastLineFeed == -1) {
+                if (pos > boundary.length + 3) {
+                    // buffer is bigger than the boundary and doesn't contain a
+                    // LF -> only keep the length of the boundary plus three
+                    // characters (two dashes and a CR)
+                    System.arraycopy(linebuffer, pos - (boundary.length + 3), linebuffer,
0, boundary.length + 3);
+                    pos = boundary.length + 3;
+                }
+            } else {
+                if (lastLineFeed == pos - 1) {
+                    // last byte is a LF -> discard the whole buffer
                     pos = 0;
                 } else {
-                    System.arraycopy(linebuffer, lastStartPos, linebuffer, 0, pos - lastStartPos);
-                    pos = pos - lastStartPos;
+                    // only keep bytes after the last LF
+                    System.arraycopy(linebuffer, lastLineFeed + 1, linebuffer, 0, pos - (lastLineFeed
+ 1));
+                    pos = pos - (lastLineFeed + 1);
                 }
             }
         }
 
-        private boolean countBoundaries(int startPos, int newLinePos) {
-            if (isBoundary(startPos, newLinePos)) {
+        private boolean countBoundaries(int lineFeedPos) {
+            if (isBoundary(lineFeedPos)) {
                 boundariesFound++;
 
                 if (boundariesFound == 2) {
@@ -195,12 +204,14 @@ public class ProtectionRequestWrapper ex
             return boundariesFound > 1;
         }
 
-        private boolean isBoundary(int startPos, int newLinePos) {
+        private boolean isBoundary(int lineFeedPos) {
             // a boundary consists of two dashes, the boundary and a CR
             // -> boundary line length == boundary length + three characters
-            if (newLinePos - startPos == boundary.length + 3) {
+            int startPos = lineFeedPos - (boundary.length + 3);
+
+            if (startPos >= 0) {
                 if (linebuffer[startPos] == DASH && linebuffer[startPos + 1] == DASH
-                        && linebuffer[startPos + boundary.length + 2] == CR) {
+                        && linebuffer[lineFeedPos - 1] == CR) {
 
                     for (int i = 0; i < boundary.length; i++) {
                         if (linebuffer[startPos + i + 2] != boundary[i]) {
@@ -270,7 +281,7 @@ public class ProtectionRequestWrapper ex
                 throw new IOException("SOAP message too big!");
             }
 
-            int expand = (len < 64 * 1024 ? 64 * 1024 : len);
+            int expand = (len < 32 * 1024 ? 32 * 1024 : len);
             byte[] newBuffer = new byte[linebuffer.length + expand];
             System.arraycopy(linebuffer, 0, newBuffer, 0, pos);
             linebuffer = newBuffer;

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/CheckServletInputStreamTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/CheckServletInputStreamTest.java?rev=1655702&r1=1655701&r2=1655702&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/CheckServletInputStreamTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/CheckServletInputStreamTest.java
Thu Jan 29 15:18:01 2015
@@ -23,6 +23,7 @@ import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.util.Random;
 
 import org.apache.chemistry.opencmis.server.impl.webservices.ProtectionRequestWrapper;
 import org.junit.Test;
@@ -76,6 +77,45 @@ public class CheckServletInputStreamTest
         baseTest(100 * 1024, 80 * 1024, 79 * 1024, 1234, true);
     }
 
+    @Test
+    public void testStream10() {
+        baseTest(900 * 1024, 1 * 1024 * 1024, 900 * 1024, 8 * 1024, true);
+    }
+
+    @Test
+    public void testStream11() {
+        baseTest(900 * 1024, 512 * 1024, 900 * 1024, 8 * 1024, false);
+    }
+
+    @Test
+    public void testStream12() {
+        baseTest(900 * 1024, 1 * 1024 * 1024, 700 * 1024, 2345, true);
+    }
+
+    @Test
+    public void testStream13() {
+        baseTest(900 * 1024, 1 * 1024 * 1024, 700, 2345, true);
+    }
+
+    @Test
+    public void testStream14() {
+        baseTest(900 * 1024, 1 * 1024 * 1024, 2048, 2345, true);
+    }
+
+    @Test
+    public void testStreamRandom() {
+        int bufferSize = 1 * 1024 * 1024;
+        Random rnd = new Random(1234567890);
+
+        for (int i = 0; i < 100; i++) {
+            int max = rnd.nextInt(bufferSize);
+            int soap = rnd.nextInt(bufferSize);
+            int readBufferSize = rnd.nextInt(64 * 1024);
+
+            baseTest(bufferSize, max, soap, readBufferSize, soap <= max);
+        }
+    }
+
     private void baseTest(int bufferSize, int max, int soap, int readBufferSize, boolean
success) {
 
         byte[] boundaryBytes = ("\r\n--" + BOUNDARY + "\r\n").getBytes();



Mime
View raw message