Sun Adapter for Batch Tutorial

The prjBatch_Secure Project

This topic provides an overview of the prjBatch_Secure Project, and describes how to run the imported sample.

The prjBatch_Secure Project contains three scenarios that employ three Batch OTDS to enable SSL or SSH secure file transfers.

The prjBatch_Secure Project Components

TheprjBatch_Secure Project uses four External Applications, seven component Adapters, and three Java Collaborations.

The Sun Adapter for Batch performs the following functions

The prjBatch_Secure Project Collaboration Definitions

The prjBatch_Secure Project includes three Java Collaborations, one for each of the three scenarios provided in the cmBatch_Secure Connectivity Map. The jcdBatchFTPOverSSL, jcdBatchSCP, and jcdBatchSFTP Java Collaboration Definitions are each created using the Collaboration Definition Wizard (Java).

ProcedureTo Create the jcdBatchFTPOverSSL Java Collaboration

  1. From the Project Explorer, right-click the prjBatch_Secure Project and select New⇒Collaboration Definition (Java) from the context menu.

    The Java Collaboration Definition Wizard appears.

  2. Enter a Collaboration Definition name (for this Project, use jcdBatchFTPOverSSL) and click Next.

  3. For Step 2 of the Wizard, from the Web Services Interfaces selection window, double-click CAPS Components Library⇒Adapters⇒File⇒FileClient⇒receive.

    The Name field now displays receive.

  4. Click Next.

  5. For Step 3 of the Wizard, from the Select OTDs selection window, double-click CAPS Components Library⇒Adapters⇒BatchAdapter⇒BatchFTPOverSSL.

    The jcdBatchFTPOverSSL OTD is added to the Selected OTDs field.

  6. Click the Up One Level button to return to the Repository directory.

  7. Double-click CAPS Components Library ⇒ Adapters ⇒ File ⇒ FileClient.

    The FileClient OTD is added to the Selected OTDs field.

  8. Click Finish.

    The Java Collaboration Editor opens to the new Collaboration in the right pane of the NetBeans IDE.

ProcedureTo Create the jcdBatchSCP Java Collaboration

  1. To create the jcdBatchSCP Collaboration, follow the procedures in the To Create the jcdBatchFTPOverSSL Java Collaboration, replacing the Collaboration name with jcdBatchSCP, and selecting only the BatchSCP OTD for Step 4 of the Wizard.

ProcedureTo Create the jcdBatchSFTP Java Collaboration

  1. To create the jcdBatchSFTP Collaboration, follow the procedures in the To Create the jcdBatchFTPOverSSL Java Collaboration, replacing the Collaboration name with jcdBatchSFTP, and selecting only the BatchSFTP OTD for Step 4 of the Wizard.

Collaboration Business Rules

The Java Collaboration Business Rules for the Project are separated into three Java Collaborations as seen from the Java Collaboration Editor: jcdBatchFTPOverSSL, jcdBatchSCP, and jcdBatchSFTP. The following images display the business rules for each of the Java Collaboration Definitions along with the Java source code.

jcdBatchFTPOverSSL Business Rules

Image shows the business rules for the jcdBatchFTPOverSSL
Java Collaboration Definition

jcdBatchFTPOverSSL Java Source File


package prBatch_Secure;


public class jcdBatchFTPOverSSL
{

    public com.stc.codegen.logger.Logger logger;

    public com.stc.codegen.alerter.Alerter alerter;

    public com.stc.codegen.util.CollaborationContext collabContext;

    public com.stc.codegen.util.TypeConverter typeConverter;

