You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2008/08/12 21:02:11 UTC
svn commit: r685266 - in /cxf/branches/2.0.x-fixes: ./
api/src/main/java/org/apache/cxf/io/
rt/core/src/main/java/org/apache/cxf/attachment/
systests/src/test/java/org/apache/cxf/systest/mtom/
Author: dkulp
Date: Tue Aug 12 12:02:10 2008
New Revision: 685266
URL: http://svn.apache.org/viewvc?rev=685266&view=rev
Log:
Merged revisions 685253 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r685253 | dkulp | 2008-08-12 14:20:19 -0400 (Tue, 12 Aug 2008) | 2 lines
[CXF-1743] Fix attachment caching to make sure temp files are deleted properly
........
Modified:
cxf/branches/2.0.x-fixes/ (props changed)
cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
Propchange: cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 12 12:02:10 2008
@@ -1 +1 @@
-/cxf/trunk:673548,674485,674547,674551,674562,674601,674649,674764,674887,675644,675653,677048,677385,678004,678009,678559,678629,678808,678852,678891,678893,679248,679597,680435,681060,681165,681813,681816,682902,682951,683089,683290,683318,684099,684790-684793,684842,684862,684895-684918,685205
+/cxf/trunk:673548,674485,674547,674551,674562,674601,674649,674764,674887,675644,675653,677048,677385,678004,678009,678559,678629,678808,678852,678891,678893,679248,679597,680435,681060,681165,681813,681816,682902,682951,683089,683290,683318,684099,684790-684793,684842,684862,684895-684918,685205,685253
Propchange: cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Aug 12 12:02:10 2008
@@ -1 +1 @@
-/cxf/trunk:1-684881,684883-684884,684886-684888,684890-684892,684894-684923,685205
+/cxf/trunk:1-684881,684883-684884,684886-684888,684890-684892,684894-684923,685205,685253
Modified: cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=685266&r1=685265&r2=685266&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java (original)
+++ cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Tue Aug 12 12:02:10 2008
@@ -64,6 +64,7 @@
}
}
+ protected boolean outputLocked;
protected OutputStream currentStream;
private long threshold = DEFAULT_THRESHOLD;
@@ -145,6 +146,17 @@
}
+ /**
+ * Locks the output stream to prevent additional writes, but maintains
+ * a pointer to it so an InputStream can be obtained
+ * @throws IOException
+ */
+ public void lockOutputStream() throws IOException {
+ currentStream.flush();
+ outputLocked = true;
+ streamList.remove(currentStream);
+ }
+
public void close() throws IOException {
currentStream.flush();
if (null != callbacks) {
@@ -152,7 +164,6 @@
cb.onClose(this);
}
}
-
doClose();
currentStream.close();
maybeDeleteTempFile(currentStream);
@@ -205,6 +216,7 @@
}
}
currentStream = out;
+ outputLocked = false;
}
public static void copyStream(InputStream in, OutputStream out, int bufferSize) throws IOException {
@@ -331,30 +343,36 @@
}
public void write(byte[] b, int off, int len) throws IOException {
- onWrite();
- this.totalLength += len;
- if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
- createFileOutputStream();
+ if (!outputLocked) {
+ onWrite();
+ this.totalLength += len;
+ if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
+ createFileOutputStream();
+ }
+ currentStream.write(b, off, len);
}
- currentStream.write(b, off, len);
}
public void write(byte[] b) throws IOException {
- onWrite();
- this.totalLength += b.length;
- if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
- createFileOutputStream();
+ if (!outputLocked) {
+ onWrite();
+ this.totalLength += b.length;
+ if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
+ createFileOutputStream();
+ }
+ currentStream.write(b);
}
- currentStream.write(b);
}
public void write(int b) throws IOException {
- onWrite();
- this.totalLength++;
- if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
- createFileOutputStream();
+ if (!outputLocked) {
+ onWrite();
+ this.totalLength++;
+ if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
+ createFileOutputStream();
+ }
+ currentStream.write(b);
}
- currentStream.write(b);
}
private void createFileOutputStream() throws IOException {
Modified: cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java?rev=685266&r1=685265&r2=685266&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java (original)
+++ cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java Tue Aug 12 12:02:10 2008
@@ -37,6 +37,7 @@
this.ct = ctParam;
cache = new CachedOutputStream();
IOUtils.copy(inParam, cache);
+ cache.lockOutputStream();
}
public String getContentType() {
Modified: cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=685266&r1=685265&r2=685266&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java (original)
+++ cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java Tue Aug 12 12:02:10 2008
@@ -212,7 +212,10 @@
for (Attachment a : attachments.getLoadedAttachments()) {
DataSource s = a.getDataHandler().getDataSource();
- cache((DelegatingInputStream) s.getInputStream(), false);
+ if (!(s instanceof AttachmentDataSource)) {
+ //AttachementDataSource objects are already cached
+ cache((DelegatingInputStream) s.getInputStream(), false);
+ }
}
}
@@ -222,11 +225,13 @@
}
loaded.add(input);
CachedOutputStream out = null;
+ InputStream origIn = input.getInputStream();
try {
out = new CachedOutputStream();
setStreamedAttachmentProperties(out);
IOUtils.copy(input, out);
input.setInputStream(out.getInputStream());
+ origIn.close();
} finally {
if (out != null) {
out.close();
Modified: cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java?rev=685266&r1=685265&r2=685266&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java (original)
+++ cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java Tue Aug 12 12:02:10 2008
@@ -57,7 +57,7 @@
@BeforeClass
public static void startServers() throws Exception {
TestUtilities.setKeepAliveSystemProperty(false);
- assertTrue("server did not launch correctly", launchServer(Server.class));
+ assertTrue("server did not launch correctly", launchServer(Server.class, true));
}
@AfterClass
@@ -100,19 +100,27 @@
TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT, TestMtom.class, true);
try {
InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl");
- long fileSize = 0;
+ int fileSize = 0;
for (int i = pre.read(); i != -1; i = pre.read()) {
fileSize++;
}
Holder<DataHandler> param = new Holder<DataHandler>();
- byte[] data = new byte[(int) fileSize];
- this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data);
+
+ int count = 50;
+ byte[] data = new byte[fileSize * count];
+ for (int x = 0; x < count; x++) {
+ this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data,
+ fileSize * x,
+ fileSize);
+ }
param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
Holder<String> name = new Holder<String>("call detail");
mtomPort.testXop(name, param);
assertEquals("name unchanged", "return detail + call detail", name.value);
assertNotNull(param.value);
+ param.value.getInputStream().close();
+
} catch (UndeclaredThrowableException ex) {
throw (Exception) ex.getCause();
}