/** * Exception tolerant roll back method * * @throws Throwable */ protected void rollbackFileMove(File sourceFile, String destinationFilePath) throws IOException { try { FileUtils.moveFile(sourceFile, FileUtils.newFile(destinationFilePath)); } catch (IOException t) { logger.debug("rollback of file move failed: " + t.getMessage()); throw t; } }
private void moveOrDelete(final File sourceFile, File destinationFile) throws DefaultMuleException { if (destinationFile != null) { // move sourceFile to new destination try { FileUtils.moveFile(sourceFile, destinationFile); } catch (IOException e) { throw new DefaultMuleException(FileMessages.failedToMoveFile(sourceFile.getAbsolutePath(), destinationFile.getAbsolutePath())); } } if (fileConnector.isAutoDelete()) { // no moveTo directory if (destinationFile == null) { // delete source if (!sourceFile.delete()) { throw new DefaultMuleException(FileMessages.failedToDeleteFile(sourceFile)); } } } }
private void moveAndDelete(final File sourceFile, File destinationFile, String originalSourceFileName, String originalSourceDirectory, MuleMessage message) throws MuleException { // If we are moving the file to a read directory, move it there now and // hand over a reference to the // File in its moved location if (destinationFile != null) { // move sourceFile to new destination try { FileUtils.moveFile(sourceFile, destinationFile); } catch (IOException e) { // move didn't work - bail out (will attempt rollback) throw new DefaultMuleException(FileMessages.failedToMoveFile( sourceFile.getAbsolutePath(), destinationFile.getAbsolutePath())); } // create new Message for destinationFile message = createMuleMessage(destinationFile, endpoint.getEncoding()); message.setProperty(FileConnector.PROPERTY_FILENAME, destinationFile.getName(), PropertyScope.INBOUND); message.setProperty(FileConnector.PROPERTY_ORIGINAL_FILENAME, originalSourceFileName, PropertyScope.INBOUND); message.setProperty(FileConnector.PROPERTY_ORIGINAL_DIRECTORY, originalSourceDirectory, PropertyScope.INBOUND); } // finally deliver the file message this.routeMessage(message); }