    public void receive( com.stc.connector.appconn.file.FileTextMessage 
input, com.stc.connector.batchadapter.appconn.ftps.FTPOverSSL 
BatchFTPOverSSL_1,com.stc.connector.appconn.file.FileApplication FileClient_1 )
        throws Throwable
    {
        // get and put
        BatchFTPOverSSL_1.getConfiguration().setLocalFile( 
"FTPOverSSL_from_remote.txt" );
        BatchFTPOverSSL_1.getClient().get();
        BatchFTPOverSSL_1.getConfiguration().setRemoteFile( 
"FTPOverSSL_to_remote.txt" );
        BatchFTPOverSSL_1.getClient().put();
        // download and upload
        BatchFTPOverSSL_1.getConfiguration().setLocalDirectory( 
"c:/BatchSecurity/FTPOverSSL" );
        BatchFTPOverSSL_1.getConfiguration().setLocalFile( 
"FTPOverSSL_from_remote.txt" );
        BatchFTPOverSSL_1.getClient().download();
        BatchFTPOverSSL_1.getConfiguration().setRemoteDirectory( 
"BatchSecurity/FTPOverSSL" );
        BatchFTPOverSSL_1.getConfiguration().setRemoteFile( 
"FTPOverSSL_to_remote.txt" );
        BatchFTPOverSSL_1.getClient().upload();
        // Create and list directories
        String entryInfo;
        int entryCnt;
        for (int i = 1; i < 6; i++) {
            BatchFTPOverSSL_1.getClient().mkdir( "mydir_" + i );
        }
        BatchFTPOverSSL_1.getClient().listDirLong();
        entryCnt = BatchFTPOverSSL_1.getClient().getEntryCount();
        entryInfo = "Directory Listing:\n";
        for (int i = 0; i < entryCnt; i++) {
            entryInfo = "[" + BatchFTPOverSSL_1.getClient().getEntry( 
i ).getDirectory() + "]" + "[" + BatchFTPOverSSL_1.getClient().getEntry( 
i ).getFile() + "]" + "[" + BatchFTPOverSSL_1.getClient().getEntry( i ).
getFileSize() + "]" + "[" + BatchFTPOverSSL_1.getClient().getEntry( 
i ).isDir() + "]" + "\n";
        }
        FileClient_1.setText( entryInfo );
        FileClient_1.write();
        // Delete and list directories
        for (int i = 1; i < 5; i++) {
            BatchFTPOverSSL_1.getClient().deleteDir( "mydir_" + i );
        }
        BatchFTPOverSSL_1.getClient().listDir();
        entryCnt = BatchFTPOverSSL_1.getClient().getEntryCount();
        entryInfo = "Directory Listing:\n";
        for (int i = 0; i < entryCnt; i++) {
            entryInfo = "[" + BatchFTPOverSSL_1.getClient().getEntry( 
i ).getDirectory() + "]" + "\n";
        }
        FileClient_1.setText( entryInfo );
        FileClient_1.write();
    }

}

jcdBatchSCP Business Rules

Image shows the business rules for the jcdBatchSCP Java
Collaboration Definition

jcdBatchSCP Java Source File


package prBatch_Secure;


public class jcdBatchSCP
{

    public com.stc.codegen.logger.Logger logger;

    public com.stc.codegen.alerter.Alerter alerter;

    public com.stc.codegen.util.CollaborationContext collabContext;

    public com.stc.codegen.util.TypeConverter typeConverter;

    public void receive( com.stc.connector.appconn.file.FileTextMessage input, 
com.stc.connector.batchadapter.appconn.scp.SCP BatchSCP_1 )
        throws Throwable
    {
        // recursive get and put
        BatchSCP_1.getConfiguration().setLocalDirectory( "C:/BatchSecurity/SCP" );
        BatchSCP_1.getConfiguration().setLocalFile( "recursive" );
        BatchSCP_1.getClient().getRecursive();
        BatchSCP_1.getConfiguration().setRemoteDirectory( "BatchSecurity/SCP" );
        BatchSCP_1.getConfiguration().setRemoteFile( "recursive" );
        BatchSCP_1.getClient().putRecursive();
    }

}

jcdBatchSFTP Business Rules

Image shows the business rules for the jcdBatchSFTP Java
Collaboration Definition

jcdBatchSFTP Java Source File


package prBatch_Secure;


public class jcdBatchSFTP
{

    public com.stc.codegen.logger.Logger logger;

    public com.stc.codegen.alerter.Alerter alerter;

    public com.stc.codegen.util.CollaborationContext collabContext;

    public com.stc.codegen.util.TypeConverter typeConverter;

    public void receive( com.stc.connector.appconn.file.FileTextMessage input, 
com.stc.connector.batchadapter.appconn.sftp.SFTP BatchSFTP_1 )
        throws Throwable
    {
        // get, make directory, change directory, put, rename, delete
        BatchSFTP_1.getConfiguration().setLocalDirectory( "C:/BatchSecurity/SFTP" );
        BatchSFTP_1.getConfiguration().setLocalFile( "SFTP_from_remote.txt" );
        BatchSFTP_1.getClient().get();
        BatchSFTP_1.getClient().mkdir( "BatchSecurity/new_SFTP" );
        BatchSFTP_1.getClient().cd( "BatchSecurity/new_SFTP" );
        BatchSFTP_1.getConfiguration().setRemoteDirectory( "" );
        BatchSFTP_1.getConfiguration().setRemoteFile( "SFTP_to_remote.txt" );
        BatchSFTP_1.getClient().put();
        BatchSFTP_1.getClient().rename( "BatchSecurity/new_SFTP/SFTP_to_remote.txt", 
"BatchSecurity/new_SFTP/renamed_SFTP_to_remote.txt" );
        BatchSFTP_1.getClient().delete( "BatchSecurity/useless_SFTP.txt" );
    }

}

