You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2007/07/18 08:38:53 UTC
svn commit: r557174 -
/incubator/servicemix/branches/servicemix-3.1/deployables/bindingcomponents/servicemix-file/src/main/java/org/apache/servicemix/file/FileSenderEndpoint.java
Author: gertv
Date: Tue Jul 17 23:38:53 2007
New Revision: 557174
URL: http://svn.apache.org/viewvc?view=rev&rev=557174
Log:
Fix for SM-1006: 0 byte files written when message contains invalid content
Modified:
incubator/servicemix/branches/servicemix-3.1/deployables/bindingcomponents/servicemix-file/src/main/java/org/apache/servicemix/file/FileSenderEndpoint.java
Modified: incubator/servicemix/branches/servicemix-3.1/deployables/bindingcomponents/servicemix-file/src/main/java/org/apache/servicemix/file/FileSenderEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.1/deployables/bindingcomponents/servicemix-file/src/main/java/org/apache/servicemix/file/FileSenderEndpoint.java?view=diff&rev=557174&r1=557173&r2=557174
==============================================================================
--- incubator/servicemix/branches/servicemix-3.1/deployables/bindingcomponents/servicemix-file/src/main/java/org/apache/servicemix/file/FileSenderEndpoint.java (original)
+++ incubator/servicemix/branches/servicemix-3.1/deployables/bindingcomponents/servicemix-file/src/main/java/org/apache/servicemix/file/FileSenderEndpoint.java Tue Jul 17 23:38:53 2007
@@ -64,9 +64,10 @@
protected void processInOnly(MessageExchange exchange, NormalizedMessage in) throws Exception {
OutputStream out = null;
+ File newFile = null;
+ boolean success = false;
try {
String name = marshaler.getOutputName(exchange, in);
- File newFile = null;
if (name == null) {
newFile = File.createTempFile(tempFilePrefix, tempFileSuffix, directory);
}
@@ -78,14 +79,20 @@
}
out = new BufferedOutputStream(new FileOutputStream(newFile));
marshaler.writeMessage(exchange, in, out, name);
- }
- finally {
+ success = true;
+ } finally {
if (out != null) {
try {
out.close();
- }
- catch (IOException e) {
+ } catch (IOException e) {
logger.error("Caught exception while closing stream on error: " + e, e);
+ }
+ }
+ //cleaning up incomplete files after things went wrong
+ if (!success) {
+ logger.debug("An error occurred while writing file " + newFile.getCanonicalPath() + ", deleting the invalid file");
+ if (!newFile.delete()) {
+ logger.warn("Unable to delete the file " + newFile.getCanonicalPath() + " after an error had occurred");
}
}
}