Class RemoteFileTemplate<F>
java.lang.Object
org.springframework.integration.file.remote.RemoteFileTemplate<F>
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.InitializingBean,RemoteFileOperations<F>
public class RemoteFileTemplate<F> extends java.lang.Object implements RemoteFileOperations<F>, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanFactoryAware
A general abstraction for dealing with remote files.
- Since:
- 3.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.file.remote.RemoteFileOperations
RemoteFileOperations.OperationsCallback<F,T> -
Field Summary
Fields Modifier and Type Field Description protected SessionFactory<F>sessionFactoryTheSessionFactoryfor acquiring remote file Sessions. -
Constructor Summary
Constructors Constructor Description RemoteFileTemplate(SessionFactory<F> sessionFactory)Construct aRemoteFileTemplatewith the supplied session factory. -
Method Summary
Modifier and Type Method Description voidafterPropertiesSet()java.lang.Stringappend(org.springframework.messaging.Message<?> message)Send a file to a remote server, based on information in a message, appending.java.lang.Stringappend(org.springframework.messaging.Message<?> message, java.lang.String subDirectory)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> TexecuteWithClient(ClientCallback<C,T> callback)Execute the callback's doWithClient method after obtaining a session's client, providing access to low level methods.booleanexists(java.lang.String path)Check if a file exists on the remote server.booleanget(java.lang.String remotePath, InputStreamCallback callback)Retrieve a remote file as an InputStream.booleanget(org.springframework.messaging.Message<?> message, InputStreamCallback callback)Retrieve a remote file as an InputStream, based on information in a message.java.lang.StringgetRemoteFileSeparator()Session<F>getSession()Obtain a raw Session object.SessionFactory<F>getSessionFactory()java.lang.StringgetTemporaryFileSuffix()<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.booleanisUseTemporaryFileName()F[]list(java.lang.String path)List the files at the remote path.booleanremove(java.lang.String path)Remove a remote file.voidrename(java.lang.String fromPath, java.lang.String toPath)Rename a remote file, creating directories if needed.java.lang.Stringsend(org.springframework.messaging.Message<?> message, java.lang.String subDirectory, FileExistsMode... mode)Send a file to a remote server, based on information in a message.java.lang.Stringsend(org.springframework.messaging.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(org.springframework.beans.factory.BeanFactory beanFactory)voidsetCharset(java.lang.String charset)Set the charset to use when converting String payloads to bytes as the content of the remote file.voidsetFileNameExpression(org.springframework.expression.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(org.springframework.expression.Expression remoteDirectoryExpression)Set the remote directory expression used to determine the remote directory to which files will be sent.voidsetRemoteFileSeparator(java.lang.String remoteFileSeparator)Set the file separator when dealing with remote files; default '/'.voidsetTemporaryFileSuffix(java.lang.String temporaryFileSuffix)Set the temporary suffix to use when transferring files to the remote system.voidsetTemporaryRemoteDirectoryExpression(org.springframework.expression.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.
-
Field Details
-
sessionFactory
TheSessionFactoryfor acquiring remote file Sessions.
-
-
Constructor Details
-
RemoteFileTemplate
Construct aRemoteFileTemplatewith the supplied session factory.- Parameters:
sessionFactory- the session factory.
-
-
Method Details
-
getSessionFactory
- Returns:
- this template's
SessionFactory. - Since:
- 4.2
-
setAutoCreateDirectory
public 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.
-
setRemoteFileSeparator
public void setRemoteFileSeparator(java.lang.String remoteFileSeparator)Set the file separator when dealing with remote files; default '/'.- Parameters:
remoteFileSeparator- the separator.
-
getRemoteFileSeparator
public final java.lang.String getRemoteFileSeparator()- Returns:
- the remote file separator.
-
setRemoteDirectoryExpression
public void setRemoteDirectoryExpression(org.springframework.expression.Expression remoteDirectoryExpression)Set the remote directory expression used to determine the remote directory to which files will be sent.- Parameters:
remoteDirectoryExpression- the remote directory expression.
-
setTemporaryRemoteDirectoryExpression
public void setTemporaryRemoteDirectoryExpression(org.springframework.expression.Expression temporaryRemoteDirectoryExpression)Set 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.
-
setFileNameExpression
public void setFileNameExpression(org.springframework.expression.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.- Parameters:
fileNameExpression- the file name expression.
-
getTemporaryFileSuffix
public java.lang.String getTemporaryFileSuffix()- Returns:
- the temporary file suffix.
-
isUseTemporaryFileName
public boolean isUseTemporaryFileName()- Returns:
- whether a temporary file name is used when sending files to the remote system.
-
setUseTemporaryFileName
public 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:
setTemporaryFileSuffix(String)
-
setFileNameGenerator
Set 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.
-
setCharset
public void setCharset(java.lang.String charset)Set the charset to use when converting String payloads to bytes as the content of the remote file. DefaultUTF-8.- Parameters:
charset- the charset.
-
setTemporaryFileSuffix
public void setTemporaryFileSuffix(java.lang.String temporaryFileSuffix)Set the temporary suffix to use when transferring files to the remote system. Default ".writing".- Parameters:
temporaryFileSuffix- the suffix- See Also:
setUseTemporaryFileName(boolean)
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException- Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware- Throws:
org.springframework.beans.BeansException
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
append
public java.lang.String append(org.springframework.messaging.Message<?> message)Description copied from interface:RemoteFileOperationsSend a file to a remote server, based on information in a message, appending.- Specified by:
appendin interfaceRemoteFileOperations<F>- Parameters:
message- The message.- Returns:
- The remote path, or null if no local file was found.
-
append
public java.lang.String append(org.springframework.messaging.Message<?> message, java.lang.String subDirectory)Description 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 interfaceRemoteFileOperations<F>- Parameters:
message- The message.subDirectory- The sub directory.- Returns:
- The remote path, or null if no local file was found.
-
send
public java.lang.String send(org.springframework.messaging.Message<?> message, FileExistsMode... mode)Description copied from interface:RemoteFileOperationsSend a file to a remote server, based on information in a message.- Specified by:
sendin interfaceRemoteFileOperations<F>- Parameters:
message- The message.mode- SeeFileExistsMode(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.
-
send
public java.lang.String send(org.springframework.messaging.Message<?> message, java.lang.String subDirectory, FileExistsMode... mode)Description 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 interfaceRemoteFileOperations<F>- Parameters:
message- The message.subDirectory- The sub directory.mode- SeeFileExistsMode(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.
-
exists
public boolean exists(java.lang.String path)Description copied from interface:RemoteFileOperationsCheck if a file exists on the remote server.- Specified by:
existsin interfaceRemoteFileOperations<F>- Parameters:
path- The full path to the file.- Returns:
- true when the file exists.
-
remove
public boolean remove(java.lang.String path)Description copied from interface:RemoteFileOperationsRemove a remote file.- Specified by:
removein interfaceRemoteFileOperations<F>- Parameters:
path- The full path to the file.- Returns:
- true when successful.
-
rename
public void rename(java.lang.String fromPath, java.lang.String toPath)Description copied from interface:RemoteFileOperationsRename a remote file, creating directories if needed.- Specified by:
renamein interfaceRemoteFileOperations<F>- Parameters:
fromPath- The current path.toPath- The new path.
-
get
Description copied from interface:RemoteFileOperationsRetrieve a remote file as an InputStream, based on information in a message.- Specified by:
getin interfaceRemoteFileOperations<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:
setFileNameExpression(Expression)
-
get
Description copied from interface:RemoteFileOperationsRetrieve a remote file as an InputStream.- Specified by:
getin interfaceRemoteFileOperations<F>- Parameters:
remotePath- The remote path to the file.callback- the callback.- Returns:
- true if the operation was successful.
-
list
Description copied from interface:RemoteFileOperationsList the files at the remote path.- Specified by:
listin interfaceRemoteFileOperations<F>- Parameters:
path- the path.- Returns:
- the list.
-
getSession
Description copied from interface:RemoteFileOperationsObtain a raw Session object. User must close the session when it is no longer needed.- Specified by:
getSessionin interfaceRemoteFileOperations<F>- Returns:
- a session.
-
execute
Description copied from interface:RemoteFileOperationsExecute the callback's doInSession method after obtaining a session. Reliably closes the session when the method exits.- Specified by:
executein interfaceRemoteFileOperations<F>- Type Parameters:
T- The type returned bySessionCallback.doInSession(org.springframework.integration.file.remote.session.Session).- Parameters:
callback- the SessionCallback.- Returns:
- The result of the callback method.
-
invoke
Description 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 interfaceRemoteFileOperations<F>- Type Parameters:
T- the return type.- Parameters:
action- the call back.- Returns:
- the result from the
RemoteFileOperations.OperationsCallback.doInOperations(RemoteFileOperations)
-
executeWithClient
Description 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 interfaceRemoteFileOperations<F>- Type Parameters:
T- The type returned byClientCallback.doWithClient(Object).C- The type of the underlying client object.- Parameters:
callback- the ClientCallback.- Returns:
- The result of the callback method.
-