SourceForge.net Logo

TxConnect:

The JCA transactional connector

 

 

 

By

Sadi Melbouci

<sadi_melbouci@sourceforge.net>


 

Table of Contents

 

Downloads. 2

License. 2

Overview.. 2

Architecture. 3

System contracts. 3

Client API 4

Resource Adapter module. 4

Handling of Connections. 5

Managing Connections. 5

Connection Pooling. 5

Transaction Management 6

Building an Adapters. 8

Dependencies. 12

Usage. 12

APIs. 16

Support 16

Release Notes. 16

 



Downloads

Download TxConnect downloads

 

License

TxConnect is licensed under  GNU Lesser General License (LGPL).

LICENSE

 

Overview

TxConnect is a JCA compliant universal connector written in accordance to Sun’s JCA specifications (JSR016). It connects J2EE based applications to legacy systems. It generically handles multiple protocols by providing an adapter for each type of protocol.

TxConnect manages a pool of re-usable connections, security and transactions. The java application gets the ConnectionFactory from JNDI and then requests a Connection handle and all the functions of pooling, security and transactions are provided.

It propagates the transactions from the J2EE container to the legacy systems or Enterprise Information System (EIS) without requiring any change to the legacy systems or applications.

 

TxConnect supports both XA Transaction as well as Local Transactions.

 

TxConnect comes with an SSH, sFTP, Telnet and Socket adapters and will be extended to support SAP, IMS, CICS, MVS, TP8 and TDS.

 

TxConnect is bi-directional, so that the J2EE application can submit real time transactional requests to the legacy application and receive the responses as speedily and reliably as using natively the legacy application.

 

TxConnect can be installed on any J2EE compliant container and provides a single interface to access all the type of legacy systems.

 

 


Architecture

The following diagram depicts the high level components that participate in the End2End transaction.

 

Figure1. End 2 End components

 

The Data Source Connector is responsible for implementing the JCA TxConnect connector. The Gateway component can be a session façade to the connector that advertises the functions performed by the connector to the business tier.

 

The TxConnect is the Data Source Connector that is based on JCA specifications defined in the JSR 016 and implements the following contracts:

 

System contracts
System contracts define the connection between the application server and the EIS. The EIS side of the system contract is implemented by a resource adapter -- a system-level software driver or adapter specific to the EIS (Telnet, SSH, Socket …etc). The application server and the resource adapter collaborate by means of the system contract to provide secure, robust, scalable access to the EIS.
Three types of system contracts are defined:



Client API
The second element of JCA is the client API. The API can be specific to the resource adapter or it can be the standard Common Client Interface (CCI) as defined by JCA. The CCI is meant to be used by vendors to provide integration tools and frameworks, making it easier for developers to access enterprise systems. It is recommended (but not mandated) that the resource adapter make use of the CCI.

TxConnect defines a single interface for all type of EIS applications; it is a combination between CCI and TxConnect custom interface.


Resource Adapter module
The resource adapter module contains all of the elements necessary to provide EIS connectivity to applications. Specifically, the resource adapter module includes the following components:
- The Java classes and interfaces that implement the resource adapter
- Any utility Java classes required by the resource adapter
- Any EIS-specific platform-dependent native libraries
- The deployment descriptor
Application servers make use of the deployment descriptor supplied with a resource adapter to configure it to a specific operational environment.

 

 

The figure 2 provides a class diagram of the JCA TxConnect connector.

 

Figure 2: TxConnect Class Diagram

 



