Class RemoteFileTemplate<F>
java.lang.Object
org.springframework.integration.file.remote.RemoteFileTemplate<F>
- Type Parameters:
- F- the file type.
- All Implemented Interfaces:
- Aware,- BeanFactoryAware,- InitializingBean,- RemoteFileOperations<F>
- Direct Known Subclasses:
- FtpRemoteFileTemplate,- SftpRemoteFileTemplate,- SmbRemoteFileTemplate
public class RemoteFileTemplate<F>
extends Object
implements RemoteFileOperations<F>, InitializingBean, BeanFactoryAware
A general abstraction for dealing with remote files.
- Since:
- 3.0
- Author:
- Iwein Fuld, Mark Fisher, Josh Long, Oleg Zhurakousky, David Turanski, Gary Russell, Artem Bilan, Alen Turkovic
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.springframework.integration.file.remote.RemoteFileOperationsRemoteFileOperations.OperationsCallback<F,T> 
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final Logprotected final SessionFactory<F> TheSessionFactoryfor acquiring remote file Sessions.
- 
Constructor SummaryConstructorsConstructorDescriptionRemoteFileTemplate(SessionFactory<F> sessionFactory) Construct aRemoteFileTemplatewith the supplied session factory.
- 
Method SummaryModifier and TypeMethodDescriptionvoidSend a file to a remote server, based on information in a message, appending.Send a file to a remote server, based on information in a message, appending.<T> Texecute(SessionCallback<F, T> callback) Execute the callback's doInSession method after obtaining a session.<T,C> T executeWithClient(ClientCallback<C, T> callback) Execute the callback's doWithClient method after obtaining a session's client, providing access to low level methods.booleanCheck if a file exists on the remote server.booleanget(String remotePath, InputStreamCallback callback) Retrieve a remote file as an InputStream.booleanget(Message<?> message, InputStreamCallback callback) Retrieve a remote file as an InputStream, based on information in a message.Return the processor for remote directory SpEL expression if any.final StringObtain a raw Session object.<T> Tinvoke(RemoteFileOperations.OperationsCallback<F, T> action) Invoke the callback and run all operations on the template argument in a dedicated thread-bound session and reliably close the it afterwards.booleanF[]List the files at the remote path.booleanRemove a remote file.voidRename a remote file, creating directories if needed.send(Message<?> message, String subDirectory, FileExistsMode... mode) Send a file to a remote server, based on information in a message.send(Message<?> message, FileExistsMode... mode) Send a file to a remote server, based on information in a message.voidsetAutoCreateDirectory(boolean autoCreateDirectory) Determine whether the remote directory should automatically be created when sending files to the remote system.voidsetBeanFactory(BeanFactory beanFactory) voidsetCharset(String charset) Set the charset to use when converting String payloads to bytes as the content of the remote file.voidsetFileNameExpression(Expression fileNameExpression) Set the file name expression to determine the full path to the remote file when retrieving a file using theget(Message, InputStreamCallback)method, with the message being the root object of the evaluation.voidsetFileNameGenerator(FileNameGenerator fileNameGenerator) Set the file name generator used to generate the remote filename to be used when transferring files to the remote system.voidsetRemoteDirectoryExpression(Expression remoteDirectoryExpression) Set the remote directory expression used to determine the remote directory to which files will be sent.voidsetRemoteFileSeparator(String remoteFileSeparator) Set the file separator when dealing with remote files; default '/'.voidsetTemporaryFileSuffix(String temporaryFileSuffix) Set the temporary suffix to use when transferring files to the remote system.voidsetTemporaryRemoteDirectoryExpression(Expression temporaryRemoteDirectoryExpression) Set a temporary remote directory expression; used when transferring files to the remote system.voidsetUseTemporaryFileName(boolean useTemporaryFileName) Set whether a temporary file name is used when sending files to the remote system.protected booleanDetermine whetherSession.dirty()should be called in theexecute(SessionCallback)when an exception is thrown from the callback.
- 
Field Details- 
logger
- 
sessionFactoryTheSessionFactoryfor acquiring remote file Sessions.
 
