Author: fmui
Date: Wed Jan 14 15:44:55 2015
New Revision: 1651711
URL: http://svn.apache.org/r1651711
Log:
CMIS-882: Server: added interface to manage temporary content
Added:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/TempStoreOutputStream.java
(with props)
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/TempStoreOutputStreamFactory.java
(with props)
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/test/java/org/apache/chemistry/opencmis/client/SessionParameterMapTest.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/RepositoryService.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/BrowserCallContextImpl.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/MultipartParser.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/impl/webservices/AbstractService.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.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/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStreamFactory.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-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/MultipartParserTest.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/test/java/org/apache/chemistry/opencmis/client/SessionParameterMapTest.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/test/java/org/apache/chemistry/opencmis/client/SessionParameterMapTest.java?rev=1651711&r1=1651710&r2=1651711&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/test/java/org/apache/chemistry/opencmis/client/SessionParameterMapTest.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/test/java/org/apache/chemistry/opencmis/client/SessionParameterMapTest.java
Wed Jan 14 15:44:55 2015
@@ -38,6 +38,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
+import org.apache.chemistry.opencmis.commons.server.TempStoreOutputStream;
import org.apache.chemistry.opencmis.commons.spi.AuthenticationProvider;
import org.junit.Test;
import org.w3c.dom.Element;
@@ -249,5 +250,10 @@ public class SessionParameterMapTest {
public long getMaxContentSize() {
return 0;
}
+
+ @Override
+ public TempStoreOutputStream getTempFileOutputStream(String
repositoryId) {
+ return null;
+ }
}
}
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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -70,7 +70,7 @@ public interface CallContext {
String MAX_CONTENT_SIZE = "maxContentSize";
/** Key: encrypt temp files (values is a Boolean) */
String ENCRYPT_TEMP_FILE = "encryptTempFiles";
- /** Key: factory for threshold streams (value is a
ThresholdOutputStreamFactory) */
+ /** Key: factory for threshold streams (value is a
TempStoreOutputStreamFactory) */
String STREAM_FACTORY = "streamFactory";
/**
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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -45,6 +45,11 @@ public interface CmisServiceFactory {
*
* When the {@link CmisService} object is not longer needed
* {@link CmisService#close()} will be called.
+ *
+ * @param context
+ * the call context
+ *
+ * @return a {@link CmisService} instance, never {@code null}
*/
CmisService getService(CallContext context);
@@ -59,8 +64,8 @@ public interface CmisServiceFactory {
/**
* Indicates if temporary files should be encrypted.
*
- * @return <code>true</code> if temporary files should be encrypted,
- * <code>false</code> otherwise
+ * @return {@code true} if temporary files should be encrypted,
+ * {@code false} otherwise
*
* @see CmisServiceFactory#getTempDirectory()
*/
@@ -83,4 +88,25 @@ public interface CmisServiceFactory {
* @return the max size in bytes or -1 to disable the size check
*/
long getMaxContentSize();
+
+ /**
+ * Returns a {@link TempStoreOutputStream} object for the given
+ * {@link CallContext}.
+ *
+ * This method is only called for the AtomPub and the Browser binding
+ * requests. The Web Services binding always used temporary files (see
+ * {@link #getTempDirectory()}).
+ *
+ * If {@code null} is returned, a default implementation that stores the
+ * document content in temporary files is used (see
+ * {@link #getTempDirectory()}).
+ *
+ * @param repositoryId
+ * the repository ID or {@code null} if the repository ID is
+ * unknown
+ *
+ * @return a {@link TempStoreOutputStream} instance or {@code null} to use
+ * the default implementation
+ */
+ TempStoreOutputStream getTempFileOutputStream(String repositoryId);
}
Added:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/TempStoreOutputStream.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/TempStoreOutputStream.java?rev=1651711&view=auto
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/TempStoreOutputStream.java
(added)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/TempStoreOutputStream.java
Wed Jan 14 15:44:55 2015
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.commons.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Subclasses of this class are used to store document content for a short
+ * period of time.
+ *
+ * The OpenCMIS server framework creates such a new stream when it needs to
+ * offload document content for a moment. That can happen when a document is
+ * created, new content is set for an existing document, or a new document
+ * version is created. How and where subclasses of this output stream store the
+ * content is not specified.
+ *
+ * The {@link #getInputStream()} and {@link #getLength()} methods are not
called
+ * before all bytes have been written to this output stream and the
+ * {@link #close()} method has been called. The {@link #destroy(Throwable)}
+ * method can be called at any time and indicates that this stream is not
needed
+ * anymore and attached resources can be cleaned up.
+ */
+public abstract class TempStoreOutputStream extends OutputStream {
+
+ /**
+ * Returns an {@link InputStream} that serves the content that has been
+ * provided to this {@link TempStoreOutputStream} instance.
+ *
+ * If this method is called multiple times, the same {@link InputStream}
+ * object must be returned.
+ *
+ * Implementations should clean up all attached resources when this stream
+ * is closed.
+ */
+ public abstract InputStream getInputStream() throws IOException;
+
+ /**
+ * Returns the length of the stream in bytes.
+ *
+ * @return the length of the stream
+ */
+ public abstract long getLength();
+
+ /**
+ * This method is called if the stream has to be released before it is
fully
+ * written or read.
+ *
+ * Implementations should clean up all attached resources.
+ *
+ * @param cause
+ * the throwable that caused the call of this method or
+ * {@code null} if no throwable object is available
+ */
+ public abstract void destroy(Throwable cause);
+}
Propchange:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/TempStoreOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -24,28 +24,34 @@ import java.util.Map;
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
+import org.apache.chemistry.opencmis.commons.server.TempStoreOutputStream;
public abstract class AbstractServiceFactory implements CmisServiceFactory {
+ @Override
public void init(Map<String, String> parameters) {
}
+ @Override
public void destroy() {
}
+ @Override
public abstract CmisService getService(CallContext context);
/**
* Returns the Java temp directory.
*/
+ @Override
public File getTempDirectory() {
String tempDir = System.getProperty("java.io.tmpdir");
return new File(tempDir);
}
/**
- * Returns <code>false</code>, do not encrypt temporary files.
+ * Returns {@code false}, do not encrypt temporary files.
*/
+ @Override
public boolean encryptTempFiles() {
return false;
}
@@ -53,6 +59,7 @@ public abstract class AbstractServiceFac
/**
* Returns a threshold of 4 MiB.
*/
+ @Override
public int getMemoryThreshold() {
return 4 * 1024 * 1024;
}
@@ -60,7 +67,17 @@ public abstract class AbstractServiceFac
/**
* Returns a max size of 4 GiB.
*/
+ @Override
public long getMaxContentSize() {
return (long) 4 * 1024 * 1024 * 1024;
}
+
+ /**
+ * Returns {@code null} to indicate that the default, temp files based
+ * implementation should be used.
+ */
+ @Override
+ public TempStoreOutputStream getTempFileOutputStream(String repositoryId) {
+ return null;
+ }
}
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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -32,7 +32,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
import org.apache.chemistry.opencmis.commons.server.MutableCallContext;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
/**
* Implementation of the {@link CallContext} interface.
@@ -45,7 +45,7 @@ public class CallContextImpl implements
public CallContextImpl(String binding, CmisVersion cmisVersion, String
repositoryId, ServletContext servletContext,
HttpServletRequest request, HttpServletResponse response,
CmisServiceFactory factory,
- ThresholdOutputStreamFactory streamFactory) {
+ TempStoreOutputStreamFactory streamFactory) {
this.binding = binding;
this.objectInfoRequired = BINDING_ATOMPUB.equals(binding);
put(REPOSITORY_ID, repositoryId);
@@ -61,17 +61,12 @@ public class CallContextImpl implements
put(CallContext.HTTP_SERVLET_REQUEST, request);
put(CallContext.HTTP_SERVLET_RESPONSE, response);
- if (streamFactory != null) {
- put(TEMP_DIR, streamFactory.getTempDir());
- put(MEMORY_THRESHOLD, streamFactory.getMemoryThreshold());
- put(MAX_CONTENT_SIZE, streamFactory.getMaxContentSize());
- put(ENCRYPT_TEMP_FILE, streamFactory.isEncrypted());
- put(STREAM_FACTORY, streamFactory);
- } else if (factory != null) {
+ if (factory != null) {
put(TEMP_DIR, factory.getTempDirectory());
put(MEMORY_THRESHOLD, factory.getMemoryThreshold());
- put(MAX_CONTENT_SIZE, -1);
- put(ENCRYPT_TEMP_FILE, false);
+ put(MAX_CONTENT_SIZE, factory.getMaxContentSize());
+ put(ENCRYPT_TEMP_FILE, factory.encryptTempFiles());
+ put(STREAM_FACTORY, streamFactory);
}
}
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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -55,9 +55,9 @@ import org.apache.chemistry.opencmis.com
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl;
+import org.apache.chemistry.opencmis.commons.server.TempStoreOutputStream;
import org.apache.chemistry.opencmis.server.shared.CappedInputStream;
-import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
/**
* Parser for Atom Entries.
@@ -83,7 +83,7 @@ public final class AtomEntryParser {
private CappedInputStream cappedStream;
- private final ThresholdOutputStreamFactory streamFactory;
+ private final TempStoreOutputStreamFactory streamFactory;
private ObjectData object;
private ContentStreamImpl atomContentStream;
@@ -94,14 +94,14 @@ public final class AtomEntryParser {
/**
* Constructor.
*/
- public AtomEntryParser(ThresholdOutputStreamFactory streamFactory) {
+ public AtomEntryParser(TempStoreOutputStreamFactory streamFactory) {
this.streamFactory = streamFactory;
}
/**
* Constructor that immediately parses the given stream.
*/
- public AtomEntryParser(InputStream stream, ThresholdOutputStreamFactory
streamFactory) throws XMLStreamException,
+ public AtomEntryParser(InputStream stream, TempStoreOutputStreamFactory
streamFactory) throws XMLStreamException,
IOException {
this(streamFactory);
parse(stream);
@@ -331,26 +331,26 @@ public final class AtomEntryParser {
}
}
- ThresholdOutputStream ths = null;
+ TempStoreOutputStream tsos = null;
byte[] bytes = null;
if (type.equals("text") || type.equals("html")) {
- ths = readContentBytes(parser);
+ tsos = readContentBytes(parser);
} else if (type.equals("xhtml")) {
bytes = copy(parser);
} else if (type.endsWith("/xml") || type.endsWith("+xml")) {
bytes = copy(parser);
} else if (type.startsWith("text/")) {
- ths = readContentBytes(parser);
+ tsos = readContentBytes(parser);
} else {
- ths = readBase64(parser);
+ tsos = readBase64(parser);
}
- if (ths != null) {
+ if (tsos != null) {
try {
- atomContentStream.setStream(ths.getInputStream());
- atomContentStream.setLength(BigInteger.valueOf(ths.getSize()));
+ atomContentStream.setStream(tsos.getInputStream());
+
atomContentStream.setLength(BigInteger.valueOf(tsos.getLength()));
} catch (IOException e) {
- ths.destroy();
+ tsos.destroy(e);
throw e;
}
}
@@ -380,12 +380,12 @@ public final class AtomEntryParser {
if (TAG_MEDIATYPE.equals(name.getLocalPart())) {
cmisContentStream.setMimeType(XMLUtils.readText(parser,
XMLConstraints.MAX_STRING_LENGTH));
} else if (TAG_BASE64.equals(name.getLocalPart())) {
- ThresholdOutputStream ths = readBase64(parser);
+ TempStoreOutputStream tsos = readBase64(parser);
try {
- cmisContentStream.setStream(ths.getInputStream());
-
cmisContentStream.setLength(BigInteger.valueOf(ths.getSize()));
+ cmisContentStream.setStream(tsos.getInputStream());
+
cmisContentStream.setLength(BigInteger.valueOf(tsos.getLength()));
} catch (IOException e) {
- ths.destroy();
+ tsos.destroy(e);
throw e;
}
} else {
@@ -415,8 +415,8 @@ public final class AtomEntryParser {
/**
* Parses a tag that contains content bytes.
*/
- private ThresholdOutputStream readContentBytes(XMLStreamReader parser)
throws XMLStreamException, IOException {
- ThresholdOutputStream bufferStream = streamFactory.newOutputStream();
+ private TempStoreOutputStream readContentBytes(XMLStreamReader parser)
throws XMLStreamException, IOException {
+ TempStoreOutputStream bufferStream = streamFactory.newOutputStream();
XMLUtils.next(parser);
@@ -433,7 +433,7 @@ public final class AtomEntryParser {
cappedStream.deductBytes(bytes.length);
}
} else if (event == XMLStreamReader.START_ELEMENT) {
- bufferStream.destroy();
+ bufferStream.destroy(null);
throw new CmisInvalidArgumentException("Unexpected tag: "
+ parser.getName());
}
@@ -443,11 +443,11 @@ public final class AtomEntryParser {
}
} catch (XMLStreamException xse) {
// remove temp file
- bufferStream.destroy();
+ bufferStream.destroy(xse);
throw xse;
} catch (IOException ioe) {
// remove temp file
- bufferStream.destroy();
+ bufferStream.destroy(ioe);
throw ioe;
}
@@ -459,8 +459,8 @@ public final class AtomEntryParser {
/**
* Parses a tag that contains base64 encoded content.
*/
- private ThresholdOutputStream readBase64(XMLStreamReader parser) throws
XMLStreamException, IOException {
- ThresholdOutputStream bufferStream = streamFactory.newOutputStream();
+ private TempStoreOutputStream readBase64(XMLStreamReader parser) throws
XMLStreamException, IOException {
+ TempStoreOutputStream bufferStream = streamFactory.newOutputStream();
Base64.OutputStream b64stream = new Base64.OutputStream(bufferStream,
Base64.DECODE);
XMLUtils.next(parser);
@@ -483,7 +483,7 @@ public final class AtomEntryParser {
}
} else if (event == XMLStreamReader.START_ELEMENT) {
b64stream.close();
- bufferStream.destroy();
+ bufferStream.destroy(null);
throw new CmisInvalidArgumentException("Unexpected tag: "
+ parser.getName());
}
@@ -495,11 +495,11 @@ public final class AtomEntryParser {
b64stream.close();
} catch (XMLStreamException xse) {
// remove temp file
- bufferStream.destroy();
+ bufferStream.destroy(xse);
throw xse;
} catch (IOException ioe) {
// remove temp file
- bufferStream.destroy();
+ bufferStream.destroy(ioe);
throw ioe;
}
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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -83,6 +83,7 @@ import org.apache.chemistry.opencmis.ser
import
org.apache.chemistry.opencmis.server.shared.NoBodyHttpServletResponseWrapper;
import
org.apache.chemistry.opencmis.server.shared.QueryStringHttpServletRequestWrapper;
import org.apache.chemistry.opencmis.server.shared.ServiceCall;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
import org.apache.commons.lang.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -169,6 +170,14 @@ public class CmisAtomPubServlet extends
CallContext context = null;
try {
+ // split path
+ String[] pathFragments = HttpUtils.splitPath(request);
+
+ // create stream factory
+ TempStoreOutputStreamFactory streamFactoy =
TempStoreOutputStreamFactory.newInstance(getServiceFactory(),
+ pathFragments.length > 0 ? pathFragments[0] : null);
+
+ // treat HEAD requests
if (METHOD_HEAD.equals(request.getMethod())) {
request = new HEADHttpServletRequestWrapper(request);
response = new NoBodyHttpServletResponseWrapper(response);
@@ -180,8 +189,8 @@ public class CmisAtomPubServlet extends
response.addHeader("Cache-Control", "private, max-age=0");
response.addHeader("Server", ServerVersion.OPENCMIS_SERVER);
- context = createContext(getServletContext(), request, response);
- dispatch(context, request, response);
+ context = createContext(getServletContext(), request, response,
streamFactoy);
+ dispatch(context, request, response, pathFragments);
} catch (Exception e) {
if (e instanceof CmisUnauthorizedException) {
response.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\"");
@@ -212,8 +221,8 @@ public class CmisAtomPubServlet extends
/**
* Dispatches to feed, entry or whatever.
*/
- private void dispatch(CallContext context, HttpServletRequest request,
HttpServletResponse response)
- throws Exception {
+ private void dispatch(CallContext context, HttpServletRequest request,
HttpServletResponse response,
+ String[] pathFragments) throws Exception {
CmisService service = null;
try {
@@ -221,8 +230,6 @@ public class CmisAtomPubServlet extends
service = getServiceFactory().getService(context);
// analyze the path
- String[] pathFragments = HttpUtils.splitPath(request);
-
if (pathFragments.length < 2) {
// root -> service document
dispatcher.dispatch("", METHOD_GET, context, service, null,
request, response);
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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -30,7 +30,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
/**
* MultiFiling Service operations.
@@ -52,7 +52,7 @@ public class MultiFilingService {
// get parameters
String removeFrom = getStringParameter(request,
Constants.PARAM_REMOVE_FROM);
- ThresholdOutputStreamFactory streamFactory =
(ThresholdOutputStreamFactory) context
+ TempStoreOutputStreamFactory streamFactory =
(TempStoreOutputStreamFactory) context
.get(CallContext.STREAM_FACTORY);
AtomEntryParser parser = new AtomEntryParser(streamFactory);
parser.setIgnoreAtomContentSrc(true); // needed for some clients
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=1651711&r1=1651710&r2=1651711&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 Jan 14 15:44:55 2015
@@ -64,7 +64,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
import org.apache.chemistry.opencmis.commons.spi.Holder;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
/**
* Object Service operations.
@@ -91,7 +91,7 @@ public class ObjectService {
VersioningState versioningState = getEnumParameter(request,
Constants.PARAM_VERSIONIG_STATE,
VersioningState.class);
- ThresholdOutputStreamFactory streamFactory =
(ThresholdOutputStreamFactory) context
+ TempStoreOutputStreamFactory streamFactory =
(TempStoreOutputStreamFactory) context
.get(CallContext.STREAM_FACTORY);
AtomEntryParser parser = new AtomEntryParser(streamFactory);
parser.setIgnoreAtomContentSrc(true); // needed for some clients
@@ -179,7 +179,7 @@ public class ObjectService {
assert response != null;
// get parameters
- ThresholdOutputStreamFactory streamFactory =
(ThresholdOutputStreamFactory) context
+ TempStoreOutputStreamFactory streamFactory =
(TempStoreOutputStreamFactory) context
.get(CallContext.STREAM_FACTORY);
AtomEntryParser parser = new
AtomEntryParser(request.getInputStream(), streamFactory);
@@ -687,7 +687,7 @@ public class ObjectService {
String checkinComment = getStringParameter(request,
Constants.PARAM_CHECKIN_COMMENT);
Boolean major = getBooleanParameter(request,
Constants.PARAM_MAJOR);
- ThresholdOutputStreamFactory streamFactory =
(ThresholdOutputStreamFactory) context
+ TempStoreOutputStreamFactory streamFactory =
(TempStoreOutputStreamFactory) context
.get(CallContext.STREAM_FACTORY);
AtomEntryParser parser = new
AtomEntryParser(request.getInputStream(), streamFactory);
@@ -801,7 +801,7 @@ public class ObjectService {
assert request != null;
assert response != null;
- ThresholdOutputStreamFactory streamFactory =
(ThresholdOutputStreamFactory) context
+ TempStoreOutputStreamFactory streamFactory =
(TempStoreOutputStreamFactory) context
.get(CallContext.STREAM_FACTORY);
AtomEntryParser parser = new AtomEntryParser(streamFactory);
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/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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -31,7 +31,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
/**
* Policy Service operations.
@@ -154,7 +154,7 @@ public class PolicyService {
// get parameters
String objectId = getStringParameter(request, Constants.PARAM_ID);
- ThresholdOutputStreamFactory streamFactory =
(ThresholdOutputStreamFactory) context
+ TempStoreOutputStreamFactory streamFactory =
(TempStoreOutputStreamFactory) context
.get(CallContext.STREAM_FACTORY);
AtomEntryParser parser = new
AtomEntryParser(request.getInputStream(), streamFactory);
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.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/RepositoryService.java?rev=1651711&r1=1651710&r2=1651711&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java
Wed Jan 14 15:44:55 2015
@@ -39,7 +39,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.server.impl.CallContextImpl;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
/**
* Repository Service operations.
@@ -484,7 +484,7 @@ public class RepositoryService {
assert response != null;
// parse entry
- ThresholdOutputStreamFactory streamFactory =
(ThresholdOutputStreamFactory) context
+ TempStoreOutputStreamFactory streamFactory =
(TempStoreOutputStreamFactory) context
.get(CallContext.STREAM_FACTORY);
AtomEntryParser parser = new AtomEntryParser(streamFactory);
parser.parse(request.getInputStream());
@@ -529,7 +529,7 @@ public class RepositoryService {
assert response != null;
// parse entry
- ThresholdOutputStreamFactory streamFactory =
(ThresholdOutputStreamFactory) context
+ TempStoreOutputStreamFactory streamFactory =
(TempStoreOutputStreamFactory) context
.get(CallContext.STREAM_FACTORY);
AtomEntryParser parser = new AtomEntryParser(streamFactory);
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/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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -33,7 +33,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
import org.apache.chemistry.opencmis.commons.spi.Holder;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
/**
* Versioning Service operations.
@@ -53,7 +53,7 @@ public class VersioningService {
assert response != null;
// get parameters
- ThresholdOutputStreamFactory streamFactory =
(ThresholdOutputStreamFactory) context
+ TempStoreOutputStreamFactory streamFactory =
(TempStoreOutputStreamFactory) context
.get(CallContext.STREAM_FACTORY);
AtomEntryParser parser = new AtomEntryParser(streamFactory);
parser.setIgnoreAtomContentSrc(true); // needed for some clients
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserCallContextImpl.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/BrowserCallContextImpl.java?rev=1651711&r1=1651710&r2=1651711&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserCallContextImpl.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserCallContextImpl.java
Wed Jan 14 15:44:55 2015
@@ -36,7 +36,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
import org.apache.chemistry.opencmis.server.impl.CallContextImpl;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
/**
* A {@link CallContext} implementation that holds browser binding specific
@@ -53,7 +53,7 @@ public class BrowserCallContextImpl exte
public BrowserCallContextImpl(String binding, CmisVersion cmisVersion,
String repositoryId,
ServletContext servletContext, HttpServletRequest request,
HttpServletResponse response,
- CmisServiceFactory factory, ThresholdOutputStreamFactory
streamFactory) {
+ CmisServiceFactory factory, TempStoreOutputStreamFactory
streamFactory) {
super(binding, cmisVersion, repositoryId, servletContext, request,
response, factory, streamFactory);
}
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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -113,6 +113,7 @@ import org.apache.chemistry.opencmis.ser
import
org.apache.chemistry.opencmis.server.shared.NoBodyHttpServletResponseWrapper;
import
org.apache.chemistry.opencmis.server.shared.QueryStringHttpServletRequestWrapper;
import org.apache.chemistry.opencmis.server.shared.ServiceCall;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -217,12 +218,20 @@ public class CmisBrowserBindingServlet e
response.addHeader("Cache-Control", "private, max-age=0");
response.addHeader("Server", ServerVersion.OPENCMIS_SERVER);
+ // split path
+ String[] pathFragments = HttpUtils.splitPath(request);
+
+ // create stream factory
+ TempStoreOutputStreamFactory streamFactoy =
TempStoreOutputStreamFactory.newInstance(getServiceFactory(),
+ pathFragments.length > 0 ? pathFragments[0] : null);
+
+ // check HTTP method
String method = request.getMethod();
if (METHOD_GET.equals(method)) {
request = new QueryStringHttpServletRequestWrapper(request);
} else if (METHOD_POST.equals(method)) {
- request = new POSTHttpServletRequestWrapper(request,
getThresholdOutputStreamFactory());
+ request = new POSTHttpServletRequestWrapper(request,
streamFactoy);
} else if (METHOD_HEAD.equals(method)) {
request = new HEADHttpServletRequestWrapper(request);
response = new NoBodyHttpServletResponseWrapper(response);
@@ -236,8 +245,8 @@ public class CmisBrowserBindingServlet e
return;
}
- context = createContext(getServletContext(), request, response);
- dispatch(context, request, response);
+ context = createContext(getServletContext(), request, response,
streamFactoy);
+ dispatch(context, request, response, pathFragments);
} catch (Exception e) {
if (e instanceof CmisUnauthorizedException) {
response.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\"");
@@ -274,8 +283,8 @@ public class CmisBrowserBindingServlet e
rootDispatcher.addResource(resource, httpMethod, serviceCall);
}
- private void dispatch(CallContext context, HttpServletRequest request,
HttpServletResponse response)
- throws Exception {
+ private void dispatch(CallContext context, HttpServletRequest request,
HttpServletResponse response,
+ String[] pathFragments) throws Exception {
BrowserCallContextImpl browserContext = (BrowserCallContextImpl)
context;
CmisService service = null;
try {
@@ -283,8 +292,6 @@ public class CmisBrowserBindingServlet e
service = getServiceFactory().getService(context);
// analyze the path
- String[] pathFragments = HttpUtils.splitPath(request);
-
if (pathFragments.length < 1) {
// root -> repository infos
repositoryDispatcher.dispatch("", METHOD_GET, context,
service, null, request, response);
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.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/MultipartParser.java?rev=1651711&r1=1651710&r2=1651711&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.java
Wed Jan 14 15:44:55 2015
@@ -35,8 +35,8 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.Constants;
import org.apache.chemistry.opencmis.commons.impl.IOUtils;
import org.apache.chemistry.opencmis.commons.impl.MimeHelper;
-import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import org.apache.chemistry.opencmis.commons.server.TempStoreOutputStream;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
/**
* Simple multi-part parser, following all necessary standards for the CMIS
@@ -57,7 +57,7 @@ public class MultipartParser {
private static final byte[] BOUNDARY_PREFIX = { CR, LF, DASH, DASH };
private final HttpServletRequest request;
- private final ThresholdOutputStreamFactory streamFactory;
+ private final TempStoreOutputStreamFactory streamFactory;
private final InputStream requestStream;
private byte[] boundary;
@@ -84,7 +84,7 @@ public class MultipartParser {
private Map<String, byte[][]> rawFields;
private String charset = IOUtils.ISO_8859_1;
- public MultipartParser(HttpServletRequest request,
ThresholdOutputStreamFactory streamFactory) throws IOException {
+ public MultipartParser(HttpServletRequest request,
TempStoreOutputStreamFactory streamFactory) throws IOException {
this.request = request;
this.streamFactory = streamFactory;
this.requestStream = request.getInputStream();
@@ -384,7 +384,7 @@ public class MultipartParser {
if (newSize < bodyBytesPos + len) {
newSize = bodyBytesPos + BUFFER_SIZE;
}
-
+
byte[] newBodyBytes = new byte[newSize];
System.arraycopy(bodyBytes, 0, newBodyBytes, 0,
bodyBytesPos);
bodyBytes = newBodyBytes;
@@ -414,7 +414,7 @@ public class MultipartParser {
}
private void readBodyAsStream() throws IOException {
- ThresholdOutputStream stream = streamFactory.newOutputStream();
+ TempStoreOutputStream stream = streamFactory.newOutputStream();
try {
while (true) {
@@ -435,12 +435,12 @@ public class MultipartParser {
stream.close();
- contentSize = BigInteger.valueOf(stream.getSize());
+ contentSize = BigInteger.valueOf(stream.getLength());
contentStream = stream.getInputStream();
} catch (IOException e) {
// if something went wrong, make sure the temp file will
// be deleted
- stream.destroy();
+ stream.destroy(e);
throw e;
}
}
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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -34,7 +34,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.IOUtils;
import org.apache.chemistry.opencmis.server.shared.HttpUtils;
import
org.apache.chemistry.opencmis.server.shared.QueryStringHttpServletRequestWrapper;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
public final class POSTHttpServletRequestWrapper extends
QueryStringHttpServletRequestWrapper {
@@ -49,7 +49,7 @@ public final class POSTHttpServletReques
private InputStream stream;
@SuppressWarnings("unchecked")
- public POSTHttpServletRequestWrapper(HttpServletRequest request,
ThresholdOutputStreamFactory streamFactory)
+ public POSTHttpServletRequestWrapper(HttpServletRequest request,
TempStoreOutputStreamFactory streamFactory)
throws IOException {
super(request);
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.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/AbstractService.java?rev=1651711&r1=1651710&r2=1651711&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.java
Wed Jan 14 15:44:55 2015
@@ -56,6 +56,7 @@ import org.apache.chemistry.opencmis.ser
import org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener;
import org.apache.chemistry.opencmis.server.impl.ServerVersion;
import org.apache.chemistry.opencmis.server.shared.ExceptionHelper;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;
@@ -108,8 +109,9 @@ public abstract class AbstractService {
throw new CmisRuntimeException("Server configuration issue. CMIS
version not set!");
}
+ TempStoreOutputStreamFactory streamFactoy =
TempStoreOutputStreamFactory.newInstance(factory, repositoryId);
CallContextImpl context = new
CallContextImpl(CallContext.BINDING_WEBSERVICES, cmisVersion, repositoryId,
- servletContext, request, response, factory, null);
+ servletContext, request, response, factory, streamFactoy);
Map<String, List<String>> headers = (Map<String, List<String>>)
wsContext.getMessageContext().get(
MessageContext.HTTP_REQUEST_HEADERS);
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.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/AbstractCmisHttpServlet.java?rev=1651711&r1=1651710&r2=1651711&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.java
Wed Jan 14 15:44:55 2015
@@ -47,7 +47,6 @@ public abstract class AbstractCmisHttpSe
private String binding;
private CmisVersion cmisVersion;
private CallContextHandler callContextHandler;
- private ThresholdOutputStreamFactory streamFactory;
@Override
public void init(ServletConfig config) throws ServletException {
@@ -72,10 +71,6 @@ public abstract class AbstractCmisHttpSe
if (factory == null) {
throw new ServletException("Service factory not available!
Configuration problem?");
}
-
- // set up stream factory
- streamFactory =
ThresholdOutputStreamFactory.newInstance(factory.getTempDirectory(),
- factory.getMemoryThreshold(), factory.getMaxContentSize(),
factory.encryptTempFiles());
}
/**
@@ -111,17 +106,10 @@ public abstract class AbstractCmisHttpSe
}
/**
- * Returns the {@link ThresholdOutputStreamFactory}.
- */
- protected ThresholdOutputStreamFactory getThresholdOutputStreamFactory() {
- return streamFactory;
- }
-
- /**
* Creates a {@link CallContext} object from a servlet request.
*/
protected CallContext createContext(ServletContext servletContext,
HttpServletRequest request,
- HttpServletResponse response) {
+ HttpServletResponse response, TempStoreOutputStreamFactory
streamFactory) {
String[] pathFragments = HttpUtils.splitPath(request);
String repositoryId = null;
Added:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/TempStoreOutputStreamFactory.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/TempStoreOutputStreamFactory.java?rev=1651711&view=auto
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/TempStoreOutputStreamFactory.java
(added)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/TempStoreOutputStreamFactory.java
Wed Jan 14 15:44:55 2015
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.server.shared;
+
+import java.io.File;
+
+import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
+import org.apache.chemistry.opencmis.commons.server.TempStoreOutputStream;
+
+/**
+ * A factory for {@link TempStoreOutputStream} objects.
+ */
+public class TempStoreOutputStreamFactory {
+
+ private CmisServiceFactory factory;
+ private String repositoryId;
+
+ private File tempDir;
+ private int memoryThreshold;
+ private long maxContentSize;
+ private boolean encrypt;
+
+ protected TempStoreOutputStreamFactory(CmisServiceFactory factory, String
repositoryId) {
+ this.factory = factory;
+ this.repositoryId = repositoryId;
+ this.tempDir = factory.getTempDirectory();
+ this.memoryThreshold = factory.getMemoryThreshold();
+ this.maxContentSize = factory.getMaxContentSize();
+ this.encrypt = factory.encryptTempFiles();
+ }
+
+ protected TempStoreOutputStreamFactory(File tempDir, int memoryThreshold,
long maxContentSize, boolean encrypt) {
+ this.factory = null;
+ this.repositoryId = null;
+ this.tempDir = tempDir;
+ this.memoryThreshold = memoryThreshold;
+ this.maxContentSize = maxContentSize;
+ this.encrypt = encrypt;
+ }
+
+ /**
+ * Creates a new factory. The parameters are used to create new
+ * {@link TempStoreOutputStream} objects.
+ *
+ * @param factory
+ * the CmisService object factory
+ * @param repositoryId
+ * the repository ID
+ */
+ public static TempStoreOutputStreamFactory newInstance(CmisServiceFactory
factory, String repositoryId) {
+ return new TempStoreOutputStreamFactory(factory, repositoryId);
+ }
+
+ /**
+ * Creates a new factory. The parameters are used to create new
+ * {@link TempStoreOutputStream} objects.
+ *
+ * @param tempDir
+ * temp directory or {@code null} for the default temp directory
+ * @param memoryThreshold
+ * memory threshold in bytes
+ * @param maxContentSize
+ * max size of the content in bytes (-1 to disable the check)
+ * @param encrypt
+ * indicates if temporary files must be encrypted
+ */
+ public static TempStoreOutputStreamFactory newInstance(File tempDir, int
memoryThreshold, long maxContentSize,
+ boolean encrypt) {
+ return new TempStoreOutputStreamFactory(tempDir, memoryThreshold,
maxContentSize, encrypt);
+ }
+
+ /**
+ * Creates a new {@link TempStoreOutputStream} object.
+ */
+ public TempStoreOutputStream newOutputStream() {
+ TempStoreOutputStream stream = null;
+
+ if (factory != null) {
+ stream = factory.getTempFileOutputStream(repositoryId);
+ }
+
+ if (stream == null) {
+ stream = new ThresholdOutputStream(tempDir, memoryThreshold,
maxContentSize, encrypt);
+ }
+
+ return stream;
+ }
+
+ /**
+ * Returns the temp directory or {@code null} for the default temp
+ * directory.
+ */
+ public File getTempDir() {
+ return tempDir;
+ }
+
+ /**
+ * Returns the memory threshold in bytes.
+ */
+ public int getMemoryThreshold() {
+ return memoryThreshold;
+ }
+
+ /**
+ * Returns the max content size in bytes.
+ */
+ public long getMaxContentSize() {
+ return maxContentSize;
+ }
+
+ /**
+ * Indicates if temporary files are encrypted.
+ */
+ public boolean isEncrypted() {
+ return encrypt;
+ }
+}
Propchange:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/TempStoreOutputStreamFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -36,6 +36,7 @@ import javax.crypto.KeyGenerator;
import javax.crypto.spec.IvParameterSpec;
import
org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
+import org.apache.chemistry.opencmis.commons.server.TempStoreOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,7 +49,7 @@ import org.slf4j.LoggerFactory;
* {@link #getInputStream()} is called or call {@link #destroy()} if the
* InputStream isn't required!
*/
-public class ThresholdOutputStream extends OutputStream {
+public class ThresholdOutputStream extends TempStoreOutputStream {
private static final Logger LOG =
LoggerFactory.getLogger(ThresholdOutputStream.class);
@@ -68,7 +69,7 @@ public class ThresholdOutputStream exten
private byte[] buf = null;
private int bufSize = 0;
- private long size = 0;
+ private long length = 0;
private File tempFile;
private OutputStream tmpStream;
private Key key;
@@ -184,8 +185,8 @@ public class ThresholdOutputStream exten
}
}
- public long getSize() {
- return size;
+ public long getLength() {
+ return length;
}
@Override
@@ -200,17 +201,17 @@ public class ThresholdOutputStream exten
return;
}
- if ((maxContentSize > -1) && (size + len > maxContentSize)) {
- destroy();
+ if ((maxContentSize > -1) && (length + len > maxContentSize)) {
+ destroy(null);
throw new CmisConstraintException("Content too big!");
}
expand(len);
System.arraycopy(buffer, offset, buf, bufSize, len);
bufSize += len;
- size += len;
+ length += len;
} catch (IOException ioe) {
- destroy();
+ destroy(ioe);
if (LOG.isErrorEnabled()) {
if (tempFile != null) {
@@ -227,8 +228,8 @@ public class ThresholdOutputStream exten
@Override
public void write(int oneByte) throws IOException {
try {
- if (maxContentSize > -1 && size + 1 > maxContentSize) {
- destroy();
+ if (maxContentSize > -1 && length + 1 > maxContentSize) {
+ destroy(null);
throw new CmisConstraintException("Content too big!");
}
@@ -237,9 +238,9 @@ public class ThresholdOutputStream exten
}
buf[bufSize++] = (byte) oneByte;
- size++;
+ length++;
} catch (IOException ioe) {
- destroy();
+ destroy(ioe);
if (LOG.isErrorEnabled()) {
if (tempFile != null) {
@@ -267,7 +268,7 @@ public class ThresholdOutputStream exten
}
tmpStream.flush();
} catch (IOException ioe) {
- destroy();
+ destroy(ioe);
if (LOG.isErrorEnabled()) {
LOG.error("Flushing the temp file {} failed: {}",
tempFile.getAbsolutePath(), ioe.toString(), ioe);
@@ -290,7 +291,12 @@ public class ThresholdOutputStream exten
/**
* Destroys the object before it has been read.
*/
- public void destroy() {
+ @Override
+ public void destroy(Throwable cause) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("ThresholdOutputStream destroyed." + (cause == null ? ""
: " Cause: " + cause.toString()), cause);
+ }
+
try {
if (tmpStream != null) {
tmpStream.flush();
@@ -315,6 +321,7 @@ public class ThresholdOutputStream exten
/**
* Returns the data as an InputStream.
*/
+ @Override
public InputStream getInputStream() throws IOException {
if (tmpStream != null) {
close();
@@ -367,8 +374,8 @@ public class ThresholdOutputStream exten
*
* @return the length of the stream in bytes
*/
- public long length() {
- return size;
+ public long getLength() {
+ return length;
}
/**
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStreamFactory.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/ThresholdOutputStreamFactory.java?rev=1651711&r1=1651710&r2=1651711&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStreamFactory.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStreamFactory.java
Wed Jan 14 15:44:55 2015
@@ -22,19 +22,13 @@ import java.io.File;
/**
* A factory for {@link ThresholdOutputStream} objects.
+ *
+ * @deprecated use {@link TempStoreOutputStreamFactory}
*/
-public final class ThresholdOutputStreamFactory {
-
- private File tempDir;
- private int memoryThreshold;
- private long maxContentSize;
- private boolean encrypt;
+public final class ThresholdOutputStreamFactory extends
TempStoreOutputStreamFactory {
private ThresholdOutputStreamFactory(File tempDir, int memoryThreshold,
long maxContentSize, boolean encrypt) {
- this.tempDir = tempDir;
- this.memoryThreshold = memoryThreshold;
- this.maxContentSize = maxContentSize;
- this.encrypt = encrypt;
+ super(tempDir, memoryThreshold, maxContentSize, encrypt);
}
/**
@@ -42,8 +36,7 @@ public final class ThresholdOutputStream
* {@link ThresholdOutputStream} objects.
*
* @param tempDir
- * temp directory or <code>null</code> for the default temp
- * directory
+ * temp directory or {@code null} for the default temp directory
* @param memoryThreshold
* memory threshold in bytes
* @param maxContentSize
@@ -59,36 +52,8 @@ public final class ThresholdOutputStream
/**
* Creates a new {@link ThresholdOutputStream} object.
*/
+ @Override
public ThresholdOutputStream newOutputStream() {
- return new ThresholdOutputStream(tempDir, memoryThreshold,
maxContentSize, encrypt);
- }
-
- /**
- * Returns the temp directory or <code>null</code> for the default temp
- * directory.
- */
- public File getTempDir() {
- return tempDir;
- }
-
- /**
- * Returns the memory threshold in bytes.
- */
- public int getMemoryThreshold() {
- return memoryThreshold;
- }
-
- /**
- * Returns the max content size in bytes.
- */
- public long getMaxContentSize() {
- return maxContentSize;
- }
-
- /**
- * Indicates if temporary files are encrypted.
- */
- public boolean isEncrypted() {
- return encrypt;
+ return new ThresholdOutputStream(getTempDir(), getMemoryThreshold(),
getMaxContentSize(), isEncrypted());
}
}
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=1651711&r1=1651710&r2=1651711&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
Wed Jan 14 15:44:55 2015
@@ -35,7 +35,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.Base64;
import org.apache.chemistry.opencmis.commons.impl.IOUtils;
import org.apache.chemistry.opencmis.server.impl.atompub.AtomEntryParser;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
import org.junit.Test;
/**
@@ -177,7 +177,7 @@ public class AtomEntryParserTest {
@Test
public void testAtomTitle() throws Exception {
- ThresholdOutputStreamFactory streamFactory =
ThresholdOutputStreamFactory.newInstance(null, THRESHOLD,
+ TempStoreOutputStreamFactory streamFactory =
TempStoreOutputStreamFactory.newInstance(null, THRESHOLD,
MAX_SIZE, false);
AtomEntryParser aep = new AtomEntryParser(new
ByteArrayInputStream(ATOM_ENTRY_NAME.getBytes()), streamFactory);
@@ -195,7 +195,7 @@ public class AtomEntryParserTest {
@Test
public void testNullStream() throws Exception {
- ThresholdOutputStreamFactory streamFactory =
ThresholdOutputStreamFactory.newInstance(null, THRESHOLD,
+ TempStoreOutputStreamFactory streamFactory =
TempStoreOutputStreamFactory.newInstance(null, THRESHOLD,
MAX_SIZE, false);
AtomEntryParser aep = new AtomEntryParser(null, streamFactory);
@@ -208,7 +208,7 @@ public class AtomEntryParserTest {
@Test(expected = XMLStreamException.class)
public void testEmptyStream() throws Exception {
- ThresholdOutputStreamFactory streamFactory =
ThresholdOutputStreamFactory.newInstance(null, THRESHOLD,
+ TempStoreOutputStreamFactory streamFactory =
TempStoreOutputStreamFactory.newInstance(null, THRESHOLD,
MAX_SIZE, false);
new AtomEntryParser(new ByteArrayInputStream(new byte[0]),
streamFactory);
}
@@ -232,7 +232,7 @@ public class AtomEntryParserTest {
System.arraycopy(end, 0, entry, entry.length - end.length, end.length);
Arrays.fill(entry, begin.length, entry.length - end.length, (byte)
'a');
- ThresholdOutputStreamFactory streamFactory =
ThresholdOutputStreamFactory.newInstance(null, THRESHOLD,
+ TempStoreOutputStreamFactory streamFactory =
TempStoreOutputStreamFactory.newInstance(null, THRESHOLD,
MAX_SIZE, false);
AtomEntryParser aep = new AtomEntryParser(new
ByteArrayInputStream(entry), streamFactory);
ContentStream contentStream = aep.getContentStream();
@@ -244,7 +244,7 @@ public class AtomEntryParserTest {
}
private static byte[] parse(byte[] entry) throws Exception {
- ThresholdOutputStreamFactory streamFactory =
ThresholdOutputStreamFactory.newInstance(null, THRESHOLD,
+ TempStoreOutputStreamFactory streamFactory =
TempStoreOutputStreamFactory.newInstance(null, THRESHOLD,
MAX_SIZE, false);
AtomEntryParser aep = new AtomEntryParser(new
ByteArrayInputStream(entry), streamFactory);
ContentStream contentStream = aep.getContentStream();
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/MultipartParserTest.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/MultipartParserTest.java?rev=1651711&r1=1651710&r2=1651711&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/MultipartParserTest.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/MultipartParserTest.java
Wed Jan 14 15:44:55 2015
@@ -36,7 +36,7 @@ import javax.servlet.http.HttpServletReq
import
org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.impl.IOUtils;
import org.apache.chemistry.opencmis.server.impl.browser.MultipartParser;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
import org.junit.Test;
/**
@@ -410,7 +410,7 @@ public class MultipartParserTest {
private MultipartParser prepareParser(String boundary, byte[] content)
throws Exception {
HttpServletRequest request =
HttpRequestMockHelper.createMultipartRequest(boundary, content);
- ThresholdOutputStreamFactory streamFactory =
ThresholdOutputStreamFactory.newInstance(null, THRESHOLD,
+ TempStoreOutputStreamFactory streamFactory =
TempStoreOutputStreamFactory.newInstance(null, THRESHOLD,
MAX_SIZE, false);
return new MultipartParser(request, streamFactory);
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.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/ThresholdOutputStreamTest.java?rev=1651711&r1=1651710&r2=1651711&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
Wed Jan 14 15:44:55 2015
@@ -27,9 +27,10 @@ import static org.junit.Assert.fail;
import java.io.File;
+import org.apache.chemistry.opencmis.commons.server.TempStoreOutputStream;
+import
org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream;
import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream.ThresholdInputStream;
-import
org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
import org.junit.Test;
public class ThresholdOutputStreamTest {
@@ -38,10 +39,13 @@ public class ThresholdOutputStreamTest {
@Test
public void testInMemory() throws Exception {
- ThresholdOutputStreamFactory streamFactory =
ThresholdOutputStreamFactory.newInstance(null, 1024, 1024, false);
+ TempStoreOutputStreamFactory streamFactory =
TempStoreOutputStreamFactory.newInstance(null, 1024, 1024, false);
+
+ TempStoreOutputStream tempStream = streamFactory.newOutputStream();
+ assertTrue(tempStream instanceof ThresholdOutputStream);
// set content
- ThresholdOutputStream tos = streamFactory.newOutputStream();
+ ThresholdOutputStream tos = (ThresholdOutputStream) tempStream;
tos.write(CONTENT);
tos.close();
@@ -51,8 +55,8 @@ public class ThresholdOutputStreamTest {
assertTrue(tis.isInMemory());
assertNull(tis.getTemporaryFile());
assertTrue(tis.markSupported());
- assertEquals(CONTENT.length, tis.length());
- assertArrayEquals(CONTENT, getBytesFromArray(tis.getBytes(), (int)
tis.length()));
+ assertEquals(CONTENT.length, tis.getLength());
+ assertArrayEquals(CONTENT, getBytesFromArray(tis.getBytes(), (int)
tis.getLength()));
// read stream
byte[] buffer = new byte[CONTENT.length];
@@ -91,10 +95,13 @@ public class ThresholdOutputStreamTest {
@Test
public void testTempFile() throws Exception {
- ThresholdOutputStreamFactory streamFactory =
ThresholdOutputStreamFactory.newInstance(null, 0, 1024, false);
+ TempStoreOutputStreamFactory streamFactory =
TempStoreOutputStreamFactory.newInstance(null, 0, 1024, false);
+
+ TempStoreOutputStream tempStream = streamFactory.newOutputStream();
+ assertTrue(tempStream instanceof ThresholdOutputStream);
// set content
- ThresholdOutputStream tos = streamFactory.newOutputStream();
+ ThresholdOutputStream tos = (ThresholdOutputStream) tempStream;
tos.write(CONTENT);
tos.close();
@@ -104,7 +111,7 @@ public class ThresholdOutputStreamTest {
assertFalse(tis.isInMemory());
assertTrue(tis.markSupported());
assertNull(tis.getBytes());
- assertEquals(CONTENT.length, tis.length());
+ assertEquals(CONTENT.length, tis.getLength());
assertTrue(tis.getTemporaryFile().exists());
assertEquals(CONTENT.length, tis.getTemporaryFile().length());
@@ -153,11 +160,14 @@ public class ThresholdOutputStreamTest {
public void testThreshold() throws Exception {
int threshold = 8;
- ThresholdOutputStreamFactory streamFactory =
ThresholdOutputStreamFactory.newInstance(null, threshold, 1024,
+ TempStoreOutputStreamFactory streamFactory =
TempStoreOutputStreamFactory.newInstance(null, threshold, 1024,
false);
for (int i = 0; i < 20; i++) {
- ThresholdOutputStream tos = streamFactory.newOutputStream();
+ TempStoreOutputStream tempStream = streamFactory.newOutputStream();
+ assertTrue(tempStream instanceof ThresholdOutputStream);
+
+ ThresholdOutputStream tos = (ThresholdOutputStream) tempStream;
for (int j = 0; j < i; j++) {
tos.write('0' + j);
}