Handling of Connections
An application component accesses the resource adapter through ConnectionFactory and Connection interfaces, which are provided by the resource adapter implementer. These interfaces can be CCI interfaces (javax.resource.cci.ConnectionFactory and javax.resource.cci.Connection) or they can be specific to the resource adapter. The classes that implement these interfaces are also provided with the resource adapter. The connection factory is obtained through the Java Naming and Directory Interface (JNDI) so that the application need have no knowledge of the underlying implementation class. Once the connection factory is retrieved, a connection is obtained from the connection factory through the getConnection() method. At least one getConnection() method must be provided by the connection factory, though more may be provided. It is important to note that a Connection is an application-level handle to an underlying physical connection to the EIS, represented by a EisManagedConnection. Once the application component is finished with the connection, it calls the close() method on the connection. This method must delegate the close to the EisManagedConnection that created the connection handle. Closing a connection handle should not close the physical connection to the EIS, it only returns it to the pool.

Managing Connections
The getConnection() method in the connection factory does not actually create a connection;
it calls the allocateConnection() method on its associated ConnectionManager.
The ConnectionManager interface is implemented by the application server (JBoss, WebLogic, WebSpehere …etc).
It is associated with a connection factory in an implementation-specific manner when the connection factory is instantiated. The call to the ConnectionManager allows the application server to "hook in" to the resource adapter functionality to provide pooling, transaction, and security services. A ConnectionRequestInfo object may be passed to allocateConnection() to pass connection request-specific information.
The ConnectionManager, in turn, calls on a ManagedConnection to obtain the connection handle. The connection handle is passed back through the ConnectionManager to the connection factory and on to the application component.

Connection Pooling
The resource adapter provides a class that implements the ManagedConnectionFactory interface. The EisManagedConnectionFactory class acts as a factory for both connection factory instances and EisManagedConnection instances. When the application server needs to create a connection factory, it calls the createConnectionFactory() method, passing in an instance of ConnectionManager; this is the instance that is called when the application component calls getConnection() on the connection factory, as discussed previously.

The application server uses one of two ManagedConnectionFactory methods to create or request managed connections. When the server requires a new instance of ManagedConnection, it calls the createManagedConnection() method. When the server wants to re-use an existing EisManagedConnection, it calls the matchManagedConnections() method. To find the right match, the server passes in a set of EisManagedConnections that could possibly meet the criteria of the requested connection, along with information about the desired connection type. Internally, the matchManagedConnection() method compares this information with the candidate set to determine if a match can be made. If so, it returns the matching EisManagedConnection; if not, it returns null.

Transaction Management

TxConnect supports both XA Transaction as well as Local Transaction. It provides a way to handle loosely and tightly coupled transactions.  TxConnect implemented LocalTransaction and XAResource interfaces to respectively support local transactions and XA transactions.

When the server boots, the server read the data source file. In our case tx-connector-xs.xml.

<tx-connection-factory>

            <jndi-name>xxx</jndi-name>

            <xa-transaction />

            ……

</ tx-connection-factory>

 

<tx.connection-factory> tells the containers that the connector support transactions.

<xa-transaction> element indicates that the connector supports XA Transaction.

 

<xa-transaction/> can be replaced by <local-transaction/> to support local transactions only.

JCA provides 2 options for transaction support: programmatic and declarative transaction demarcation. The first option requires that use Java Transaction API (JTA) to write explicit code for begin, commit and rollback operations.

The second option is throw an EJB that will configure a transactional behavior as show the following ejb-jar.xml:

 

   <container-transaction >

      <method >

         <ejb-name>TxConnectFacade</ejb-name>

          <method-name>*</method-name>

       </method>

       <trans-attribute>Required</trans-attribute>

    </container-transaction>

 

   <resource-ref >

            <res-ref-name>ra/jssh-tx-connector</res-ref-name>

            <res-type>javax.resource.cci.ConnectionFactory</res-type>

            <res-auth>Container</res-auth>

   </resource-ref>

 

<trans-attribute>Required</trans-attribute> instructs the container to star the transaction if it’s not already started.

 

When transaction starts, the container calls getLocalTransaction() or getXAResource() on ManagedConnection to get respectively Local Transaction or XA Transaction.

 

When begin, commit or rollback transaction is invoked, the container invokes respectively begin, commit or rollback transaction on LocalTransaction interface that is implemented by EisLocalTranasction in TxConnect.

 