- 
- 
Constructor Details- 
RemoteFileTemplateConstruct aRemoteFileTemplatewith the supplied session factory.- Parameters:
- sessionFactory- the session factory.
 
 
- 
- 
Method Details- 
getSessionFactory- Returns:
- this template's SessionFactory.
- Since:
- 4.2
 
- 
setAutoCreateDirectorypublic void setAutoCreateDirectory(boolean autoCreateDirectory) Determine whether the remote directory should automatically be created when sending files to the remote system.- Parameters:
- autoCreateDirectory- true to create the directory.
 
- 
setRemoteFileSeparatorSet the file separator when dealing with remote files; default '/'.- Parameters:
- remoteFileSeparator- the separator.
 
- 
getRemoteFileSeparator- Returns:
- the remote file separator.
 
- 
setRemoteDirectoryExpressionSet the remote directory expression used to determine the remote directory to which files will be sent.- Parameters:
- remoteDirectoryExpression- the remote directory expression.
 
- 
getDirectoryExpressionProcessorReturn the processor for remote directory SpEL expression if any.- Returns:
- the processor for remote directory SpEL expression.
 
- 
setTemporaryRemoteDirectoryExpressionSet a temporary remote directory expression; used when transferring files to the remote system. After a successful transfer the file is renamed using theremoteDirectoryExpression.- Parameters:
- temporaryRemoteDirectoryExpression- the temporary remote directory expression.
 
- 
setFileNameExpressionSet the file name expression to determine the full path to the remote file when retrieving a file using theget(Message, InputStreamCallback)method, with the message being the root object of the evaluation.- Parameters:
- fileNameExpression- the file name expression.
 
- 
getTemporaryFileSuffix- Returns:
- the temporary file suffix.
 
- 
isUseTemporaryFileNamepublic boolean isUseTemporaryFileName()- Returns:
- whether a temporary file name is used when sending files to the remote system.
 
- 
setUseTemporaryFileNamepublic void setUseTemporaryFileName(boolean useTemporaryFileName) Set whether a temporary file name is used when sending files to the remote system.- Parameters:
- useTemporaryFileName- true to use a temporary file name.
- See Also:
 
- 
setFileNameGeneratorSet the file name generator used to generate the remote filename to be used when transferring files to the remote system. DefaultDefaultFileNameGenerator.- Parameters:
- fileNameGenerator- the file name generator.
 
- 
setCharsetSet the charset to use when converting String payloads to bytes as the content of the remote file. DefaultUTF-8.- Parameters:
- charset- the charset.
 
- 
setTemporaryFileSuffixSet the temporary suffix to use when transferring files to the remote system. Default ".writing".- Parameters:
- temporaryFileSuffix- the suffix
- See Also:
 
- 
setBeanFactory- Specified by:
- setBeanFactoryin interface- BeanFactoryAware
- Throws:
- BeansException
 
- 
afterPropertiesSetpublic void afterPropertiesSet()- Specified by:
- afterPropertiesSetin interface- InitializingBean
 
- 
appendDescription copied from interface:RemoteFileOperationsSend a file to a remote server, based on information in a message, appending.- Specified by:
- appendin interface- RemoteFileOperations<F>
- Parameters:
- message- The message.
- Returns:
- The remote path, or null if no local file was found.
 
- 
appendDescription copied from interface:RemoteFileOperationsSend a file to a remote server, based on information in a message, appending. The subDirectory is appended to the remote directory evaluated from the message.- Specified by:
- appendin interface- RemoteFileOperations<F>
- Parameters:
- message- The message.
- subDirectory- The sub directory.
- Returns:
- The remote path, or null if no local file was found.
 
- 
sendDescription copied from interface:RemoteFileOperationsSend a file to a remote server, based on information in a message.- Specified by:
- sendin interface- RemoteFileOperations<F>
- Parameters:
- message- The message.
- mode- See- FileExistsMode(optional; default REPLACE). A vararg is used to make the argument optional; only the first will be used if more than one is provided.
- Returns:
- The remote path, or null if no local file was found.
 
