You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by lh...@apache.org on 2009/04/20 23:41:32 UTC

svn commit: r766892 - in /servicemix/components/bindings/servicemix-vfs/trunk: pom.xml src/main/java/org/apache/servicemix/vfs/VFSSendingEndpoint.java

Author: lhein
Date: Mon Apr 20 21:41:31 2009
New Revision: 766892

URL: http://svn.apache.org/viewvc?rev=766892&view=rev
Log:
applied patch (see SMXCOMP-55) for determining the temp file name

Modified:
    servicemix/components/bindings/servicemix-vfs/trunk/pom.xml
    servicemix/components/bindings/servicemix-vfs/trunk/src/main/java/org/apache/servicemix/vfs/VFSSendingEndpoint.java

Modified: servicemix/components/bindings/servicemix-vfs/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-vfs/trunk/pom.xml?rev=766892&r1=766891&r2=766892&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-vfs/trunk/pom.xml (original)
+++ servicemix/components/bindings/servicemix-vfs/trunk/pom.xml Mon Apr 20 21:41:31 2009
@@ -41,7 +41,7 @@
   <properties>
     <previous.releases>3.1.2,3.2,3.2.1,3.2.2,3.2.3,2008.01</previous.releases>
     <servicemix-version>3.3</servicemix-version>
-    <servicemix-shared-version>2009.01</servicemix-shared-version>
+    <servicemix-shared-version>2009.02-SNAPSHOT</servicemix-shared-version>
 
       <servicemix.osgi.import>
           org.apache.servicemix;resolution:=optional,

Modified: servicemix/components/bindings/servicemix-vfs/trunk/src/main/java/org/apache/servicemix/vfs/VFSSendingEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-vfs/trunk/src/main/java/org/apache/servicemix/vfs/VFSSendingEndpoint.java?rev=766892&r1=766891&r2=766892&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-vfs/trunk/src/main/java/org/apache/servicemix/vfs/VFSSendingEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-vfs/trunk/src/main/java/org/apache/servicemix/vfs/VFSSendingEndpoint.java Mon Apr 20 21:41:31 2009
@@ -60,22 +60,34 @@
         }
     }
     
-    /* (non-Javadoc)
-     * @see org.apache.servicemix.common.endpoints.ProviderEndpoint#process(javax.jbi.messaging.MessageExchange)
-     */
     @Override
-    public void process(MessageExchange exchange) throws Exception {
-        NormalizedMessage message =exchange.getMessage("in");
+    protected void processInOnly(MessageExchange exchange, NormalizedMessage in)
+    		throws Exception {
         OutputStream out = null;
+        String tmpName = null;
+        String name = null;
+        FileObject tmpFile = null;
+        FileObject newFile = null;
+        FileContent content = null;
         try {
-            String name = marshaler.getOutputName(exchange, message);
+            name = marshaler.getOutputName(exchange, in);
             if (name == null) {
                 throw new MessagingException("No output name available. Cannot output message!");
             }
+            tmpName = marshaler.getTempOutputName(exchange, in);
             file.close(); // remove any cached informations
-            FileObject newFile = file.resolveFile(name);
-            newFile.close(); // remove any cached informations
-            FileContent content = newFile.getContent();
+            if (tmpName != null) {
+            	// writing to temp file first
+            	tmpFile = tmpName != null ? file.resolveFile(tmpName) : null;
+                tmpFile.close();
+                content = tmpFile.getContent();
+            } else {
+            	// writing to target file
+            	newFile = file.resolveFile(name);
+            	newFile.close(); // remove any cached informations
+                content = newFile.getContent();
+            }
+            // remove any cached informations
             content.close();
             if (content != null) {
                 out = content.getOutputStream();
@@ -83,8 +95,7 @@
             if (out == null) {
                 throw new MessagingException("No output stream available for output name: " + name);
             }
-            marshaler.writeMessage(exchange, message, out, name);
-            done(exchange);
+            marshaler.writeMessage(exchange, in, out, name);
         }
         finally {
             if (out != null) {
@@ -95,6 +106,13 @@
                     logger.error("Caught exception while closing stream on error: " + e, e);
                 }
             }
+            if (name != null && !name.equals(tmpName)) {
+            	if (!tmpFile.canRenameTo(newFile)) {
+            		throw new IOException("File " + tmpName + " could not be renamed to " + name);
+            	} else {
+            		tmpFile.moveTo(newFile);
+            	}
+            }
         }
     }