Similarly for when the container invokes start, prepare, commit, end or rollback, the container invokes start, prepare, commit, end or rollback on XAResource interface implemented by EisXAResource.

 

Some EIS systems don’t support transaction in conventional way. For instance, a telecom switch can be accessed through SSH and have command line to add, delete and update subscribers.

TxConnect provides a way to integrate this type of EIS application with the J2EE integrated transactional behavior by implementing transaction compensation scheme.

TxConnect provide setRollbackTx method to set the rollback command in case of failure.

 

//Get the Initial Context
Context context = getInitialContext();
Object obj  = context.lookup("java:ra/jssh-tx-connector");
// get the Connection Factory
ConnectionFactory connectionFactory = (ConnectionFactory)obj;
// Get a connection
IEisConnection connection = (IEisConnection) connectionFactory.getConnection();

connection.execute(“add –subscriber 303-555-6666 –trunk 4444 –line 6666”);

connection.setRollbackTx(“delete 303-555-6666”);

 

If the Transaction fails, the delete command will be executed on the switch and always leave the system clean and enforce the data integrity.

 

Building an Adapters

The adapter is a class that implements the interface IConnectionDriver. This interface provides a set of methods that are generic to support most of the known adapters.

The adapter is supplied to the JCA connector in the configuration. In this section, we will show how to build a sample adapter.

 

public interface IConnectionDriver

{

    /**

     * This method implements the put function of FTP and sFTP.

     * @param local: is local file name

     * @param remote: is the remote file name

     * @throws JsshException

     */

    void put(String local, String remote) throws ConnectionException;

    /**

     * This method implements the get FTP function

     * @param local

     * @param remote

     *

     */

    void get(String local, String remote)throws ConnectionException;

  

    /**

     * This method executes a command on remote EIS system and

     * return a result of the execution.

     * @param command

     * @return

     */

    String execute (String command)throws ConnectionException;

    /**

     * This method sends data to EIS server and returns response back.

     * @param message

     * @return

     */

    String send(String message)throws ConnectionException;

   

    /**

     * This method is called to receive data after the connection

     * is being made to the EIS server.

     * @return

     */

    String receive ()throws ConnectionException;

    /**

     * This method connect to EIS

     *

     */

    void connect()throws ConnectionException;

   

    /**

     * @return the hostname

     */

    public String getHostname();

    /**

     * @param hostname: the hostname to to connect to

     */

    public void setHostname(String hostname);

   /**

     * @param port the port to connect to

     */

    public void setPort(int port);

    /**

     * @return the password

     */

    public String getPassword();

    /**

     * @param password the password to set

     */

    public void setPassword(String password);

    /**

     * @return the port

     */

    public int getPort();

   

    /**

     * @return the username

     */

    public String getUsername();

    /**

     * @param username the username to set

     */

    public void setUsername(String username);

    /**

     * @return the driver

     */

    public String getPrompt();

    /**

     * @param prompt the prompt to set

     */

    public void setPrompt(String prompt);

    /**

     * @return the timeout

     */

    public int getTimeout();

    /**

     * @param timeout the timeout to set

     */

    public void setTimeout(int timeout);

}

 

 

Sample Adapter

Below is class implementing IConnectionDriver to provide a simple adapter of a Socket client. To avoid any cluttering of this code, we have removed the setters and getters and some method that are not pertinent to the socket such as get and the put.

 

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.net.Socket;

import org.apache.log4j.Logger;

 

import com.dsoft.jca.driver.ConnectionException;

import com.dsoft.jca.driver.IConnectionDriver;

 

 

/**

 * @author Sadi Melbouci

 *

 */

public class SocketAdapter implements IConnectionDriver

{

    static Logger log = Logger.getLogger(SocketAdapter.class);

   

    private String hostname = null;

    private int port = 0;

    private String username = null;