- 
sendDescription copied from interface:RemoteFileOperationsSend a file to a remote server, based on information in a message. The subDirectory is appended to the remote directory evaluated from the message.- Specified by:
- sendin interface- RemoteFileOperations<F>
- Parameters:
- message- The message.
- subDirectory- The sub directory.
- mode- See- FileExistsMode(optional; default REPLACE). A vararg is used to make the argument optional; only the first will be used if more than one is provided.
- Returns:
- The remote path, or null if no local file was found.
 
- 
existsDescription copied from interface:RemoteFileOperationsCheck if a file exists on the remote server.- Specified by:
- existsin interface- RemoteFileOperations<F>
- Parameters:
- path- The full path to the file.
- Returns:
- true when the file exists.
 
- 
removeDescription copied from interface:RemoteFileOperationsRemove a remote file.- Specified by:
- removein interface- RemoteFileOperations<F>
- Parameters:
- path- The full path to the file.
- Returns:
- true when successful.
 
- 
renameDescription copied from interface:RemoteFileOperationsRename a remote file, creating directories if needed.- Specified by:
- renamein interface- RemoteFileOperations<F>
- Parameters:
- fromPath- The current path.
- toPath- The new path.
 
- 
getDescription copied from interface:RemoteFileOperationsRetrieve a remote file as an InputStream, based on information in a message.- Specified by:
- getin interface- RemoteFileOperations<F>
- Parameters:
- message- The message which will be evaluated to generate the remote path.
- callback- the callback.
- Returns:
- true if the operation was successful.
- See Also:
 
- 
getDescription copied from interface:RemoteFileOperationsRetrieve a remote file as an InputStream.- Specified by:
- getin interface- RemoteFileOperations<F>
- Parameters:
- remotePath- The remote path to the file.
- callback- the callback.
- Returns:
- true if the operation was successful.
 
- 
listDescription copied from interface:RemoteFileOperationsList the files at the remote path.- Specified by:
- listin interface- RemoteFileOperations<F>
- Parameters:
- path- the path.
- Returns:
- the list.
 
- 
getSessionDescription copied from interface:RemoteFileOperationsObtain a raw Session object. User must close the session when it is no longer needed.- Specified by:
- getSessionin interface- RemoteFileOperations<F>
- Returns:
- a session.
 
- 
executeDescription copied from interface:RemoteFileOperationsExecute the callback's doInSession method after obtaining a session. Reliably closes the session when the method exits.- Specified by:
- executein interface- RemoteFileOperations<F>
- Type Parameters:
- T- The type returned by- SessionCallback.doInSession(org.springframework.integration.file.remote.session.Session).
- Parameters:
- callback- the SessionCallback.
- Returns:
- The result of the callback method.
 
- 
shouldMarkSessionAsDirtyDetermine whetherSession.dirty()should be called in theexecute(SessionCallback)when an exception is thrown from the callback. By default, this method returnstrue. Remote file protocol extensions can override this method to provide a specific strategy against the thrown exception, e.g.file not founderror is not a signal that session is broken.- Parameters:
- ex- the exception to check if- Sessionmust be marked as dirty.
- Returns:
- true if Session.dirty()should be called.
- Since:
- 6.0.8
 
- 
invokeDescription copied from interface:RemoteFileOperationsInvoke the callback and run all operations on the template argument in a dedicated thread-bound session and reliably close the it afterwards.- Specified by:
- invokein interface- RemoteFileOperations<F>
- Type Parameters:
- T- the return type.
- Parameters:
- action- the call back.
- Returns:
- the result from the RemoteFileOperations.OperationsCallback.doInOperations(RemoteFileOperations)
 
- 
executeWithClientDescription copied from interface:RemoteFileOperationsExecute the callback's doWithClient method after obtaining a session's client, providing access to low level methods. Reliably closes the session when the method exits.- Specified by:
- executeWithClientin interface- RemoteFileOperations<F>
- Type Parameters:
- T- The type returned by- ClientCallback.doWithClient(Object).
- C- The type of the underlying client object.
- Parameters:
- callback- the ClientCallback.
- Returns:
- The result of the callback method.
 
 
-