Sun Adapter for Batch/FTP

com.stc.eways.batchext
Class FtpFileClientImpl

java.lang.Object
  extended by com.stc.eways.batchext.FtpFileClientImpl
All Implemented Interfaces:
FtpFileClient
Direct Known Subclasses:
FtpFileClientImplUser0

public class FtpFileClientImpl
extends java.lang.Object
implements FtpFileClient

This class is the standard implementation of the interface FtpFileClient. It is a core part of Batch e*Way FTP ETD and is used for ETD implementation and e*Way Connection delegation. You can extend this class to provide your own implementation, if desired.

Version:
cvs revision: $Revision: 1.19 $ Last Modified: $Date: 2008/03/04 03:05:51 $
Author:
Harry Liu

Field Summary
protected  com.stc.connector.logging.Logger mLogger
           
protected  boolean transferAllowed
           
 
Fields inherited from interface com.stc.eways.batchext.FtpFileClient
ENCODING_BIG5, ENCODING_DEFAULT, ENCODING_EUC_JP, ENCODING_GBK, ENCODING_JIS, ENCODING_SJIS, TC_GET, TC_PUT
 
Constructor Summary
FtpFileClientImpl()
          Constructor.
FtpFileClientImpl(FtpETD etd)
          Constructor.
 
Method Summary
 void allowTransfer()
          Allow transfers in XA mode.
 void cleanupPostTransferGet(TransferNamesAndCommands tncg)
          Cleans up any failures during Post Transfer Command for "get".
 void cleanupPostTransferPut(TransferNamesAndCommands tncp)
          Cleans up any failures during Post Transfer Command for "put".
 void cleanupPreTransferGet(TransferNamesAndCommands tncg)
          Cleans up any failures during Pre Transfer Command for "get".
 void cleanupPreTransferPut(TransferNamesAndCommands tncp)
          Cleans up any failures during Pre Transfer Command for "put".
 void cleanupRawCommands(TransferNamesAndCommands tncr)
          Cleans up any failures during pre/post ftp raw commands.
 void cleanupTransferGet(TransferNamesAndCommands tncg)
          Cleans up any failures during ftp Transfer "get".
 void cleanupTransferPut(TransferNamesAndCommands tncp)
          Cleans up any failures during ftp Transfer "put".
 void close()
          Does an FTP log-out and disconnects.
 void connect()
          Performs the FTP connection, log-in and switch modes, and so on.
 void connect(java.lang.String encoding)
          Performs the FTP connection, log-in and switch modes, and so on.
 void disconnect()
          Does FTP log-out and disconnects.
 void doPostTransferGet(TransferNamesAndCommands tncg)
          Performs Post Transfer Command for FTP get operation.
 void doPostTransferPut(TransferNamesAndCommands tncp)
          Performs Post Transfer Command for FTP put operation.
 void doPreTransferGet(TransferNamesAndCommands tncg)
          Performs Pre Transfer Command for FTP get operation.
 void doPreTransferPut(TransferNamesAndCommands tncp)
          Performs Pre Transfer Command for FTP put operation.
 void doRawCommands(java.lang.String commands)
          Performs FTP pre and post transfer raw commands, for example: SITE RECFM=FB;SITE LRECL=50;SITE BLOCKSIZE=32750;SITE TRACKS;SITE PRI=5;SITE SEC=5 NOTE: The commands are separated by a semicolon (;), and only FTP raw commands are expected.
 void doTransferGet(TransferNamesAndCommands tncg)
          Performs the real FTP get transfer.
 void doTransferPut(TransferNamesAndCommands tncp)
          Performs the real FTP put transfer.
 void get()
          Retrieves a file from the remote FTP server.
 void getIfExists()
          per QAI 94512 - requested by eXchange team same as get() but will return siliently if the target does not exists;