    private String password = null;

    private String prompt = null;

    private int timeout = 0;

   

    private Socket socket = null;

    private InputStream input = null;

    private OutputStream output = null;

   

    public void connect() throws ConnectionException

    {

       try

       {

           socket = new Socket(hostname, port);

           input = socket.getInputStream();

           output = socket.getOutputStream();

       }

       catch(Exception he)

       {

           log.error("Unable to connect to: " + hostname);

           throw new ConnectionException(he);

       }

    }

 

    public String execute(String command) throws ConnectionException

    {

       send(command);

       String result = receive();

       return result;

    }

    public String receive() throws ConnectionException

    {

       StringBuffer buffer = new StringBuffer();

       int bufsize = 2048;

       char[] data = null;

       try

       {

          

           int available = this.input.available();

           if (available > bufsize)

              bufsize = available;

           data = new char[bufsize];

           BufferedReader in = new BufferedReader(new InputStreamReader(input));

 

           for (;;)

           {

              log.debug("Reading from InputStream");

             

              int size = in.read(data, 0, bufsize);

              if (size <= 0)

                  break;

              String str = String.valueOf(data);

              log.debug("Received:\n"+ str);

 

              buffer.append(data, 0, size);

              for (int i = 0; i< bufsize; i++)

                    data[i] = '\0';

           }

 

       }

       catch (IOException ioe)

       {

           log.error("Socket is being closed", ioe);

           throw new ConnectionException(ioe);

       }

      

       return buffer.toString();

    }

 

    public String send(String message) throws ConnectionException

    {

       byte [] bytes = message.getBytes();

       try

       {

           log.debug("Sending:\n" + message);

           output.write(bytes);

       }

       catch (Exception e)

       {

           log.error("Unable to sent data to: " + hostname);

           throw new ConnectionException(e);

       }

       return null;

    }

}

 

 

The adapter is packaged into a jar file and supplied to the JCA configuration as a driver, the following xml data source file shows the configuration:

 

<tx-connection-factory>

              <jndi-name>ra/jssh-tx-connector</jndi-name>

              <xa-transaction />

              <rar-name>txconnect-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="port" type="java.lang.Integer">

                     22

              </config-property>

              <config-property name="username" type="java.lang.String">

                     user

              </config-property>

              <config-property name="password" type="java.lang.String">

                     password

              </config-property>

              <!-- The prompt is only used for Telnet -->

              <config-property name="prompt" type="java.lang.String">

                     ]#

              </config-property>

              <config-property name="timeout" type="java.lang.Integer">

                     30

              </config-property>

              <config-property name="driver" type="java.lang.String">

                     com.dsoft.ssh.SocketAdapter

              </config-property>

 

              <min-pool-size>1</min-pool-size>

              <max-pool-size>3</max-pool-size>

       </tx-connection-factory>

 

 


 

 

Dependencies

To build TxConnect, the following jar files should be added to the classpath:

 

log4j.jar

j2ee.jar

hibernate3.jar

activation.jar

commons-logging.jar

 

 

 

The following files are JBoss specific but any other jars provided by an application (WebLogic, WebSphere …etc) can be used.

 

jboss-common.jar

jnpserver.jar

jboss-saaj.jar

jbossall-client.jar

jboss-system.jar

jboss-management.jar

jboss-jmx.jar

javax.servlet.jar

javax.servlet.jsp.jar

jboss-jca.jar

 

In this example, we have used MySQL as our backend database to perform 2 phase commit or XA transaction. We have used MySQL connector, please download

mysql-connector-java-5.0.4-bin.jar

from MySQL Driver.

Usage

Available Adapters

The following adapters are shipped within protocols.jar file.

Adapter

Class

Description

SSH adapter

com.dsoft.ssh.SshAdapter

SSH adapter to run shell command line at the SSH connection is being established

Telnet Adapter

com.dsoft.telnet.JTelnet

 

