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 2012/04/27 21:48:42 UTC
svn commit: r1331558 - in /chemistry/opencmis/trunk:
chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/local/
chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/...
Author: fmui
Date: Fri Apr 27 19:48:41 2012
New Revision: 1331558
URL: http://svn.apache.org/viewvc?rev=1331558&view=rev
Log:
Server: added capability to set the maximum content upload size
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/local/AbstractLocalService.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CmisServiceFactory.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/AbstractServiceFactory.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/CallContextImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.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/atompub/PolicyService.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DummyCallContext.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/webapp/WEB-INF/classes/repository.properties
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/local/AbstractLocalService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/local/AbstractLocalService.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/local/AbstractLocalService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/local/AbstractLocalService.java Fri Apr 27 19:48:41 2012
@@ -145,5 +145,9 @@ public abstract class AbstractLocalServi
public int getMemoryThreshold() {
return 0;
}
+
+ public long getMaxSize() {
+ return -1;
+ }
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.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/server/CallContext.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java Fri Apr 27 19:48:41 2012
@@ -46,6 +46,7 @@ public interface CallContext {
String TEMP_DIR = "tempDir";
String MEMORY_THRESHOLD = "memoryThreshold";
+ String MAX_SIZE = "maxSize";
/**
* Returns the binding. Usually it returns
@@ -108,4 +109,9 @@ public interface CallContext {
* Returns the memory threshold.
*/
int getMemoryThreshold();
+
+ /**
+ * Returns the may size of content.
+ */
+ long getMaxSize();
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CmisServiceFactory.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/server/CmisServiceFactory.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CmisServiceFactory.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CmisServiceFactory.java Fri Apr 27 19:48:41 2012
@@ -23,6 +23,8 @@ package org.apache.chemistry.opencmis.co
import java.io.File;
import java.util.Map;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
+
/**
* Factory for {@link CmisService} objects.
*/
@@ -63,4 +65,12 @@ public interface CmisServiceFactory {
* @see CmisServiceFactory#getTempDirectory()
*/
int getMemoryThreshold();
+
+ /**
+ * Returns the maximal content size in bytes. If a client provides content
+ * bigger than that, {@link CmisConstraintException} is thrown.
+ *
+ * @return the max size in bytes or -1 to disable the size check
+ */
+ long getMaxSize();
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/AbstractServiceFactory.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/AbstractServiceFactory.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/AbstractServiceFactory.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/AbstractServiceFactory.java Fri Apr 27 19:48:41 2012
@@ -49,4 +49,11 @@ public abstract class AbstractServiceFac
public int getMemoryThreshold() {
return 4 * 1024 * 1024;
}
+
+ /**
+ * Returns a max size of 4 GiB.
+ */
+ public long getMaxSize() {
+ return (long) 4 * 1024 * 1024 * 1024;
+ }
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/CallContextImpl.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/CallContextImpl.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/CallContextImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/CallContextImpl.java Fri Apr 27 19:48:41 2012
@@ -84,6 +84,10 @@ public class CallContextImpl implements
return (Integer) get(MEMORY_THRESHOLD);
}
+ public long getMaxSize() {
+ return (Long) get(MAX_SIZE);
+ }
+
/**
* Adds a parameter.
*/
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.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/AtomEntryParser.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java Fri Apr 27 19:48:41 2012
@@ -75,6 +75,7 @@ public class AtomEntryParser {
private File tempDir;
private int memoryThreshold;
+ private long maxSize;
private ObjectData object;
private ContentStreamImpl atomContentStream;
@@ -83,16 +84,17 @@ public class AtomEntryParser {
/**
* Constructor.
*/
- public AtomEntryParser(File tempDir, int memoryThreshold) {
+ public AtomEntryParser(File tempDir, int memoryThreshold, long maxSize) {
this.tempDir = tempDir;
this.memoryThreshold = memoryThreshold;
+ this.maxSize = maxSize;
}
/**
* Constructor that immediately parses the given stream.
*/
- public AtomEntryParser(InputStream stream, File tempDir, int memoryThreshold) throws Exception {
- this(tempDir, memoryThreshold);
+ public AtomEntryParser(InputStream stream, File tempDir, int memoryThreshold, long maxSize) throws Exception {
+ this(tempDir, memoryThreshold, maxSize);
parse(stream);
}
@@ -383,7 +385,7 @@ public class AtomEntryParser {
* Parses a tag that contains base64 encoded content.
*/
private ThresholdOutputStream readBase64(XMLStreamReader parser) throws Exception {
- ThresholdOutputStream bufferStream = new ThresholdOutputStream(tempDir, memoryThreshold);
+ ThresholdOutputStream bufferStream = new ThresholdOutputStream(tempDir, memoryThreshold, maxSize);
Base64.OutputStream b64stream = new Base64.OutputStream(bufferStream, Base64.DECODE);
next(parser);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.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/CmisAtomPubServlet.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java Fri Apr 27 19:48:41 2012
@@ -94,6 +94,7 @@ public class CmisAtomPubServlet extends
private File tempDir;
private int memoryThreshold;
+ private long maxSize;
private Dispatcher dispatcher;
private CallContextHandler callContextHandler;
@@ -119,6 +120,7 @@ public class CmisAtomPubServlet extends
tempDir = factory.getTempDirectory();
memoryThreshold = factory.getMemoryThreshold();
+ maxSize = factory.getMaxSize();
// initialize the dispatcher
dispatcher = new Dispatcher();
@@ -174,7 +176,7 @@ public class CmisAtomPubServlet extends
CallContext context = null;
try {
context = HttpUtils.createContext(request, response, getServletContext(), CallContext.BINDING_ATOMPUB,
- callContextHandler, tempDir, memoryThreshold);
+ callContextHandler, tempDir, memoryThreshold, maxSize);
dispatch(context, request, response);
} catch (Exception e) {
if (e instanceof CmisPermissionDeniedException) {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.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/MultiFilingService.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java Fri Apr 27 19:48:41 2012
@@ -53,7 +53,8 @@ public class MultiFilingService {
// get parameters
String removeFrom = getStringParameter(request, Constants.PARAM_REMOVE_FROM);
- AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold());
+ AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
+ context.getMaxSize());
parser.setIgnoreAtomContentSrc(true); // needed for some clients
parser.parse(request.getInputStream());
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=1331558&r1=1331557&r2=1331558&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 Fri Apr 27 19:48:41 2012
@@ -81,7 +81,8 @@ public final class ObjectService {
VersioningState versioningState = getEnumParameter(request, Constants.PARAM_VERSIONIG_STATE,
VersioningState.class);
- AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold());
+ AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
+ context.getMaxSize());
parser.setIgnoreAtomContentSrc(true); // needed for some clients
parser.parse(request.getInputStream());
@@ -138,7 +139,7 @@ public final class ObjectService {
HttpServletRequest request, HttpServletResponse response) throws Exception {
// get parameters
AtomEntryParser parser = new AtomEntryParser(request.getInputStream(), context.getTempDirectory(),
- context.getMemoryThreshold());
+ context.getMemoryThreshold(), context.getMaxSize());
// execute
String newObjectId = service.createRelationship(repositoryId, parser.getProperties(), parser.getPolicyIds(),
@@ -449,7 +450,7 @@ public final class ObjectService {
Boolean major = getBooleanParameter(request, Constants.PARAM_MAJOR);
AtomEntryParser parser = new AtomEntryParser(request.getInputStream(), context.getTempDirectory(),
- context.getMemoryThreshold());
+ context.getMemoryThreshold(), context.getMaxSize());
// execute
Holder<String> objectIdHolder = new Holder<String>(objectId);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/PolicyService.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/PolicyService.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/PolicyService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/PolicyService.java Fri Apr 27 19:48:41 2012
@@ -111,7 +111,7 @@ public class PolicyService {
String objectId = getStringParameter(request, Constants.PARAM_ID);
AtomEntryParser parser = new AtomEntryParser(request.getInputStream(), context.getTempDirectory(),
- context.getMemoryThreshold());
+ context.getMemoryThreshold(), context.getMaxSize());
// execute
service.applyPolicy(repositoryId, parser.getId(), objectId, null);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.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/VersioningService.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.java Fri Apr 27 19:48:41 2012
@@ -53,7 +53,8 @@ public class VersioningService {
public static void checkOut(CallContext context, CmisService service, String repositoryId,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// get parameters
- AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold());
+ AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
+ context.getMaxSize());
parser.setIgnoreAtomContentSrc(true); // needed for some clients
parser.parse(request.getInputStream());
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.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/CmisBrowserBindingServlet.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java Fri Apr 27 19:48:41 2012
@@ -126,6 +126,7 @@ public class CmisBrowserBindingServlet e
private File tempDir;
private int memoryThreshold;
+ private long maxSize;
private Dispatcher repositoryDispatcher;
private Dispatcher rootDispatcher;
@@ -152,6 +153,7 @@ public class CmisBrowserBindingServlet e
tempDir = factory.getTempDirectory();
memoryThreshold = factory.getMemoryThreshold();
+ maxSize = factory.getMaxSize();
// initialize the dispatchers
repositoryDispatcher = new Dispatcher(false);
@@ -244,7 +246,7 @@ public class CmisBrowserBindingServlet e
CallContext context = null;
try {
context = HttpUtils.createContext(request, response, getServletContext(), CallContext.BINDING_BROWSER,
- callContextHandler, tempDir, memoryThreshold);
+ callContextHandler, tempDir, memoryThreshold, maxSize);
dispatch(context, request, response);
} catch (Exception e) {
if (e instanceof CmisPermissionDeniedException) {
@@ -347,7 +349,7 @@ public class CmisBrowserBindingServlet e
}
} else if (METHOD_POST.equals(method)) {
POSTHttpServletRequestWrapper postRequest = new POSTHttpServletRequestWrapper(request, tempDir,
- memoryThreshold);
+ memoryThreshold, maxSize);
String cmisaction = getStringParameter(postRequest, Constants.CONTROL_CMISACTION);
String objectId = getStringParameter(postRequest, Constants.CONTROL_OBJECT_ID);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.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/POSTHttpServletRequestWrapper.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.java Fri Apr 27 19:48:41 2012
@@ -47,7 +47,7 @@ public class POSTHttpServletRequestWrapp
private BigInteger size;
private InputStream stream;
- public POSTHttpServletRequestWrapper(HttpServletRequest request, File tempDir, int memoryThreshold)
+ public POSTHttpServletRequestWrapper(HttpServletRequest request, File tempDir, int memoryThreshold, long maxSize)
throws Exception {
super(request);
@@ -93,7 +93,7 @@ public class POSTHttpServletRequestWrapp
contentType = (item.getContentType() == null ? Constants.MEDIATYPE_OCTETSTREAM : item
.getContentType());
- ThresholdOutputStream os = new ThresholdOutputStream(tempDir, memoryThreshold);
+ ThresholdOutputStream os = new ThresholdOutputStream(tempDir, memoryThreshold, maxSize);
try {
byte[] buffer = new byte[64 * 1024];
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.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/shared/HttpUtils.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java Fri Apr 27 19:48:41 2012
@@ -45,7 +45,7 @@ public class HttpUtils {
*/
public static CallContext createContext(HttpServletRequest request, HttpServletResponse response,
ServletContext servletContext, String binding, CallContextHandler callContextHandler, File tempDir,
- int memoryThreshold) {
+ int memoryThreshold, long maxSize) {
String[] pathFragments = splitPath(request);
String repositoryId = null;
@@ -70,9 +70,10 @@ public class HttpUtils {
context.put(CallContext.HTTP_SERVLET_REQUEST, request);
context.put(CallContext.HTTP_SERVLET_RESPONSE, response);
- // temp files
+ // content
context.put(CallContext.TEMP_DIR, tempDir);
context.put(CallContext.MEMORY_THRESHOLD, memoryThreshold);
+ context.put(CallContext.MAX_SIZE, maxSize);
// decode range
String rangeHeader = request.getHeader("Range");
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.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/shared/ThresholdOutputStream.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java Fri Apr 27 19:48:41 2012
@@ -29,6 +29,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
+
/**
* An OutputStream that stores the data in main memory until it reaches a
* threshold. If the threshold is passed the data is written to a temporary
@@ -39,29 +41,53 @@ import java.io.OutputStream;
* InputStream isn't required!
*/
public class ThresholdOutputStream extends OutputStream {
- private static final int MAX_GROW = 10 * 1024 * 1024;
- private static final int DEFAULT_THRESHOLD = 4 * 1024 * 1024;
+ private static final int MAX_GROW = 10 * 1024 * 1024; // 10 MiB
+ private static final int DEFAULT_THRESHOLD = 4 * 1024 * 1024; // 4 MiB
private File tempDir;
private int memoryThreshold;
+ private long maxSize;
private byte[] buf = null;
private int bufSize = 0;
- private long size;
+ private long size = 0;
private File tempFile;
private OutputStream tmpStream;
- public ThresholdOutputStream(File tempDir, int memoryThreshold) {
- this(64 * 1024, tempDir, memoryThreshold);
+ /**
+ * Constructor.
+ *
+ * @param tempDir
+ * temp directory
+ * @param memoryThreshold
+ * memory threshold in bytes
+ * @param maxSize
+ * max size of the content in bytes (-1 to disable the check)
+ */
+ public ThresholdOutputStream(File tempDir, int memoryThreshold, long maxSize) {
+ this(64 * 1024, tempDir, memoryThreshold, maxSize);
}
- public ThresholdOutputStream(int initSize, File tempDir, int memoryThreshold) {
+ /**
+ * Constructor.
+ *
+ * @param initSize
+ * initial internal buffer size
+ * @param tempDir
+ * temp directory
+ * @param memoryThreshold
+ * memory threshold in bytes
+ * @param maxSize
+ * max size of the content in bytes (-1 to disable the check)
+ */
+ public ThresholdOutputStream(int initSize, File tempDir, int memoryThreshold, long maxSize) {
if (initSize < 0) {
throw new IllegalArgumentException("Negative initial size: " + initSize);
}
this.tempDir = tempDir;
this.memoryThreshold = (memoryThreshold < 0 ? DEFAULT_THRESHOLD : memoryThreshold);
+ this.maxSize = maxSize;
buf = new byte[initSize];
}
@@ -104,34 +130,59 @@ public class ThresholdOutputStream exten
@Override
public void write(byte[] buffer, int offset, int len) throws IOException {
- if (len == 0) {
- return;
- }
+ try {
+ if (len == 0) {
+ return;
+ }
- expand(len);
- System.arraycopy(buffer, offset, buf, bufSize, len);
- bufSize += len;
- size += len;
+ if ((maxSize > -1) && (size + len > maxSize)) {
+ destroy();
+ throw new CmisConstraintException("Content too big!");
+ }
+
+ expand(len);
+ System.arraycopy(buffer, offset, buf, bufSize, len);
+ bufSize += len;
+ size += len;
+ } catch (IOException ioe) {
+ destroy();
+ throw ioe;
+ }
}
@Override
public void write(int oneByte) throws IOException {
- if (bufSize == buf.length) {
- expand(1);
- }
+ try {
+ if ((maxSize > -1) && (size + 1 > maxSize)) {
+ destroy();
+ throw new CmisConstraintException("Content too big!");
+ }
+
+ if (bufSize == buf.length) {
+ expand(1);
+ }
- buf[bufSize++] = (byte) oneByte;
- size++;
+ buf[bufSize++] = (byte) oneByte;
+ size++;
+ } catch (IOException ioe) {
+ destroy();
+ throw ioe;
+ }
}
@Override
public void flush() throws IOException {
if (tmpStream != null) {
- if (bufSize > 0) {
- tmpStream.write(buf, 0, bufSize);
- bufSize = 0;
+ try {
+ if (bufSize > 0) {
+ tmpStream.write(buf, 0, bufSize);
+ bufSize = 0;
+ }
+ tmpStream.flush();
+ } catch (IOException ioe) {
+ destroy();
+ throw ioe;
}
- tmpStream.flush();
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.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/AtomEntryParserTest.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java Fri Apr 27 19:48:41 2012
@@ -39,6 +39,7 @@ import org.junit.Test;
public class AtomEntryParserTest {
private static final int THRESHOLD = 4 * 1024 * 1024;
+ private static final int MAX_SIZE = -1;
private static final String CMIS_ENTRY_CONTENT = "This is my content!";
private static final String CMIS_ENTRY = "<?xml version='1.0' encoding='utf-8'?>"
@@ -171,7 +172,8 @@ public class AtomEntryParserTest {
@Test
public void testAtomTitle() throws Exception {
- AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(ATOM_ENTRY_NAME.getBytes()), null, THRESHOLD);
+ AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(ATOM_ENTRY_NAME.getBytes()), null,
+ THRESHOLD, MAX_SIZE);
assertNotNull(aep);
assertNotNull(aep.getObject());
@@ -187,7 +189,7 @@ public class AtomEntryParserTest {
@Test
public void testNullStream() throws Exception {
- AtomEntryParser aep = new AtomEntryParser(null, null, THRESHOLD);
+ AtomEntryParser aep = new AtomEntryParser(null, null, THRESHOLD, MAX_SIZE);
assertNotNull(aep);
assertNull(aep.getId());
@@ -198,7 +200,7 @@ public class AtomEntryParserTest {
@Test
public void testEmptyStream() throws Exception {
- AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(new byte[0]), null, THRESHOLD);
+ AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(new byte[0]), null, THRESHOLD, MAX_SIZE);
assertNotNull(aep);
assertNull(aep.getId());
@@ -208,7 +210,7 @@ public class AtomEntryParserTest {
}
private static byte[] parse(byte[] entry) throws Exception {
- AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(entry), null, THRESHOLD);
+ AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(entry), null, THRESHOLD, MAX_SIZE);
ContentStream contentStream = aep.getContentStream();
assertNotNull(contentStream);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ConfigConstants.java Fri Apr 27 19:48:41 2012
@@ -27,6 +27,7 @@ public class ConfigConstants {
public static final String OVERRIDE_CALL_CONTEXT = "InMemoryServer.OverrideCallContext";
public static final String MEMORY_THRESHOLD = "InMemoryServer.MemoryThreshold";
public static final String TEMP_DIR = "InMemoryServer.TempDir";
+ public static final String MAX_SIZE = "InMemoryServer.MaxSize";
// Helper constants that allow to fill a repository with data on
// initialization
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DummyCallContext.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DummyCallContext.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DummyCallContext.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DummyCallContext.java Fri Apr 27 19:48:41 2012
@@ -89,4 +89,8 @@ public class DummyCallContext implements
public int getMemoryThreshold() {
return 4 * 1024 * 1024;
}
+
+ public long getMaxSize() {
+ return 4 * 1024 * 1024 * 1024;
+ }
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java Fri Apr 27 19:48:41 2012
@@ -77,15 +77,17 @@ public class InMemoryServiceFactoryImpl
private boolean fUseOverrideCtx = false;
private StoreManager storeManager; // singleton root of everything
private CleanManager cleanManager = null;
-
+
private File tempDir;
private int memoryThreshold;
-
+ private long maxSize;
@Override
public void init(Map<String, String> parameters) {
LOG.info("Initializing in-memory repository...");
+ System.out.println(parameters);
+
inMemoryServiceParameters = parameters;
String overrideCtx = parameters.get(ConfigConstants.OVERRIDE_CALL_CONTEXT);
if (null != overrideCtx) {
@@ -105,9 +107,17 @@ public class InMemoryServiceFactoryImpl
String tempDirStr = parameters.get(ConfigConstants.TEMP_DIR);
tempDir = (tempDirStr == null ? super.getTempDirectory() : new File(tempDirStr));
-
+
String memoryThresholdStr = parameters.get(ConfigConstants.MEMORY_THRESHOLD);
- memoryThreshold = (memoryThresholdStr == null ? super.getMemoryThreshold(): Integer.parseInt(memoryThresholdStr));
+ memoryThreshold = (memoryThresholdStr == null ? super.getMemoryThreshold() : Integer
+ .parseInt(memoryThresholdStr));
+
+ String maxSizeStr = parameters.get(ConfigConstants.MAX_SIZE);
+ maxSize = (maxSizeStr == null ? super.getMaxSize() : Long.parseLong(maxSizeStr));
+
+ System.out.println("maxSizeStr > " + maxSizeStr);
+ System.out.println("super.getMaxSize() > " + super.getMaxSize());
+ System.out.println("content > " + tempDir + " / " + memoryThreshold + " / " + maxSize);
Date deploymentTime = new Date();
String strDate = new SimpleDateFormat("EEE MMM dd hh:mm:ss a z yyyy", Locale.US).format(deploymentTime);
@@ -166,8 +176,12 @@ public class InMemoryServiceFactoryImpl
public int getMemoryThreshold() {
return memoryThreshold;
}
-
-
+
+ @Override
+ public long getMaxSize() {
+ return maxSize;
+ }
+
@Override
public void destroy() {
if (null != cleanManager) {
@@ -311,11 +325,15 @@ public class InMemoryServiceFactoryImpl
public File getTempDirectory() {
- return null;
+ return tempDir;
}
public int getMemoryThreshold() {
- return 0;
+ return memoryThreshold;
+ }
+
+ public long getMaxSize() {
+ return maxSize;
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/webapp/WEB-INF/classes/repository.properties
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/webapp/WEB-INF/classes/repository.properties?rev=1331558&r1=1331557&r2=1331558&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/webapp/WEB-INF/classes/repository.properties (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/webapp/WEB-INF/classes/repository.properties Fri Apr 27 19:48:41 2012
@@ -28,6 +28,7 @@ InMemoryServer.TypeDefinitionsFile=types
# InMemoryServer.MemoryThreshold=10485760
# InMemoryServer.TempDir=/path/to/your/tmp
+InMemoryServer.MaxSize=20971520
# settings for init repository with data
# enable or disable