Completing the prjBatch_Secure Project

Import the prjBatch_Secure Project described in To Import a Non-JBI Based Sample Project. After the sample Project has been imported and appears in your Project Explorer tree, create the Project’s Environment.

ProcedureTo Create an Environment

Environments include the External Systems, Logical Hosts, Sun Java System Application Servers and Message Servers used by a Project and contain the configuration information for these components.

  1. From the NetBeans IDE click the Services tab.

  2. Right-click the Repository and select New Environment.

    A new Environment is added to the Services tree.

  3. Rename the new Environment to envBatch_Secure.

  4. Right-click envBatch_Secure and select New⇒BatchFTPOverSSL External System.

  5. Name this External System esBatchFTPOverSSL.

    The esBatchFTPOverSSL window is added to the Environment Editor.

  6. Right-click envBatch_Secure and select New⇒BatchSCP External System.

  7. Name this External System esBatchSCP.

    The esBatchSCP window is added to the Environment Editor.

  8. Right-click envBatch_Secure and select New⇒BatchSFTP External System.

  9. Name this External System esBatchSFTP.

    The esBatchSFTP window is added to the Environment Editor.

  10. Right-click envBatch_Secure and select New⇒File External System.

  11. Name the External System esFile and click OK.

    The esFile window is added to the Environment Editor.

  12. Right-click envBatch_Secure and select New⇒Logical Host.

    The LogicalHost1 box is added to the Environment and LogicalHost1 is added to the Environment Editor tree.

  13. From the Services tree, right-click LogicalHost1 and select New⇒Sun Java System Application Server.

    A new Sun Java System Application Server is added to the Services tree under Localhost1.

  14. Save the Project.

Configuring the Adapter Properties

The prjBatch_Secure Project uses seven component Adapters, each represented in the Connectivity Map as a node between an External Application and the Service.

ProcedureTo Configure the File Adapter Connectivity Map properties

  1. From the Connectivity Map, double-click the inbound FileIn_BatchFTPOverSSL Adapter between the FileIn_BatchFTPOverSSL External Application and the jcolBatchFTPOverSSL1 service.

    The Properties Editor opens to the inbound File Adapter properties.

  2. Modify the configuration for your system, including the settings in the following table.

    Inbound File Adapter Connectivity Map Properties 

    Parameter Settings - Set as directed, otherwise use the default settings

    Input File Name 

    FileIn_BatchFTPOverSSL.txt

  3. From the Connectivity Map, modify the inbound FileIn_BatchSFTP Adapter between the FileIn_BatchSFTP External Application and the jcolBatchSFTP1 service.

    See the following table.

    Inbound File Adapter Connectivity Map Properties 

    Parameter Settings - Set as directed, otherwise use the default settings

    Input File Name 

    FileIn_BatchSFTP.txt

  4. From the Connectivity Map, modify the inbound FileIn_BatchSCP Adapter between the FileIn_BatchSCP External Application and the jcolBatchSCP1 service.

    See the following table.

    Inbound File Adapter Connectivity Map Properties 

    Parameter Settings - Set as directed, otherwise use the default settings

    Input File Name 

    FileIn_BatchSCP.txt

  5. From the Connectivity Map, modify the Outbound FileOut_BatchFTPOverSSL Adapter between the FileOut_BatchFTPOverSSL External Application and the jcolBatchFTPOverSSL1 service.

    See the following table.

    Outbound File Adapter Connectivity Map Properties 

    Parameter Settings - Set as directed, otherwise use the default settings

    Output File Name 

    FileOut_BatchFTPOverSSL.dat

ProcedureTo Modify the File Adapter Environment properties

  1. From the Services tree, right-click the esFile External System, and select Properties.

    The Properties Editor opens to the File Adapter Environment properties.

  2. Modify the File Adapter Environment properties for your system, including the settings in the following table, and click OK.

    File Adapter Environment Properties 

    Inbound File Adapter ⇒ Parameter Settings - Set as directed, otherwise use the default settings.

    Directory 

    An input directory on your system that the inbound File Adapters poll and pick up any specified input files. 

    Outbound File Adapter ⇒ Parameter Settings - Set as directed, otherwise use the default settings.

    Directory 

    An output directory to which the outbound File Adapter publishes (writes) the output messages. 