Secure FTP Adapter

com.dsoft.ssh.SshAdapter

Secure FTP Adapter that provides secure file transfer. Also you can test the existence of a file. You can use this adapter along with the SSH commands.

Socket Adapter

Com.dsoft.socket.SocketAdapter

A Socket adapter providing a way to connect, send and receive replies from remote hosts.

 

JCA TxConnect Settings

 The XML file below show the JCA adapter data source file can be deployed to an application server.

 

<connection-factory>

<tx-connection-factory>

              <jndi-name>ra/jssh-tx-connector</jndi-name>

              <xa-transaction />

              <rar-name>txconnect-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="port" type="java.lang.Integer">

                     22

              </config-property>

              <config-property name="username" type="java.lang.String">

                     user

              </config-property>

              <config-property name="password" type="java.lang.String">

                     password

              </config-property>

              <!-- The prompt is only used for Telnet -->

              <config-property name="prompt" type="java.lang.String">

                     ]#

              </config-property>

              <config-property name="timeout" type="java.lang.Integer">

                     30

              </config-property>

              <config-property name="driver" type="java.lang.String">

                     com.dsoft.ssh.SshAdapter

              </config-property>

 

              <min-pool-size>1</min-pool-size>

              <max-pool-size>3</max-pool-size>

 

       </tx-connection-factory>

</connection-factory>

 

Attribute

Description

Required

tx-connection-factory

Indicates to the container that transaction is enabled.

Y

xa-transaction

XA transaction is enabled for this connector. this can be substituted by local-transaction

N

jndi-name

JNDI Name

Y

rar-name

Deployable rar file

Y

connection-definition

Connection Interface used by TxConnect

Y

hostname

Host to connect to.

Y

port

Port Number to connect to. Optional for Telnet and SSH.

N

prompt

Valid for telnet only, prompt on the remote machine

N

username

Credentials: username

N

password

Credentials: password

N

timeout

Connection Timeout.

N

driver

The Adapter Class, It can be SSH-Adapter, Telnet Adapter, Socket Adapter or any other custom adapter that you implement.

Y

 

Data Access Settings

We have used Hibernate managed by JMX. We will not provide all the details on the setting of this implementation, but we will provide the key features that will serve us to enable XA transaction.

The following file (hibernate-service.xml) is packaged along the .har file.

The .har file contains the dtos and hbm.xml files.

 

<server>

       <mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=test_MySQL">

              <attribute name="DatasourceName">java:/testDS</attribute> 

              <attribute name="SessionFactoryName">java:/hibernate/TEST_SESSION</attribute>

  </mbean>

</server>

 

The following XML file is the data source file that provides information to the container about the database connectivity and ties it with the .har file through the DatasourceName attribute (hibernate-service.xml) to the JNDI name defined in the Data Source file.

 

<datasources>

       <xa-datasource>

              <jndi-name>testDS</jndi-name>

              <track-connection-by-tx>true</track-connection-by-tx>

              <isSameRM-override-value>false</isSameRM-override-value>

              <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>

              <xa-datasource-property name="URL">

                     jdbc:mysql://localhost:3306/test

              </xa-datasource-property>

              <xa-datasource-property name="User">

                     mysql

              </xa-datasource-property>

              <xa-datasource-property name="Password">

                     mysql

              </xa-datasource-property>

              <exception-sorter-class-name>

                     org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter

              </exception-sorter-class-name>

              <dialect>org.hibernate.dialect.MySQLDialect</dialect>

              <no-tx-separate-pools />

              <metadata>

                     <type-mapping>mySQL</type-mapping>

              </metadata>

       </xa-datasource>

       <!--

       <local-tx-datasource>

              <jndi-name>dsoft-DS</jndi-name>

              <connection-url>jdbc:mysql://rhel-tts5:3306/tts</connection-url>

              <driver-class>com.mysql.jdbc.Driver</driver-class>

              <user-name>mysql</user-name>

              <password>mysql</password>

              <exception-sorter-class-name>

                     org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter

              </exception-sorter-class-name>

             

              <dialect>org.hibernate.dialect.MySQLDialect</dialect>

 

              <metadata>

                     <type-mapping>mySQL</type-mapping>

              </metadata>

       </local-tx-datasource>

       -->

