Search in sources :

Example 1 with AbstractFileInfo

use of org.springframework.integration.file.remote.AbstractFileInfo in project spring-integration by spring-projects.

the class AbstractRemoteFileOutboundGateway method mGetWithoutRecursion.

private List<File> mGetWithoutRecursion(Message<?> message, Session<F> session, String remoteDirectory, String remoteFilename) throws IOException {
    List<File> files = new ArrayList<File>();
    String remotePath = buildRemotePath(remoteDirectory, remoteFilename);
    @SuppressWarnings("unchecked") List<AbstractFileInfo<F>> remoteFiles = (List<AbstractFileInfo<F>>) ls(message, session, remotePath);
    if (remoteFiles.size() == 0 && this.options.contains(Option.EXCEPTION_WHEN_EMPTY)) {
        throw new MessagingException("No files found at " + (remoteDirectory != null ? remoteDirectory : "Client Working Directory") + " with pattern " + remoteFilename);
    }
    try {
        for (AbstractFileInfo<F> lsEntry : remoteFiles) {
            if (lsEntry.isDirectory()) {
                continue;
            }
            String fullFileName = remoteDirectory != null ? remoteDirectory + getFilename(lsEntry) : getFilename(lsEntry);
            /*
				 * With recursion, the filename might contain subdirectory information
				 * normalize each file separately.
				 */
            String fileName = this.getRemoteFilename(fullFileName);
            String actualRemoteDirectory = this.getRemoteDirectory(fullFileName, fileName);
            File file = get(message, session, actualRemoteDirectory, fullFileName, fileName, lsEntry.getFileInfo());
            if (file != null) {
                files.add(file);
            }
        }
    } catch (Exception e) {
        if (files.size() > 0) {
            throw new PartialSuccessException(message, "Partially successful recursive 'mget' operation on " + (remoteDirectory != null ? remoteDirectory : "Client Working Directory"), e, files, remoteFiles);
        } else if (e instanceof MessagingException) {
            throw (MessagingException) e;
        } else if (e instanceof IOException) {
            throw (IOException) e;
        }
    }
    return files;
}
Also used : MessagingException(org.springframework.messaging.MessagingException) ArrayList(java.util.ArrayList) PartialSuccessException(org.springframework.integration.support.PartialSuccessException) IOException(java.io.IOException) MessagingException(org.springframework.messaging.MessagingException) MessageHandlingException(org.springframework.messaging.MessageHandlingException) IOException(java.io.IOException) PartialSuccessException(org.springframework.integration.support.PartialSuccessException) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) AbstractFileInfo(org.springframework.integration.file.remote.AbstractFileInfo)

Example 2 with AbstractFileInfo

use of org.springframework.integration.file.remote.AbstractFileInfo in project spring-integration by spring-projects.

the class AbstractRemoteFileOutboundGateway method mGetWithRecursion.

private List<File> mGetWithRecursion(Message<?> message, Session<F> session, String remoteDirectory, String remoteFilename) throws IOException {
    List<File> files = new ArrayList<File>();
    @SuppressWarnings("unchecked") List<AbstractFileInfo<F>> fileNames = (List<AbstractFileInfo<F>>) ls(message, session, remoteDirectory);
    if (fileNames.size() == 0 && this.options.contains(Option.EXCEPTION_WHEN_EMPTY)) {
        throw new MessagingException("No files found at " + (remoteDirectory != null ? remoteDirectory : "Client Working Directory") + " with pattern " + remoteFilename);
    }
    try {
        for (AbstractFileInfo<F> lsEntry : fileNames) {
            String fullFileName = remoteDirectory != null ? remoteDirectory + getFilename(lsEntry) : getFilename(lsEntry);
            /*
				 * With recursion, the filename might contain subdirectory information
				 * normalize each file separately.
				 */
            String fileName = this.getRemoteFilename(fullFileName);
            String actualRemoteDirectory = this.getRemoteDirectory(fullFileName, fileName);
            File file = get(message, session, actualRemoteDirectory, fullFileName, fileName, lsEntry.getFileInfo());
            if (file != null) {
                files.add(file);
            }
        }
    } catch (Exception e) {
        if (files.size() > 0) {
            throw new PartialSuccessException(message, "Partially successful recursive 'mget' operation on " + (remoteDirectory != null ? remoteDirectory : "Client Working Directory"), e, files, fileNames);
        } else if (e instanceof MessagingException) {
            throw (MessagingException) e;
        } else if (e instanceof IOException) {
            throw (IOException) e;
        } else {
            throw new MessagingException("Failed to process MGET on first file", e);
        }
    }
    return files;
}
Also used : MessagingException(org.springframework.messaging.MessagingException) ArrayList(java.util.ArrayList) PartialSuccessException(org.springframework.integration.support.PartialSuccessException) IOException(java.io.IOException) MessagingException(org.springframework.messaging.MessagingException) MessageHandlingException(org.springframework.messaging.MessageHandlingException) IOException(java.io.IOException) PartialSuccessException(org.springframework.integration.support.PartialSuccessException) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) AbstractFileInfo(org.springframework.integration.file.remote.AbstractFileInfo)

Aggregations

File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AbstractFileInfo (org.springframework.integration.file.remote.AbstractFileInfo)2 PartialSuccessException (org.springframework.integration.support.PartialSuccessException)2 MessageHandlingException (org.springframework.messaging.MessageHandlingException)2 MessagingException (org.springframework.messaging.MessagingException)2