@ComponentProfile(summary="Put a file on a FTP/SFTP server; uses PUT, RNFR and RNTO for atomicity", tag="producer,ftp,ftps,sftp", recommended=FileTransferConnection.class) public class FtpProducer extends RequestReplyProducerImp
The connection type for this implementation should always be a concrete subclass of FileTransferConnection
such as
FtpConnection
or SftpConnection
The destination returned by the ProduceDestination implementation should be in the URL form dictated by the
FileTransferConnection
flavour or simply the IP Address / DNS name of the FTP/SFTP Server. If the URL form is used,
then it is possible to override the username, password, and port settings of the FTP server, in all other cases the configuration
specified in the FileTransferConnection
object will be used.
The output filename is controlled using the standard FileNameCreator interface. The AdaptrisMessage object is first uploaded to the build-directory and subsequently renamed into the dest-directory. In most FTP Server implementations, the rename can be considered an atomic operation, so using this method reduces the liklehood of file read attempts during the upload.
It is possible to perform limited request retry functionality using this implementation, in this instance
reply-directory
element must be set. We strongly discourage anyone else from trying to implement request reply
using FTP, it is dangerous and prone to undefined behaviour.
When running in request reply mode, the following steps occur after producing the file in the normal fashion.
reply-directory
reply-proc-directory
is set, then move the file to this directory, otherwise delete it
In the situation where a specific file should be treated as the reply, then the metadata key corresponding to
CoreConstants#FTP_REPLYTO_NAME
should be populated.
CoreConstants.FTP_REPLYTO_NAME
,
FileNameCreator
,
FtpConnection
,
FileTransferConnection
,
ProduceDestination
In the adapter configuration file this class is aliased as ftp-producer which is the preferred alternative to the fully qualified classname when building your configuration.
log
CONFIRMATION_ID_KEY
Constructor and Description |
---|
FtpProducer()
Default Constructor with the following defaults.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the component.
|
protected long |
defaultTimeout()
The default is 1 minute (60000 ms).
|
protected AdaptrisMessage |
doRequest(AdaptrisMessage msg,
ProduceDestination destination,
long timeout)
Actually do the request.
|
java.lang.String |
getBuildDirectory()
Get the build directory.
|
java.lang.String |
getDestDirectory()
Get the destination directory.
|
FileNameCreator |
getFilenameCreator() |
java.lang.String |
getReplyDirectory()
Get the Reply Directory.
|
java.lang.String |
getReplyProcDirectory()
Get the ReplyProc Directory.
|
java.lang.Boolean |
getReplyUsesEncoder() |
void |
init()
Initialises the component.
|
void |
prepare()
Prepare for initialisation.
|
void |
produce(AdaptrisMessage msg,
ProduceDestination destination)
Produce the
AdaptrisMessage to the supplied ProduceDestination , over-riding any configured destinations. |
boolean |
replyUsesEncoder() |
void |
setBuildDirectory(java.lang.String string)
Set the build directory.
|
void |
setDestDirectory(java.lang.String string)
Set the dest directory.
|
void |
setFilenameCreator(FileNameCreator creator) |
void |
setReplyDirectory(java.lang.String string)
Set the Reply Directory.
|
void |
setReplyProcDirectory(java.lang.String string)
Set the ReplyProc Directory.
|
void |
setReplyUsesEncoder(java.lang.Boolean b)
Set whether to use any configured encoder to parse the reply.
|
void |
start()
Starts the component.
|
void |
stop()
Stop the component
|
getIgnoreReplyMetadata, produce, request, request, request, request, setIgnoreReplyMetadata, shouldIgnoreReplyMetadata
getDestination, setDestination
createName, createQualifier, decode, encode, getEncoder, getIsTrackingEndpoint, getMessageFactory, getUniqueId, handleConnectionException, isTrackingEndpoint, registerConnection, registerEncoderMessageFactory, retrieveConnection, setEncoder, setIsTrackingEndpoint, setMessageFactory, setUniqueId, withMessageFactory
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
decode, encode, getEncoder, getMessageFactory, handleConnectionException, registerConnection, retrieveConnection, setEncoder, setMessageFactory
getUniqueId
createName, createQualifier, isTrackingEndpoint
public FtpProducer()
public void close()
ComponentLifecycle
A closed component should release any connections it uses, etc. and clean up completely. Throwing a RuntimeException
may
cause unintended consequences
ComponentLifecycle.close()
public void init() throws CoreException
ComponentLifecycle
Component initialisation includes config verification, creation of connections etc.
CoreException
- wrapping any underlying Exception
sComponentLifecycle.init()
public void start() throws CoreException
ComponentLifecycle
Once a component is started it should be ready to process messages. In the case of AdaptrisMessageConsumer
, calling start
will begin message delivery.
CoreException
- wrapping any underlying Exception
sComponentLifecycle.start()
public void stop()
ComponentLifecycle
A stopped component is not expected to be ready to process messages. In the case of AdaptrisMessageConsumer
, calling stop
will pause message delivery. Throwing a RuntimeException
may cause unintended consequences
ComponentLifecycle.stop()
protected long defaultTimeout()
defaultTimeout
in class RequestReplyProducerImp
RequestReplyProducerImp.defaultTimeout()
public void produce(AdaptrisMessage msg, ProduceDestination destination) throws ProduceException
AdaptrisMessageSender
AdaptrisMessage
to the supplied ProduceDestination
, over-riding any configured destinations.msg
- the AdaptrisMessage
to producedestination
- the ProduceDestination
to produce toProduceException
- wrapping any underlying ExceptionsAdaptrisMessageSender.produce(AdaptrisMessage, ProduceDestination)
protected AdaptrisMessage doRequest(AdaptrisMessage msg, ProduceDestination destination, long timeout) throws ProduceException
RequestReplyProducerImp
doRequest
in class RequestReplyProducerImp
ProduceException
RequestReplyProducerImp.doRequest(AdaptrisMessage, ProduceDestination, long)
public void prepare() throws CoreException
ComponentLifecycleExtension
CoreException
public java.lang.String getBuildDirectory()
public java.lang.String getDestDirectory()
public void setBuildDirectory(java.lang.String string)
string
- the dir.public void setDestDirectory(java.lang.String string)
string
- the dir.public java.lang.String getReplyDirectory()
public void setReplyDirectory(java.lang.String string)
string
- the reply directory.public java.lang.String getReplyProcDirectory()
public void setReplyProcDirectory(java.lang.String string)
string
- the reply proc directory.public boolean replyUsesEncoder()
public java.lang.Boolean getReplyUsesEncoder()
public void setReplyUsesEncoder(java.lang.Boolean b)
b
- true or false; default true.public FileNameCreator getFilenameCreator()
public void setFilenameCreator(FileNameCreator creator)