</datasources>

 

As you may notice, xa-datasource enables XA Transaction to take place when local-transaction enables local transaction.

 

To run this example, you need to install MySQL database MySQL Database .

Create Database called test if it’s not already created.

 

From your command prompt:

$ mysql

mysql > Create database test;

 

Create the test table using the following script:

 

CREATE TABLE properties (

name VARCHAR(45) NOT NULL

, value VARCHAR(128) NOT NULL

, description VARCHAR(255)

, PRIMARY KEY (name)

) ENGINE=InnoDB;

 

 

Below is the sample EJB code that accesses the database and EIS in the same transaction. The method addProperty() insert a property into the database and write it into a file on some remote system. In case of failure, the database transaction is rolled back and the file created on remote system gets deleted.

The EJB uses a Utility class to access the connector.

 

import java.rmi.RemoteException;

import javax.ejb.EJBException;

import javax.ejb.SessionBean;

import javax.ejb.SessionContext;

 

import javax.ejb.CreateException;

 

import org.apache.log4j.Logger;

 

import examples.com.dsoft.bis.delegate.EisDelegate;

import examples.com.dsoft.data.dao.PropertiesDao;

import examples.com.dsoft.data.dto.Properties;

 

/**

* @ejb.bean name="TxConnectFacade" display-name="Name for TxConnectFacade"

* description="Description for TxConnectFacade"

* jndi-name="ejb/TxConnectFacade" type="Stateless" view-type="both"

*

* @ejb.transaction type="Required"

*

* @ejb.resource-ref

* res-auth="Container"

* jndi-name="ra/jssh-tx-connector"

* res-type="javax.resource.cci.ConnectionFactory"

* res-ref-name="ra/jssh-tx-connector"

*

*

*

* @author Sadi Melbouci

*

*/

public class TxConnectFacadeBean implements SessionBean

{

static Logger log = Logger.getLogger(TxConnectFacadeBean.class);

 

……

/**

* @ejb.interface-method view-type = "both"

*

* @param name

* @param value

* @param desc

*/

public void addProperty(String name, String value, String desc)

{

try

{

EisDelegate delegate = new EisDelegate();

//

// Create the CSV file

//

String command = "touch properties.txt; echo " + value + "," + name

+ "," + desc + "\\n >> /tmp/properties.txt";

// In case of Rollback, delete the whole file

delegate.setTxRollBack("/bin/rm /tmp/properties.txt");

delegate.execute(command);

PropertiesDao dao = new PropertiesDao();

Properties instance = new Properties(name, value, desc);

dao.attachDirty(instance);

 

}

catch (Exception e)

{

log.error("An error occured during the Property Creation", e);

throw new EJBException(

"Problem happened during transaction processing");

}

}

 

}

 

Notice the EJB annotation that references the connector and Transaction type.

 

Below is the Utility class that wraps the operations that can be performed on the Connector.


import java.util.Hashtable;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NamingException;

import javax.resource.cci.Connection;

import javax.resource.cci.ConnectionFactory;

import javax.resource.cci.Interaction;

import javax.resource.cci.MappedRecord;

import javax.resource.cci.Record;

import javax.resource.cci.RecordFactory;

 

import org.apache.log4j.Logger;

 

import com.dsoft.jca.driver.ConnectionException;

import com.dsoft.jca.eis.IEisConnection;

 

/**

 * @author Sadi Melbouci

 *

 */

public class EisDelegate

{

    static Logger log = Logger.getLogger(EisDelegate.class);

   

    private IEisConnection connection = null;