protected  com.stc.connector.logging.Logger getLogger()
           
 byte[] getPayload()
          Retrieves the ETD's data payload.
 TransferNamesAndCommands getResolvedNamesForGet()
          Resolves names from patterns for the FTP get operation.
 TransferNamesAndCommands getResolvedNamesForPut()
          Resolves names from patterns for the FTP put operation.
 java.util.Properties getUserProperties()
          Retrieves user-defined properties.
 void initialConfigValues(java.util.Properties props)
          Initializes configuration properties from specified properties.
 void initialize(FtpETD etd)
          Initializes the ETD object.
 boolean isConnected()
          Verifies that the e*Way Connection to the external system is still available.
 boolean isOpen()
          Verifies that the e*Way Connection to the external system is still available.
 boolean isXA()
          Determines whether an e*Way Connection is in the XA mode.
static void main(java.lang.String[] args)
          Used to do stand-alone testing.
 void open()
          Performs an FTP connection, log-in and switch modes, and so on.
 void open(java.lang.String encoding)
          Performs an FTP connection, log-in and switch modes, and so on.
 void put()
          Stores a remote FTP file.
 void releaseResources()
          Releases the e*Way Connection's resources but does not close the connection to the external system.
 boolean reset()
          Resets the data content of an FtpFileClient.
 void restoreConfigValues()
          Restores all configuration properties from the related e*Way Connection's configuration file.
 void setInputStreamAdapter(com.stc.eways.common.eway.standalone.streaming.InputStreamAdapter isa)
          This method is used to request data streams from another ETD.
 void setOutputStreamAdapter(com.stc.eways.common.eway.standalone.streaming.OutputStreamAdapter osa)
          This method is used to request data streams from another ETD.
 void setPayload(byte[] newPayload)
          Sets the ETD's data payload.
 void terminate()
          Terminates the FtpFileClient.
 void undoPostTransferGet(TransferNamesAndCommands tncg)
          Undoes Post Transfer for FTP get operation.
 void undoPostTransferPut(TransferNamesAndCommands tncp)
          Undoes Post Transfer for FTP put operation.
 void undoPreTransferGet(TransferNamesAndCommands tncg)
          Undoes Pre Transfer for FTP get operation.
 void undoPreTransferPut(TransferNamesAndCommands tncp)
          Undoes Pre Transfer for FTP put operation.
 void undoRawCommands(TransferNamesAndCommands tncr)
          Undo pre/post ftp raw commands.
 void undoTransferGet(TransferNamesAndCommands tncg)
          Undoes ftp get transfer.
 void undoTransferPut(TransferNamesAndCommands tncp)
          Undoes ftp put transfer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mLogger

protected com.stc.connector.logging.Logger mLogger

transferAllowed

protected boolean transferAllowed
Constructor Detail

FtpFileClientImpl

public FtpFileClientImpl(FtpETD etd)
                  throws FtpFileException
Constructor.

Parameters:
etd - FtpETD instance.
Throws:
FtpFileException - If some error occurs.

FtpFileClientImpl

public FtpFileClientImpl()
Constructor.

Method Detail

initialize

public void initialize(FtpETD etd)
                throws FtpFileException
Initializes the ETD object.

Specified by:
initialize in interface FtpFileClient
Parameters:
etd - An instance of the FtpETD object.
Throws:
FtpFileException - If some error occurs.

doRawCommands

public void doRawCommands(java.lang.String commands)
                   throws FtpFileException
Performs FTP pre and post transfer raw commands, for example: SITE RECFM=FB;SITE LRECL=50;SITE BLOCKSIZE=32750;SITE TRACKS;SITE PRI=5;SITE SEC=5 NOTE: The commands are separated by a semicolon (;), and only FTP raw commands are expected.

Specified by:
doRawCommands in interface FtpFileClient
Parameters:
commands - The FTP raw command set.
commands - The raw command set.
Throws:
FtpFileException - If some error occurs.

main

public static void main(java.lang.String[] args)
Used to do stand-alone testing.

Parameters:
args - Command line parameters.

close

public void close()
Does an FTP log-out and disconnects.

Specified by:
close in interface FtpFileClient

open

public void open()
          throws FtpFileException
