6 Replies Latest reply on Dec 9, 2010 5:15 AM by Kevin Conner

    Some issues about use FTP action

    Gang Ma Newbie

      Hello, I want to run the example 'helloworld_ftp_action' today. But I got some questions
      I started a ftp server 192.168.1.1 with username sa and password sa.
      after deploy the .esb archive, the jboss-esb.xml as follows

      <providers>
       <ftp-provider name="FTPprovider" hostname="192.168.1.1" >
       <ftp-bus busid="helloFTPChannel" >
       <ftp-message-filter
       username="sa"
       password="sa"
       passive="false"
       directory="jbossesb"
       input-suffix=".dat"
       work-suffix=".esbWorking"
       post-delete="false"
       post-suffix=".COMPLETE"
       error-delete="false"
       error-suffix=".HAS_ERROR"
       />
       </ftp-bus>
       </ftp-provider>
      
       <jms-provider name="JBossMQ"
       connection-factory="ConnectionFactory"
       jndi-context-factory="org.jnp.interfaces.NamingContextFactory"
       jndi-URL="localhost" >
      
       <jms-bus busid="quickstartEsbChannel">
       <jms-message-filter
       dest-type="QUEUE"
       dest-name="queue/quickstart_helloworld_ftp_esb"
       selector="source='fromHelloworldFTPAction'"
       />
       </jms-bus>
      
       </jms-provider>
      
       <schedule-provider name="cronExample">
       <cron-schedule scheduleid="cron-schedule" cronExpression="0/5 * * * * ?"/>
       </schedule-provider>
      
       </providers>
      
       <services>
       <service
       category="myCategory"
       name="myFileListener"
       description="Hello World File Action (esb listener)" >
       <listeners>
       <ftp-listener name="FtpGateway"
       busidref="helloFTPChannel"
       maxThreads="1"
       is-gateway="true"
       scheduleidref="cron-schedule"/>
       <jms-listener name="helloWorldFileAction"
       busidref="quickstartEsbChannel"
       maxThreads="1"
       />
       </listeners>
       <actions>
       <action name="action1"
       class="org.jboss.soa.esb.samples.quickstart.helloworldftpaction.MyAction"
       process="displayMessage,playWithMessage"
       />
       </actions>
       </service>
       </services>
      
      </jbossesb>
      


      In FTP server I can see that the sa has connect to it.
      After I call the target 'ant runtest', it only create a file on FTP server but didn't invoke any method in JbossESB.
      Here is the test class
      package org.jboss.soa.esb.samples.quickstart.helloworldftpaction.test;
      
      import java.io.IOException;
      import java.io.OutputStream;
      import java.io.PrintStream;
      import java.net.MalformedURLException;
      import java.net.URL;
      import java.net.URLConnection;
      
      public class CreateTestFile {
      
       public static void main(final String[] args) {
       if (args.length != 5)
       {
       System.err.println("Usage: java " + CreateTestFile.class.getName() + " <hostname> <username> <password> <filename> <contents>") ;
       System.exit(1) ;
       }
       else
       {
       final String hostname = args[0] ;
       final String username = args[1] ;
       final String password = args[2] ;
       final String filename = args[3] ;
       final String contents = args[4] ;
      
       final URL url ;
       final String filenameVal ;
       if (filename.charAt(0) == '/')
       {
       filenameVal = (filename.length() > 1 ? "%2F" + filename.substring(1) : "%2F") ;
       }
       else
       {
       filenameVal = filename ;
       }
       try
       {
       url = new URL("ftp://" + username + ":" + password + "@" + hostname + "/" + filenameVal) ;
       }
       catch (final MalformedURLException murle)
       {
       exit("Invalid URL: " + filenameVal, murle, 2) ;
       return ; // for compiler
       }
       final URLConnection connection ;
       try
       {
       connection = url.openConnection() ;
       }
       catch (final IOException ioe)
       {
       exit("Error accessing location: " + filenameVal, ioe, 3) ;
       return ; // for compiler
       }
       connection.setDoOutput(true) ;
       final OutputStream os ;
       try
       {
       os = connection.getOutputStream() ;
       }
       catch (final IOException ioe)
       {
       exit("Error obtaining output stream for location: " + filenameVal, ioe, 4) ;
       return ; // for compiler
       }
      
       try
       {
       final PrintStream ps = new PrintStream(os) ;
       ps.print(contents) ;
       ps.close() ;
       }
       finally
       {
       try
       {
       os.close() ;
       }
       catch (final IOException ioe) {} //ignore
       }
       }
       }
      
       private static void exit(final String message, final Throwable th, final int exitValue)
       {
       System.err.println(message) ;
       th.printStackTrace() ;
       System.exit(exitValue) ;
       }
      }


      First I want to know what does this mean in jboss-esb.xml?
      <schedule-provider name="cronExample">
       <cron-schedule scheduleid="cron-schedule" cronExpression="0/5 * * * * ?"/>
       </schedule-provider>




      Second, in the test class, does the value of hostname, username, password is the FTP's or others? (If FTP's only put the file to FTP not via ESB)

      Third, If I want to put the file 'upload.txt' to the FTP and download the file 'download.xml' from the ftp server via JbossESB. How should I do?

      T.

        • 1. Re: Some issues about use FTP action
          Gang Ma Newbie

          Maybe I misunderstand the test class. I fell puzzle about this

          • 2. Re: Some issues about use FTP action
            Daniel Bevenius Master

            It looks like your jbossesb.ftp.directory property may be incorrect. Can you try this with an absolute path?

            The schedule-provider is described in the section "Scheduling of Services" in the ProgrammersGuide.


            Second, in the test class, does the value of hostname, username, password is the FTP's or others? (If FTP's only put the file to FTP not via ESB)

            Sorry, I'm not sure I understand you question here. The values of hostname, username, and password all or for the same ftp server. The testclass sends the file via ftp. The esb will later get files from the same ftp server.


            Third, If I want to put the file 'upload.txt' to the FTP and download the file 'download.xml' from the ftp server via JbossESB. How should I do?

            You can use ".txt" and then later save the file somewhere with a different name. You could create an action for this for example.

            Regards,

            /Daniel




            • 3. Re: Some issues about use FTP action
              Gang Ma Newbie

              thank you very much. I misunderstand the function of this example. In previously, I thought when run the test, it will invoke the ESB and ESB put the file to FTP server.

              According your feedback what does the 'jbossesb.ftp.directory' mean? Does it means the directory in ftp server or JbossESb server? Where are the files stored when the ESB get the files from FTP?

              • 4. Re: Some issues about use FTP action
                Daniel Bevenius Master

                 

                According your feedback what does the 'jbossesb.ftp.directory' mean?

                This refers the the property in quickstarts/conf/quickstarts.properties:
                # If you are running the ftp tests then you must complete the following
                jbossesb.ftp.hostname=
                jbossesb.ftp.username=
                jbossesb.ftp.password=
                jbossesb.ftp.directory=
                

                Does it means the directory in ftp server or JbossESb server?

                In this case is it both. This is the directory to which the test client will publish the file and where the ESB will poll for the file.

                Where are the files stored when the ESB get the files from FTP?

                The file contents will packaged into an ESB Message object by the ftp listener. The content will then be accessable in the Message body. The file is not stored locally but you create an action that does this for you.

                Regards,

                /Daniel

                • 5. Re: Some issues about use FTP action
                  Igor JStarter Novice

                  How could I send now this file to an other FTP server ?

                  • 6. Re: Some issues about use FTP action
                    Kevin Conner Master

                    Take a look at the Notifier action.