    private ConnectionFactory connectionFactory = null;

    private Context ctx = null;

   

   

    public EisDelegate() throws Exception

    {

                    try

                    {

                        ctx = getInitialContext();

                        Object obj  = ctx.lookup("java:ra/jssh-tx-connector");

                        connectionFactory = (ConnectionFactory)obj;

            Connection con = connectionFactory.getConnection();

            connection = (IEisConnection) con;

                    }

                    catch (NamingException ne)

                    {

                        throw new Exception (ne.getMessage());

                    }

    }

   

   

    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;

    }

   

    public String process(String command)

    {

                    String res = null;

                   

                    try

                    {

            Interaction interaction = connection.createInteraction();

            System.out.println("EisBean interaction = " + interaction);

            RecordFactory recordFactory = connectionFactory.getRecordFactory();

            System.out.println("EisBean recordFactory = " + recordFactory);

            MappedRecord mappedRecord = recordFactory.createMappedRecord(command);

            System.out.println("EisBean mappedRecord = " + mappedRecord);

            Record resultRecord = interaction.execute(null, mappedRecord);

            System.out.println("EisBean resultRecord = " + resultRecord);

                        

                        res = resultRecord.getRecordName();

                        connection.close();

                    }

                    catch (Exception ne)

                    {

                        System.out.println("Error When invoking Pool");

                        ne.printStackTrace();

                    }

                   

                    return res;

    }

   

    public void setTxRollBack(String command)

    {

                    connection.setRollbackTx(command);

    }

   

    public String execute (String command)

    {

                    String result = null;

                    try

                    {

                        result = connection.execute(command);

                    }

                    catch (ConnectionException ce)

                    {

                        log.error("Unable to execute the command");

                    }

                    finally

                    {

                        try

                        {

                                         connection.close();

                        }

                        catch (Throwable e)

                                         {

                                             log.error("Unable to close the connection", e);

                                         }

                    }

                    return result;

    }

 

    //

    // For instance, If you would like to send a message

    // over a socket, you can use this method.

    //

   

    public String send (String message)

    {

         String result = null;

         try

         {

             result = connection.send(message);

         }

         catch(Exception e)

         {

             log.error("Unable to send a message", e);

         }

         return result;

    }

   

    //

    // To receive a socket message (Not listening on socket)

    // You can use this method

    //

    public String receive()

    {

         String result = null;

         try

         {

             result = connection.receive();

         }

         catch(Exception e)

         {

             log.error("Unable to receive a message", e);

         }

         return result;

    }

}

 

 

 

Download Content

The download Zip file contains the binaries to deploy and test TxConnect:

txconnect-1.0.0.rar is the JCA connector.
mysql-ds.xml is the datasource configuration to access the MySQL database.
tx-connector-ds.xml is connector configuration file.
protocols.jar contains the protocols adapters (ssh, telnet, sFTP and Socket).
container-web.war contain a servlet to test the connector.
example.ear contains an EJB to test the connector.

Copy these files into JBoss deploy directory and it's ready to go.

Go http://localhost:8080/connector-web/Connector

This will invoke a simple servlet. The servlet gets the connection and execute the Unix command

ps -ef > /tmp/Test.txt

and then ftp over the file to c:\\Test.txt

 

APIs

The TxConnect API is described in TxConnect Connection.

The CCI API is described in CCI Connection

Support

For support or enhancement suggestions, please check the forum at:  FORUM

.

We value your comments and recommendations and  would like to build something of value for the java community.

 

Release Notes

Release 1.2

 

·        Simplify the packaging of the source code

·        Clarify some documentation in the user guide

·        Adapter classes renaming from SshDriver to SshAdapter

·        Add a servlet to test the current build.

·        Add an EJB example and JUnit test to test the EJB

 

 

First Release of TxConnect. It provides:

-         Support of SSH, SFTP Adapter

-         Support of Telnet Adapter

-         Support of Socket Adapter