Performs an FTP connection, log-in and switch modes, and so on.

Specified by:
open in interface FtpFileClient
Throws:
FtpFileException - If some error occurs.

open

public void open(java.lang.String encoding)
          throws FtpFileException
Performs an FTP connection, log-in and switch modes, and so on.

Specified by:
open in interface FtpFileClient
Parameters:
encoding - The encoding for the server.
Throws:
FtpFileException - If some error occurs.

allowTransfer

public void allowTransfer()
Allow transfers in XA mode.

Specified by:
allowTransfer in interface FtpFileClient

reset

public boolean reset()
              throws FtpFileException
Resets the data content of an FtpFileClient.

Specified by:
reset in interface FtpFileClient
Returns:
false if the ETD doesn't have a meaningful implementation of reset(); so do a new of the ETD instead. Otherwise, return true if the reset will clear the data content of the ETD.
Throws:
FtpFileException - If some error occurs.

terminate

public void terminate()
               throws FtpFileException
Terminates the FtpFileClient.

Specified by:
terminate in interface FtpFileClient
Throws:
FtpFileException - If some error occurs.

getPayload

public byte[] getPayload()
Retrieves the ETD's data payload.

The data payload is a blob (byte array) used to store the raw content of a file.

Specified by:
getPayload in interface FtpFileClient
Returns:
The data payload.

setPayload

public void setPayload(byte[] newPayload)
Sets the ETD's data payload.

The data payload is a blob (byte array) used to store the raw content of a file.

Specified by:
setPayload in interface FtpFileClient
Parameters:
newPayload - The data payload.

initialConfigValues

public void initialConfigValues(java.util.Properties props)
                         throws FtpFileException
Initializes configuration properties from specified properties.

Specified by:
initialConfigValues in interface FtpFileClient
Parameters:
props - The specified properties.
Throws:
FtpFileException - If some error occurs.

isOpen

public boolean isOpen()
Verifies that the e*Way Connection to the external system is still available.

Specified by:
isOpen in interface FtpFileClient
Returns:
true if the connection is still open and available; false if otherwise.

restoreConfigValues

public void restoreConfigValues()
                         throws FtpFileException
Restores all configuration properties from the related e*Way Connection's configuration file.

Specified by:
restoreConfigValues in interface FtpFileClient
Throws:
FtpFileException - If some error occurs.

isXA

public boolean isXA()
Determines whether an e*Way Connection is in the XA mode.

Specified by:
isXA in interface FtpFileClient
Returns:
true or false.

releaseResources

public void releaseResources()
Releases the e*Way Connection's resources but does not close the connection to the external system.

Specified by:
releaseResources in interface FtpFileClient

getUserProperties

public java.util.Properties getUserProperties()
Retrieves user-defined properties.

This method is an advanced setting and is part of the e*Way's user-extensibility features.

The properties are from the user properties file.

Specified by:
getUserProperties in interface FtpFileClient
Returns:
User Properties.

connect

public void connect()
             throws FtpFileException
Description copied from interface: FtpFileClient
Performs the FTP connection, log-in and switch modes, and so on.

Specified by:
connect in interface FtpFileClient
Throws:
FtpFileException - If some error occurs.

connect

public void connect(java.lang.String encoding)
             throws FtpFileException
Description copied from interface: FtpFileClient
Performs the FTP connection, log-in and switch modes, and so on.

Specified by:
connect in interface FtpFileClient
Parameters:
encoding - The encoding for the server.
Throws:
FtpFileException - If some error occurs.

disconnect

public void disconnect()
Does FTP log-out and disconnects.

Specified by:
disconnect in interface FtpFileClient

isConnected

public boolean isConnected()
Verifies that the e*Way Connection to the external system is still available.

Specified by:
isConnected in interface FtpFileClient
Returns:
true if the connection is still open and available; false if otherwise.

setInputStreamAdapter

public void setInputStreamAdapter(com.stc.eways.common.eway.standalone.streaming.InputStreamAdapter isa)
This method is used to request data streams from another ETD.

