Class FtpClient

  • All Implemented Interfaces:
    com.consol.citrus.common.InitializingPhase, com.consol.citrus.common.Named, com.consol.citrus.common.ShutdownPhase, com.consol.citrus.endpoint.Endpoint, com.consol.citrus.messaging.Consumer, com.consol.citrus.messaging.Producer, com.consol.citrus.messaging.ReplyConsumer, com.consol.citrus.messaging.SelectiveConsumer
    Direct Known Subclasses:
    SftpClient

    public class FtpClient
    extends com.consol.citrus.endpoint.AbstractEndpoint
    implements com.consol.citrus.messaging.Producer, com.consol.citrus.messaging.ReplyConsumer, com.consol.citrus.common.InitializingPhase, com.consol.citrus.common.ShutdownPhase
    Since:
    2.7.5
    Author:
    Christoph Deppisch
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        FtpClient()
      Default constructor initializing endpoint configuration.
      protected FtpClient​(FtpEndpointConfiguration endpointConfiguration)
      Default constructor using endpoint configuration.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static String addFileNameToTargetPath​(String sourcePath, String targetPath)
      If the target path is a directory (ends with "/"), add the file name from the source path to the target path.
      protected void connectAndLogin()
      Opens a new connection and performs login with user name and password if set.
      com.consol.citrus.messaging.SelectiveConsumer createConsumer()
      Creates a message consumer for this endpoint.
      com.consol.citrus.messaging.Producer createProducer()
      Creates a message producer for this endpoint for sending messages to this endpoint.
      protected FtpMessage deleteFile​(DeleteCommand delete, com.consol.citrus.context.TestContext context)
      Performs delete file operation.
      void destroy()  
      protected FtpMessage executeCommand​(CommandType ftpCommand, com.consol.citrus.context.TestContext context)  
      FtpEndpointConfiguration getEndpointConfiguration()  
      org.apache.commons.net.ftp.FTPClient getFtpClient()
      Gets the apache ftp client.
      protected InputStream getLocalFileInputStream​(String path, String dataType, com.consol.citrus.context.TestContext context)
      Constructs local file input stream.
      void initialize()  
      protected boolean isDirectory​(String remoteFilePath)
      Check file path type directory or file.
      protected FtpMessage listFiles​(ListCommand list, com.consol.citrus.context.TestContext context)
      Perform list files operation and provide file information as response.
      com.consol.citrus.message.Message receive​(com.consol.citrus.context.TestContext context)  
      com.consol.citrus.message.Message receive​(com.consol.citrus.context.TestContext context, long timeout)  
      com.consol.citrus.message.Message receive​(String selector, com.consol.citrus.context.TestContext context)  
      com.consol.citrus.message.Message receive​(String selector, com.consol.citrus.context.TestContext context, long timeout)  
      protected FtpMessage retrieveFile​(GetCommand command, com.consol.citrus.context.TestContext context)
      Performs retrieve file operation.
      void send​(com.consol.citrus.message.Message message, com.consol.citrus.context.TestContext context)  
      void setCorrelationManager​(com.consol.citrus.message.correlation.CorrelationManager<com.consol.citrus.message.Message> correlationManager)
      Sets the correlation manager.
      void setFtpClient​(org.apache.commons.net.ftp.FTPClient ftpClient)
      Sets the apache ftp client.
      protected FtpMessage storeFile​(PutCommand command, com.consol.citrus.context.TestContext context)
      Performs store file operation.
      • Methods inherited from class com.consol.citrus.endpoint.AbstractEndpoint

        getActor, getConsumerName, getName, getProducerName, setActor, setName
      • Methods inherited from interface com.consol.citrus.messaging.Consumer

        getName
      • Methods inherited from interface com.consol.citrus.messaging.Producer

        getName
    • Constructor Detail

      • FtpClient

        public FtpClient()
        Default constructor initializing endpoint configuration.
      • FtpClient

        protected FtpClient​(FtpEndpointConfiguration endpointConfiguration)
        Default constructor using endpoint configuration.
        Parameters:
        endpointConfiguration -
    • Method Detail

      • getEndpointConfiguration

        public FtpEndpointConfiguration getEndpointConfiguration()
        Specified by:
        getEndpointConfiguration in interface com.consol.citrus.endpoint.Endpoint
        Overrides:
        getEndpointConfiguration in class com.consol.citrus.endpoint.AbstractEndpoint
      • send

        public void send​(com.consol.citrus.message.Message message,
                         com.consol.citrus.context.TestContext context)
        Specified by:
        send in interface com.consol.citrus.messaging.Producer
      • executeCommand

        protected FtpMessage executeCommand​(CommandType ftpCommand,
                                            com.consol.citrus.context.TestContext context)
      • listFiles

        protected FtpMessage listFiles​(ListCommand list,
                                       com.consol.citrus.context.TestContext context)
        Perform list files operation and provide file information as response.
        Parameters:
        list -
        context -
        Returns:
      • deleteFile

        protected FtpMessage deleteFile​(DeleteCommand delete,
                                        com.consol.citrus.context.TestContext context)
        Performs delete file operation.
        Parameters:
        delete -
        context -
      • isDirectory

        protected boolean isDirectory​(String remoteFilePath)
                               throws IOException
        Check file path type directory or file.
        Parameters:
        remoteFilePath -
        Returns:
        Throws:
        IOException
      • storeFile

        protected FtpMessage storeFile​(PutCommand command,
                                       com.consol.citrus.context.TestContext context)
        Performs store file operation.
        Parameters:
        command -
        context -
      • getLocalFileInputStream

        protected InputStream getLocalFileInputStream​(String path,
                                                      String dataType,
                                                      com.consol.citrus.context.TestContext context)
                                               throws IOException
        Constructs local file input stream. When using ASCII data type the test variable replacement is activated otherwise plain byte stream is used.
        Parameters:
        path -
        dataType -
        context -
        Returns:
        Throws:
        IOException
      • retrieveFile

        protected FtpMessage retrieveFile​(GetCommand command,
                                          com.consol.citrus.context.TestContext context)
        Performs retrieve file operation.
        Parameters:
        command -
      • addFileNameToTargetPath

        protected static String addFileNameToTargetPath​(String sourcePath,
                                                        String targetPath)
        If the target path is a directory (ends with "/"), add the file name from the source path to the target path. Otherwise, don't do anything Example:

        sourcePath="/some/dir/file.pdf"
        targetPath="/other/dir/"
        returns: "/other/dir/file.pdf"

      • connectAndLogin

        protected void connectAndLogin()
                                throws IOException
        Opens a new connection and performs login with user name and password if set.
        Throws:
        IOException
      • receive

        public com.consol.citrus.message.Message receive​(com.consol.citrus.context.TestContext context)
        Specified by:
        receive in interface com.consol.citrus.messaging.Consumer
      • receive

        public com.consol.citrus.message.Message receive​(String selector,
                                                         com.consol.citrus.context.TestContext context)
        Specified by:
        receive in interface com.consol.citrus.messaging.SelectiveConsumer
      • receive

        public com.consol.citrus.message.Message receive​(com.consol.citrus.context.TestContext context,
                                                         long timeout)
        Specified by:
        receive in interface com.consol.citrus.messaging.Consumer
      • receive

        public com.consol.citrus.message.Message receive​(String selector,
                                                         com.consol.citrus.context.TestContext context,
                                                         long timeout)
        Specified by:
        receive in interface com.consol.citrus.messaging.SelectiveConsumer
      • initialize

        public void initialize()
        Specified by:
        initialize in interface com.consol.citrus.common.InitializingPhase
      • destroy

        public void destroy()
        Specified by:
        destroy in interface com.consol.citrus.common.ShutdownPhase
      • createProducer

        public com.consol.citrus.messaging.Producer createProducer()
        Creates a message producer for this endpoint for sending messages to this endpoint.
        Specified by:
        createProducer in interface com.consol.citrus.endpoint.Endpoint
      • createConsumer

        public com.consol.citrus.messaging.SelectiveConsumer createConsumer()
        Creates a message consumer for this endpoint. Consumer receives messages on this endpoint.
        Specified by:
        createConsumer in interface com.consol.citrus.endpoint.Endpoint
        Returns:
      • setFtpClient

        public void setFtpClient​(org.apache.commons.net.ftp.FTPClient ftpClient)
        Sets the apache ftp client.
        Parameters:
        ftpClient -
      • getFtpClient

        public org.apache.commons.net.ftp.FTPClient getFtpClient()
        Gets the apache ftp client.
        Returns:
      • setCorrelationManager

        public void setCorrelationManager​(com.consol.citrus.message.correlation.CorrelationManager<com.consol.citrus.message.Message> correlationManager)
        Sets the correlation manager.
        Parameters:
        correlationManager -