JCA for SSH is powerful connector, yet simple to use to connect to legacy or remote systems via SSH. It also provides the functionality to upload and downloads file using sFTP.
This release support the outbound only. The future release will contain the inflow or inbound functionality that will receive messages from legacy systems.
JCA for SSH is powerful connector, yet simple to use to connect to legacy or remote systems via SSH. It also provides the functionality to upload and downloads file using sFTP.
JCA for SSH not only provide the SSH functionality, it also provide the sFTP functionality on the same connection.
JCA for SSH is used in J2EE environment when connecting from container components such as EJBs, servlet to an EIS systems. More Information can be found at: JCA Overview
The picture below shows the different components that can be inserted into the architecture. JCA for SSH makes sure that the connection pool is maintained and reconnects automatically in case of connection failure or disconnect from the remote host.
JCA for SSH is built on JBoss, but can run on any other container.
The following jar are required:
Unzip JCA-FOR-SSH-x.x.x.zip and deploy it into JBoss or any other container. The .rar file contains the JCA adapter and the .war file contain the test servlet.
Define the DataSource
We need to define our Datasource, in order to do so, we create an XML descriptor of the datasource. Below is the description of the datasource.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE connection-factories PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN" "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd"> <connection-factories> <no-tx-connection-factory> <jndi-name>ra/jca-test</jndi-name> <rar-name>ssh-pool-1.0.0.rar</rar-name> <connection-definition>javax.resource.cci.ConnectionFactory</connection-definition> <config-property name="hostname" type="java.lang.String">localhost</config-property> <config-property name="username" type="java.lang.String">user</config-property> <config-property name="password" type="java.lang.String">password</config-property> <min-pool-size>3</min-pool-size> <max-pool-size>10</max-pool-size> </no-tx-connection-factory> </connection-factories>
The JNDI_NAME is set to ra/jca-test.
we are using CCI (Common Client Interface) as Connection Factory.
We specify the hostname and the credentials.
min-pool-size specifies the minimum number of connection that shall be maintained
by the container's ConnectionManager.
max-pool-size specifies the maximum number of connection for this connector.
private Context getInitialContext() throws NamingException
{ Hashtable props = new Hashtable(); String providerUrl = ""; props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); props.put(Context.PROVIDER_URL,"jnp://localhost:1099"); Context ctx = new InitialContext(props); return ctx; }
//Get the Initial Context Context context = getInitialContext(); Object obj = context.lookup("java:ra/jca-test"); // get the Connection Factory ConnectionFactory connectionFactory = (ConnectionFactory)obj; // Get a connection Connection connection = connectionFactory.getConnection();
//Create an Interaction Interaction interaction = connection.createInteraction(); //Create an Interaction Record Factory RecordFactory recordFactory = connectionFactory.getRecordFactory(); //Create the Record that will contain the command MappedRecord mappedRecord = recordFactory.createMappedRecord("dir > /tmp/Test.txt"); //Execute the command on the legacy system Record resultRecord = interaction.execute(null, mappedRecord); // If you are expecting result back. System.out.println("Result: " + resultRecord.getRecordName());
For SFTP, we have defined our own interface that inherits from CCI connection.
IEisConnection eisConn = (IEisConnection) connection; //We will ftp over the file create by the previous command.
String remoteFile = "/tmp/Test.txt"; String toLocal = "C:\\Test.txt"; eisConn.get(toLocal, remoteFile); eisConn.close();
It is recommended to use the CCI API but not mandated. The details for this API
can be found at:
CCI Connection
The IEis API documentation can be found at:
FTP Interface
This is the first initial release