Specified by:
setInputStreamAdapter in interface FtpFileClient
Parameters:
isa - An InputStreamAdapter object.

setOutputStreamAdapter

public void setOutputStreamAdapter(com.stc.eways.common.eway.standalone.streaming.OutputStreamAdapter osa)
This method is used to request data streams from another ETD.

Specified by:
setOutputStreamAdapter in interface FtpFileClient
Parameters:
osa - An OutputStreamAdapter object.

getResolvedNamesForGet

public TransferNamesAndCommands getResolvedNamesForGet()
                                                throws FtpFileException
Resolves names from patterns for the FTP get operation.

Specified by:
getResolvedNamesForGet in interface FtpFileClient
Returns:
An object of TransferNamesAndCommands.
Throws:
FtpFileException - If some error occurs.

getResolvedNamesForPut

public TransferNamesAndCommands getResolvedNamesForPut()
                                                throws FtpFileException
Resolves names from patterns for the FTP put operation.

Specified by:
getResolvedNamesForPut in interface FtpFileClient
Returns:
An object of TransferNamesAndCommands.
Throws:
FtpFileException - If some error occurs.

doPostTransferGet

public void doPostTransferGet(TransferNamesAndCommands tncg)
                       throws java.lang.Exception
Performs Post Transfer Command for FTP get operation.

Specified by:
doPostTransferGet in interface FtpFileClient
Parameters:
tncg - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

doPreTransferGet

public void doPreTransferGet(TransferNamesAndCommands tncg)
                      throws java.lang.Exception
Performs Pre Transfer Command for FTP get operation.

Specified by:
doPreTransferGet in interface FtpFileClient
Parameters:
tncg - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

doTransferGet

public void doTransferGet(TransferNamesAndCommands tncg)
                   throws java.lang.Exception
Performs the real FTP get transfer.

Specified by:
doTransferGet in interface FtpFileClient
Parameters:
tncg - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

doPostTransferPut

public void doPostTransferPut(TransferNamesAndCommands tncp)
                       throws java.lang.Exception
Performs Post Transfer Command for FTP put operation.

Specified by:
doPostTransferPut in interface FtpFileClient
Parameters:
tncp - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

doPreTransferPut

public void doPreTransferPut(TransferNamesAndCommands tncp)
                      throws java.lang.Exception
Performs Pre Transfer Command for FTP put operation.

Specified by:
doPreTransferPut in interface FtpFileClient
Parameters:
tncp - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

doTransferPut

public void doTransferPut(TransferNamesAndCommands tncp)
                   throws java.lang.Exception
Performs the real FTP put transfer.

Specified by:
doTransferPut in interface FtpFileClient
Parameters:
tncp - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

put

public void put()
         throws FtpFileException
Stores a remote FTP file. This method is exposed in the ETD structure and takes the related e*Way Connection's configuration parameters as its input. The method encapsulates all necessary FTP operations.

Specified by:
put in interface FtpFileClient
Throws:
FtpFileException - If some error occurs.

undoPreTransferGet

public void undoPreTransferGet(TransferNamesAndCommands tncg)
                        throws java.lang.Exception
Undoes Pre Transfer for FTP get operation.

Specified by:
undoPreTransferGet in interface FtpFileClient
Parameters:
tncg - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

undoTransferGet

public void undoTransferGet(TransferNamesAndCommands tncg)
                     throws java.lang.Exception
Undoes ftp get transfer.

Specified by:
undoTransferGet in interface FtpFileClient
Parameters:
tncg - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

undoPreTransferPut

public void undoPreTransferPut(TransferNamesAndCommands tncp)
                        throws java.lang.Exception
Undoes Pre Transfer for FTP put operation.

Specified by:
undoPreTransferPut in interface FtpFileClient
Parameters:
tncp - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

undoTransferPut

public void undoTransferPut(TransferNamesAndCommands tncp)
                     throws java.lang.Exception
Undoes ftp put transfer.