ProcedureTo Modify the Batch/FTP Adapter Connectivity Map Properties

  1. From the Connectivity Map, double-click the BatchFTPoverSSL1 Adapter, located between the BatchFTPOverSSL1 External Application and the jcolBatchFTPOverSSL1 service.

    The Adapter Properties Editor appears.

  2. Modify the BatchFTPoverSSL Adapter Connectivity Map properties for your system, including the settings in the following table, and click OK.

    BatchFTPoverSSL Adapter Connectivity Map Properties 

    FTP and SSL Settings - Set as directed, otherwise use the default settings

    Local Directory 

    The local directory name and path for files that are sent to or received from a remote system. The default is X:/Batch51 

    Target File Name 

    The name of the remote file. 

ProcedureTo Modify the BatchFTPoverSSL Adapter Environment Properties

  1. From the Services tree, right-click the BatchFTPoverSSL External System (in this Project, esBatchFTPoverSSL ), and select Properties.

    The Properties Editor opens to the BatchFTPoverSSL Adapter Environment properties.

  2. Modify the BatchFTPoverSSL Adapter Environment properties for your system, including the settings in the following table, and click OK.

    BatchFTPoverSSL Adapter Environment Properties 

    FTP and SSL Settings - Set as directed, otherwise use the default settings.

    Host Name 

    Host name or IP of the FTP server 

    Server Port 

    Port number to use to connect to the FTP server 

    User Name 

    User ID used to log into the system 

    Password 

    Password required to log into the system 

    Configure the Adapter properties for your system.

ProcedureTo Create the Sample Directories

The prjBatch_Secure sample Project uses a number of directories.

  1. Create the directories associated with Adapter configuration properties:

    • Target Directory (Inbound File Adapter Environment Properties):

      Select a name for your target directory.

    • Output Directory (Outbound File Adapter Environment Properties):

      Select a name for your output directory.

    Create these directories on your system, or change the properties to reference your existing directories.

ProcedureTo Create the Deployment Profile

A Deployment Profile is used to assign Collaborations and message destinations to the Sun Java System Application Server and message server. Deployment profiles are created using the Deployment Editor.

  1. From the Enterprise Explorer’s Project Explorer, right-click the Project (prjBatch_Secure) and select New⇒Deployment Profile.

  2. Enter a name for the Deployment Profile (for this sample dpBatch_Secure).

  3. Make sure that the selected Environment is envBatch_Secure and click OK.

  4. Click Automap.

    The Project’s components are automatically mapped to their respective system windows.


    Note –

    If any of your Project components did not successfully map to an external system, open each of your Adapter’s configuration properties (Connectivity Map and Environment) and click OK to close and save the current configuration, then click Automap again.


  5. Save the Project.

Creating and Starting the Domain

A domain is an instance of a Logical Host. After the domain is created, the Project is built and then deployed.

ProcedureTo Create and Start the Domain

  1. Navigate to your JavaCAPS6\logicalhost directory, where JavaCAPS6 is the location of your Java CAPS installation.

  2. Double-click the domainmgr.bat file.

    The Domain Manager appears.

  3. Do one of the following:

    • If you have already created a domain, select your domain in the Domain Manager and click Start an Existing Domain.

    • If there are no existing domains, click Yes.

      The Create Domain dialog box appears.

      1. Make any necessary changes to the Create Domain dialog box and click Create.

      2. Select the domain and click the Start an Existing Domain button

      The new domain is added to the Domain Manager.

    • Once your domain is started, a green check mark indicates that the domain is running.

Building and Deploying the Project

The Build process compiles and validates the Project’s Java files and creates the Project EAR file.

ProcedureTo Build the Project

  1. From the Deployment Editor toolbar, click the Build icon.

    If there are any validation errors, a Validation Errors pane will appear at the bottom of the Deployment Editor and displays information regarding the errors.

  2. Make any necessary corrections and click Build again.

ProcedureTo Deploy the Project

  1. From the Deployment Editor toolbar, click the Deploy icon.

    The Deploy prompt appears.

  2. Click Yes.

    A message appears when the project is successfully deployed.

ProcedureTo Run the Sample

To run your deployed sample Project do the following

  1. From your configured input directory, paste (or rename) the sample input file to trigger the Adapter.

  2. From your output directory, verify the output data.


    Note –

    For UNIX, be sure to upload the appropriate LogicalHost.