Author: fmui
Date: Tue Dec 16 12:49:20 2014
New Revision: 1645931
URL: http://svn.apache.org/r1645931
Log:
Server: Web Services: close stream if possible
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/WSConverter.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/ObjectService.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/VersioningService.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/WSConverter.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/WSConverter.java?rev=1645931&r1=1645930&r2=1645931&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/WSConverter.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/WSConverter.java
Tue Dec 16 12:49:20 2014
@@ -22,6 +22,7 @@ import static org.apache.chemistry.openc
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
+import java.io.Closeable;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -281,24 +282,30 @@ public final class WSConverter {
private static Class<?> streamDataHandlerClass1;
private static Method streamDataHandlerReadMethod1;
+ private static Method streamDataHandlerCloseMethod1;
private static Class<?> streamDataHandlerClass2;
private static Method streamDataHandlerReadMethod2;
+ private static Method streamDataHandlerCloseMethod2;
static {
try {
streamDataHandlerClass1 =
Class.forName("org.jvnet.staxex.StreamingDataHandler");
streamDataHandlerReadMethod1 =
streamDataHandlerClass1.getMethod("readOnce", new Class<?>[0]);
+ streamDataHandlerCloseMethod1 =
streamDataHandlerClass1.getMethod("close", new Class<?>[0]);
} catch (Exception e) {
streamDataHandlerClass1 = null;
streamDataHandlerReadMethod1 = null;
+ streamDataHandlerCloseMethod1 = null;
}
try {
streamDataHandlerClass2 =
Class.forName("com.sun.xml.internal.org.jvnet.staxex.StreamingDataHandler");
streamDataHandlerReadMethod2 =
streamDataHandlerClass2.getMethod("readOnce", new Class<?>[0]);
+ streamDataHandlerCloseMethod2 =
streamDataHandlerClass1.getMethod("close", new Class<?>[0]);
} catch (Exception e) {
streamDataHandlerClass2 = null;
streamDataHandlerReadMethod2 = null;
+ streamDataHandlerCloseMethod2 = null;
}
}
@@ -2645,6 +2652,33 @@ public final class WSConverter {
return result;
}
+ public static void closeStream(CmisContentStreamType contentStream) {
+ if (contentStream == null) {
+ return;
+ }
+
+ DataHandler streamDataHandler = contentStream.getStream();
+
+ if (streamDataHandler != null) {
+ try {
+ if (streamDataHandler instanceof Closeable) {
+ ((Closeable) streamDataHandler).close();
+ } else {
+ if (streamDataHandlerClass1 != null &&
streamDataHandlerClass1.isInstance(streamDataHandler)) {
+
streamDataHandlerCloseMethod1.invoke(streamDataHandler, (Object[]) null);
+ } else if (streamDataHandlerClass2 != null &&
streamDataHandlerClass2.isInstance(streamDataHandler)) {
+
streamDataHandlerCloseMethod2.invoke(streamDataHandler, (Object[]) null);
+ }
+ }
+ } catch (Exception e) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Closing the stream failed: " + e.toString(), e);
+ }
+ }
+ }
+
+ }
+
/**
* Converts a content stream object.
*/
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/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/webservices/ObjectService.java?rev=1645931&r1=1645930&r2=1645931&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/ObjectService.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/ObjectService.java
Tue Dec 16 12:49:20 2014
@@ -18,6 +18,7 @@
*/
package org.apache.chemistry.opencmis.server.impl.webservices;
+import static
org.apache.chemistry.opencmis.commons.impl.WSConverter.closeStream;
import static org.apache.chemistry.opencmis.commons.impl.WSConverter.convert;
import static
org.apache.chemistry.opencmis.commons.impl.WSConverter.convertExtensionHolder;
import static
org.apache.chemistry.opencmis.commons.impl.WSConverter.convertHolder;
@@ -93,6 +94,8 @@ public class ObjectService extends Abstr
convert(contentStream, false),
convert(VersioningState.class, versioningState), policies,
convert(addAces, null), convert(removeAces, null),
extData);
+ closeStream(contentStream);
+
if (stopAfterService(service)) {
return;
}
@@ -565,6 +568,8 @@ public class ObjectService extends Abstr
service.setContentStream(repositoryId, objectIdHolder,
overwriteFlag, changeTokenHolder,
convert(contentStream, false), extData);
+ closeStream(contentStream);
+
if (stopAfterService(service)) {
return;
}
@@ -597,6 +602,8 @@ public class ObjectService extends Abstr
service.appendContentStream(repositoryId, objectIdHolder,
changeTokenHolder, convert(contentStream, true),
isLastChunk, extData);
+ closeStream(contentStream);
+
if (stopAfterService(service)) {
return;
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/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/webservices/VersioningService.java?rev=1645931&r1=1645930&r2=1645931&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/VersioningService.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/VersioningService.java
Tue Dec 16 12:49:20 2014
@@ -18,6 +18,7 @@
*/
package org.apache.chemistry.opencmis.server.impl.webservices;
+import static
org.apache.chemistry.opencmis.commons.impl.WSConverter.closeStream;
import static org.apache.chemistry.opencmis.commons.impl.WSConverter.convert;
import static
org.apache.chemistry.opencmis.commons.impl.WSConverter.convertExtensionHolder;
import static
org.apache.chemistry.opencmis.commons.impl.WSConverter.convertHolder;
@@ -104,6 +105,8 @@ public class VersioningService extends A
service.checkIn(repositoryId, objectIdHolder, major,
convert(properties), convert(contentStream, false),
checkinComment, policies, convert(addAces, null),
convert(removeAces, null), extData);
+ closeStream(contentStream);
+
if (stopAfterService(service)) {
return;
}