Specified by:
undoTransferPut in interface FtpFileClient
Parameters:
tncp - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

undoPostTransferGet

public void undoPostTransferGet(TransferNamesAndCommands tncg)
                         throws java.lang.Exception
Undoes Post Transfer for FTP get operation.

Specified by:
undoPostTransferGet in interface FtpFileClient
Parameters:
tncg - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

undoPostTransferPut

public void undoPostTransferPut(TransferNamesAndCommands tncp)
                         throws java.lang.Exception
Undoes Post Transfer for FTP put operation.

Specified by:
undoPostTransferPut in interface FtpFileClient
Parameters:
tncp - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

cleanupPostTransferGet

public void cleanupPostTransferGet(TransferNamesAndCommands tncg)
                            throws java.lang.Exception
Cleans up any failures during Post Transfer Command for "get".

Specified by:
cleanupPostTransferGet in interface FtpFileClient
Parameters:
tncg - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

cleanupPostTransferPut

public void cleanupPostTransferPut(TransferNamesAndCommands tncp)
                            throws java.lang.Exception
Cleans up any failures during Post Transfer Command for "put".

Specified by:
cleanupPostTransferPut in interface FtpFileClient
Parameters:
tncp - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

cleanupPreTransferGet

public void cleanupPreTransferGet(TransferNamesAndCommands tncg)
                           throws java.lang.Exception
Cleans up any failures during Pre Transfer Command for "get".

Specified by:
cleanupPreTransferGet in interface FtpFileClient
Parameters:
tncg - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

cleanupPreTransferPut

public void cleanupPreTransferPut(TransferNamesAndCommands tncp)
                           throws java.lang.Exception
Cleans up any failures during Pre Transfer Command for "put".

Specified by:
cleanupPreTransferPut in interface FtpFileClient
Parameters:
tncp - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

cleanupRawCommands

public void cleanupRawCommands(TransferNamesAndCommands tncr)
                        throws FtpFileException
Cleans up any failures during pre/post ftp raw commands.

Specified by:
cleanupRawCommands in interface FtpFileClient
Parameters:
tncr - An instance of TransferNamesAndCommands class.
Throws:
FtpFileException - If some error occurs.

cleanupTransferGet

public void cleanupTransferGet(TransferNamesAndCommands tncg)
                        throws java.lang.Exception
Cleans up any failures during ftp Transfer "get".

Specified by:
cleanupTransferGet in interface FtpFileClient
Parameters:
tncg - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

cleanupTransferPut

public void cleanupTransferPut(TransferNamesAndCommands tncp)
                        throws java.lang.Exception
Cleans up any failures during ftp Transfer "put".

Specified by:
cleanupTransferPut in interface FtpFileClient
Parameters:
tncp - An instance of TransferNamesAndCommands class.
Throws:
java.lang.Exception - If some error occurs.

undoRawCommands

public void undoRawCommands(TransferNamesAndCommands tncr)
                     throws FtpFileException
Undo pre/post ftp raw commands.

Specified by:
undoRawCommands in interface FtpFileClient
Parameters:
tncr - An instance of TransferNamesAndCommands.
Throws:
FtpFileException - If some error occurs.

get

public void get()
         throws FtpFileException
Retrieves a file from the remote FTP server. This method retrieves the first matching entry under your directory and file name. It is exposed in ETD structure and takes the e*Way Connection's configuration parameters as its input. The method encapsulates all necessary FTP operations. Note: If no qualified file is available for retrieving, you will get the exception containing java.io.FileNotFoundException as a nested exception.

Specified by:
get in interface FtpFileClient
Throws:
FtpFileException - If some error occurs.

getIfExists

public void getIfExists()
                 throws FtpFileException
per QAI 94512 - requested by eXchange team same as get() but will return siliently if the target does not exists;

Specified by:
getIfExists in interface FtpFileClient
Throws:
FtpFileException - If some error occurs.

getLogger

protected com.stc.connector.logging.Logger getLogger()

Sun Adapter for Batch/FTP