Examples

This chapter describes how to use WebTJCA in JEUS 6 and WebLogic.

1. Using WebTJCA in JEUS 6

1.1. Configuring a Resource Adapter

To use JCA, the user must first configure a resource adapter. In the resource adapter, the WAS vendor’s settings and the configuration defined in JCA must be specified. The resource adapter must be packaged in a Java Archive (JAR) with a .rar extension.

The following is a list of items that must be included in the resource adapter specified in JCA.

Contents of RAR file Requirements Relative location within RAR file

Deployment Descriptor

Required

META-INF/ra.xml

howto.html, image files, etc.

Optional

Arbitary (that is, could be at root level or sub-level)

JAR files

Optional

Arbitary

Platform-specific native libraries

Optional

Arbitary

The developer needs to configure the ra.xml and jeus-connector-dd.xml files.

For more information about the configuration and deployment of ra.xml and jeus-connector-dd.xml, refer to "JEUS JCA Guide".

Configuring ra.xml

Inflow and outbound are specified together. The following is an example of configuring ra.xml.

<?xml version="1.0" encoding="UTF-8"?>
<connector id="Connector_ID" version="1.5" xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd">
  <description>Tmax Sample Resource Adapter</description>
  <display-name>TmaxRA</display-name>
  <vendor-name>TmaxSoft</vendor-name>
  <eis-type>TP Monitor</eis-type>
  <resourceadapter-version>1.0.0.0</resourceadapter-version>
  <resourceadapter>
    <resourceadapter-class>com.tmax.connector.spi.TmaxResourceAdapterImpl</resourceadapter-class>
    <config-property>
        <config-property-name>port</config-property-name>
        <config-property-type>java.lang.Integer </config-property-type>
        <config-property-value>6556</config-property-value>
    </config-property>
    <config-property>
        <config-property-name>fdlfile</config-property-name>
        <config-property-type>java.lang.String</config-property-type>
        <config-property-value>C:\TmaxSoft\JEUS6.0\lib\application\tmax.fdl</config-property-value>
    </config-property>
    <outbound-resourceadapter>
      <connection-definition>
        <managedconnectionfactory-class>com.tmax.connector.spi.TmaxManagedConnectionFactoryImpl
        </managedconnectionfactory-class>
        <config-property>
            <config-property-name>host</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>192.168.1.43</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>host_port</config-property-name>
            <config-property-type>java.lang.Integer</config-property-type>
            <config-property-value>11120</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>backup</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>192.168.1.43</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>backup_port</config-property-name>
            <config-property-type>java.lang.Integer</config-property-type>
            <config-property-value>15300</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>support_xa</config-property-name>
            <config-property-type>java.lang.Boolean</config-property-type>
            <config-property-value>true</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>headerType</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>extendedV4</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>connectTimeout</config-property-name>
            <config-property-type>java.lang.Integer</config-property-type>
            <config-property-value>15000</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>fdlFile</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>C:\TmaxSoft\JEUS6.0\lib\application\tmax.fdl</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>xidMapperPath</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>C:\TmaxSoft\JEUS6.0\lib\application\</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>xidMapperFile</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>webtxidmapper</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>logLevel</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>DEBUG</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>logDir</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>d:\\</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>logFile</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>webt.log</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>logValidDays</config-property-name>
            <config-property-type>java.lang.Integer</config-property-type>
            <config-property-value>1</config-property-value>
        </config-property>
        <config-property>
            <config-property-name>connectionName</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>tmax1</config-property-value>
        </config-property>
        <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
        <connectionfactory-impl-class>com.tmax.connector.cci.TmaxConnectionFactoryImpl</connectionfactory-impl-class>
        <connection-interface>javax.resource.cci.Connection</connection-interface>
        <connection-impl-class>com.tmax.connector.cci.TmaxConnectionImpl</connection-impl-class>
      </connection-definition>

      <transaction-support>XATransaction</transaction-support>
      <reauthentication-support>false</reauthentication-support>
    </outbound-resourceadapter>
    <inbound-resourceadapter>
        <messageadapter>
            <messagelistener>
                <messagelistener-type>javax.resource.cci.MessageListener</messagelistener-type>
                <activationspec>
                    <activationspec-class>com.tmax.connector.spi.TmaxActivationSpec</activationspec-class>
                    <required-config-property>
                        <config-property-name>serviceName</config-property-name>
                    </required-config-property>
                </activationspec>
            </messagelistener>
        </messageadapter>
    </inbound-resourceadapter>
  </resourceadapter>
</connector>
Configuring jeus-connector-dd.xml

The following is an example of configuring jeus-connector-dd.xml. In the example, export-name is the name of the JNDI that can refer to the outbound connection.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jeus-connector-dd xmlns="http://www.tmaxsoft.com/xml/ns/jeus">
    <module-name>TmaxRA</module-name>
    <use-workmanager>true</use-workmanager>
    <connection-pool>
        <export-name>TmaxConnector</export-name>
        <transaction-support>XATransactionOnly</transaction-support>
        <pool-management>
            <min>5</min>
            <max>20</max>
        </pool-management>
    </connection-pool>
</jeus-connector-dd>
Deployment

The following is the process of deploying the configuration files.

  1. Configure the folder to which to deploy the files.

    webt5.9.7.0.jar
    META-INF/ra.xml
    META-INF/jeus-connector-dd.xml
  2. Generate the TmaxRA.rar file using the .jar file.

  3. Deploy the file to JEUS through JCA. In JEUS WebAdmin, use the [Deploy Application Module] menu.

1.2. Outbound Examples

The following is an example of jsp calling a TOUPPER service of Tmax.

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page import="javax.resource.cci.Connection"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.resource.cci.ConnectionFactory"%>
<%@page import="javax.resource.cci.RecordFactory"%>
<%@page import="javax.resource.cci.MappedRecord"%>
<%@page import="javax.resource.cci.Interaction"%>
<%@page import="javax.resource.cci.InteractionSpec"%>
<%@page import="com.tmax.connector.cci.TmaxInteractionSpecImpl"%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
    <title>Insert title here</title>
</head>
<body>
<%
 InitialContext ctx = new InitialContext();
 ConnectionFactory connFactory = (ConnectionFactory)ctx.lookup("TmaxConnector");
 Connection conn = connFactory.getConnection();

 Interaction action = conn.createInteraction();
 TmaxInteractionSpecImpl aspec = new TmaxInteractionSpecImpl();
 aspec.setSvcName("TOUPPER");
 aspec.setAction(InteractionSpec.SYNC_SEND_RECEIVE);

 RecordFactory recordFactory = connFactory.getRecordFactory();
 MappedRecord sndBuf = recordFactory.createMappedRecord(null);
 sndBuf.put("$String","abc");
 MappedRecord rcvBuf = recordFactory.createMappedRecord(null);

 if( action.execute(aspec, sndBuf, rcvBuf) )
 {
    String result = (String)rcvBuf.get("$String");
 }
 conn.close();
 System.out.println("end lookup");
%>
</body>
</html>

1.3. Inflow Examples

In JCA’s inflow architecture, when a service request is sent from Tmax, JCA invokes the registered message-driven bean. The user must implement and deploy this message-driven bean.

TmaxListenerBean.java

In the following example, when a service request is received, WebTJCA invokes OnMessage of the message-driven bean to call an EJB according to the name of the service.

package com.tmax.sample.echoMBean;

import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.resource.ResourceException;
import javax.resource.cci.MappedRecord;
import javax.resource.cci.MessageListener;
import javax.resource.cci.Record;
import javax.rmi.PortableRemoteObject;
import com.tmax.sample.TmaxBLSample;
import com.tmax.sample.TmaxBLSampleHome;

public class TmaxListenerBean implements MessageListener, MessageDrivenBean {
 /**
  *
  */
 private static final long serialVersionUID = 7971664840039920708L;
 public TmaxListenerBean() {
 }

 public void ejbCreate() throws EJBException {
 }

 public void ejbRemove() throws EJBException {
  // TODO Auto-generated method stub
 }

 public void setMessageDrivenContext(MessageDrivenContext ctx)
      throws EJBException {
  }

 public Record onMessage(Record in) throws ResourceException {
  System.out.println(in);
  String svcName = (String)((MappedRecord)in).get("$ServiceName");

  if( svcName.equalsIgnoreCase("echostring") )
  {
     return in;
  }
  else if( svcName.equalsIgnoreCase("create_account_b"))
  {
      System.out.println(((MappedRecord)in).get("$Message"));
      Context initial;
      try {
            System.setProperty("java.naming.factory.initial",
                       "jeus.jndi.JNSContextFactory");
            System.setProperty("java.naming.factory.url.pkgs", "jeus.jndi.jns.url");
            System.setProperty("java.naming.provider.url", "192.168.11.253");

            initial = new InitialContext();

             Object object = initial.lookup("TmaxBLSample");    // return EJB Home
             if( object == null )
             {
                return createFailRecord(in, -6);
             }

             TmaxBLSampleHome home = (TmaxBLSampleHome)
             PortableRemoteObject.narrow(object, TmaxBLSampleHome.class);
             TmaxBLSample sample =  home.create();
             if( sample.createAccount(in) )
             {
                MappedRecord out = (MappedRecord) in.clone();
                out.put("$ReturnCode", new Integer(0));
                out.put("RESULT", "OK");
                return out;
             }
             else
             {
                return createFailRecord(in, -1);
             }
      } catch (NamingException e) {
           e.printStackTrace();
           return createFailRecord(in, -2);
      } catch (RemoteException e) {
           e.printStackTrace();
           return createFailRecord(in, -3);
      } catch (CreateException e) {
           e.printStackTrace();
           return createFailRecord(in, -4);
      } catch (CloneNotSupportedException e) {
           e.printStackTrace();
           return createFailRecord(in, -5);
      }
  }
  else if( svcName.equalsIgnoreCase("transfer_money_b"))
  {
      System.out.println(((MappedRecord)in).get("$Message"));

      Context initial;
      try {
            System.setProperty("java.naming.factory.initial",
                       "jeus.jndi.JNSContextFactory");
            System.setProperty("java.naming.factory.url.pkgs", "jeus.jndi.jns.url");
            System.setProperty("java.naming.provider.url", "192.168.11.253");

            initial = new InitialContext();

             Object object = initial.lookup("TmaxBLSample");    // return EJB Home
             if( object == null )
             {
                 return createFailRecord(in, -6);
             }

             TmaxBLSampleHome home = (TmaxBLSampleHome)
             PortableRemoteObject.narrow(object, TmaxBLSampleHome.class);
             TmaxBLSample sample =  home.create();
             if( sample.transferMoney(in) )
             {
                 MappedRecord out = (MappedRecord) in.clone();
                 out.put("$ReturnCode", new Integer(0));
                 out.put("RESULT", "OK");
                 return out;
             }
             else
             {
                return createFailRecord(in, -1);
             }
      } catch (NamingException e) {
          e.printStackTrace();
          return createFailRecord(in, -2);
      } catch (RemoteException e) {
          e.printStackTrace();
          return createFailRecord(in, -3);
      } catch (CreateException e) {
          e.printStackTrace();
          return createFailRecord(in, -4);
      } catch (CloneNotSupportedException e) {
          e.printStackTrace();
          return createFailRecord(in, -5);
      }
  }
  return in;
 }

 public Record createFailRecord(Record src, int usrcode)
 {
     MappedRecord out = null;
     try {
           out = (MappedRecord) src.clone();
       }
       catch (CloneNotSupportedException e) {
           e.printStackTrace();
           return null;
        }
     out.put("$ReturnCode", new Integer(-1));
     out.put("$UserCode", new Integer(usrcode));
     out.put("RESULT", "FAIL");
     return out;
 }
}
ejb-jar.xml

ejb.jar.xml is a deployment descriptor for EJB 2.0, which contains the following options.

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
 <display-name>TmaxListenerBean</display-name>
 <enterprise-beans>
  <message-driven>
   <display-name>TmaxListenerBean</display-name>
   <ejb-name>TmaxListenerBean</ejb-name>
   <ejb-class>com.tmax.sample.echoMBean.TmaxListenerBean</ejb-class>
   <transaction-type>Container</transaction-type>
   <message-destination-link>TmaxRA</message-destination-link>
   <activation-config>
    <activation-config-property>
     <activation-config-property-name>serviceName</activation-config-property-name>
     <activation-config-property-value>
     ECHOSTRING,CREATE_ACCOUNT_B,TRANSFER_MONEY_B
     </activation-config-property-value>
    </activation-config-property>
   </activation-config>
  </message-driven>
 </enterprise-beans>
</ejb-jar>
jeus-ejb-dd.xml

jeus-ejb-dd.xml is a deployment descriptor for the EJB 2.0 file of JEUS.

<?xml version="1.0"?>
<jeus-ejb-dd xmlns="http://www.tmaxsoft.com/xml/ns/jeus">
 <beanlist>
  <jeus-bean>
   <ejb-name>TmaxListenerBean</ejb-name>
   <mdb-resource-adapter-name>TmaxRA</mdb-resource-adapter-name>
  </jeus-bean>
 </beanlist>
</jeus-ejb-dd>

For more information about jeus-ejb-dd.xml, refer to "5.3.1.4. Creating jeus-ejb-dd.xml DD" in "JEUS EJB Guide".

2. Using WebTJCA in WebLogic

This section describes how to use WebTJCA in WebLogic.

2.1. Configuring a Resource Adapter

To use JCA, the user must first configure a resource adapter. In the resource adapter, the settings specific to the WAS vendor and the configuration defined in JCA must be specified. The resource adapter must be packaged in a Java Archive (JAR) with the .rar extension.

The following is a list of items that must be included in the resource adapter specified in JCA.

Contents of RAR file Requirements Relative location within RAR file

Deployment Descriptor

Required

META-INF/ra.xml

howto.html, image files, etc.

Optional

Arbitary (that is, could be at root level or sub-level)

JAR files

Optional

Arbitary

Platform-specific native libraries

Optional

Arbitary

Developers need to configure the ra.xml and weblogic-ra.xml files as follows.

Configuring ra.xml

Inflow and outbound are specified together. For more information about configuring ra.xml, see Configuring WebTJCA ra.xml. For configuration examples, see Configuring a Resource Adapter.

Configuring weblogic-ra.xml

The following is an example of configuring weblogic-ra.xml. In the example, jndi-name is the name of the JNDI that can refer to the outbound connection.

<?xml version="1.0" ?>
<weblogic-connector xmlns="http://www.bea.com/ns/weblogic/90">
 <jndi-name>TmaxRA</jndi-name>
    <enable-access-outside-app>true</enable-access-outside-app>
    <outbound-resource-adapter>
     <connection-definition-group>
      <connection-factory-interface>javax.resource.cci.ConnectionFactory
      </connection-factory-interface>
   <connection-instance>
    <jndi-name>TmaxConnector</jndi-name>
    <connection-properties>
     <pool-params>
      <initial-capacity>2</initial-capacity>
      <max-capacity>10</max-capacity>
      <capacity-increment>1</capacity-increment>
      <shrinking-enabled>true</shrinking-enabled>
      <shrink-frequency-seconds>60</shrink-frequency-seconds>
     </pool-params>
    </connection-properties>
   </connection-instance>
     </connection-definition-group>
    </outbound-resource-adapter>
</weblogic-connector>
Deployment

The following is the process of deploying the configuration files.

  1. Configure the folder to which to deploy the files.

    webt5.9.7.0.jar
    META-INF/ra.xml
    META-INF/weblogic-ra.xml
  2. Generate the TmaxRA.rar file using the .jar file.

  3. Deploy the file to WebLogic through JCA. In the WebLogic administrator tool, use the [Deploy Application] menu.

For more information about the configuration of weblogic-ra.xml, refer to "Programming WebLogic Resource Adapters" in the BEA WebLogic Server Guide. For more information about the deployment, refer to "Deploying Applications to WebLogic Server".

2.2. Outbound Communication Examples

The following is an example of jsp calling a TOUPPER service of Tmax. For the outbound examples, see Outbound Examples.

2.3. Inflow Examples

In JCA’s inflow architecture, when a service request is sent from Tmax, JCA invokes the registered message-driven bean. The user must implement and deploy this message-driven bean.

TmaxListenerBean.java

When a service request is received, WebTJCA invokes OnMessage of the message-driven bean to call an EJB according to the name of the service. See the example of TmaxListenerBean.java in Inflow Examples.

ejb-jar.xml

ejb-jar.xml, a deployment descriptor for EJB 2.0. It includes the following option information.

The file includes <enterprise-beans>, which specifies the structures of all EJBs, and <assembly-descriptor>, which specifies the option information for application deployment. The file also configures transaction processing method and the security policy for the beans. The following example is the configuration for deploying TmaxListenerBean configured with MDB.

<ejb-jar id="ejb-jar_ID" version="2.1"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
  <display-name>TmaxListenerBean</display-name>
  <enterprise-beans>
    <message-driven>
      <display-name>TmaxListenerBean</display-name>
      <ejb-name>TmaxListenerBean</ejb-name>
      <ejb-class>com.tmax.sample.echoMBean.TmaxListenerBean</ejb-class>
      <messaging-type>javax.resource.cci.MessageListener</messaging-type>
      <transaction-type>Container</transaction-type>
      <message-destination-link>TmaxRA</message-destination-link>
      <activation-config>
        <activation-config-property>
          <activation-config-property-name>serviceName
          </activation-config-property-name>
          <activation-config-property-value>
             ECHOSTRING,CREATE_ACCOUNT_B,TRANSFER_MONEY_B
          </activation-config-property-value>
        </activation-config-property>
      </activation-config>
    </message-driven>
   </enterprise-beans>
   <assembly-descriptor>
     <message-destination>
       <message-destination-name>TmaxRA</message-destination-name>
     </message-destination>
    </assembly-descriptor>
</ejb-jar>

Unlike JEUS, WebLogic must be specified as follows. The message link and assembly descriptor must not be set for WebLogic.

<!-- message--link>TmaxRA</message-destination-link -->
<!-- assembly-descriptor>
   <message-destination>
      <message-destination-name>TmaxRA</message-destination-name>
   </message-destination>
</assembly-descriptor -->
weblogic-ejb-jar.xml

This file defines WebLogic-dependent properties, which may include caching, clustering, and optimization configurations.

<?xml version="1.0" ?>
<weblogic-connector xmlns="http://www.bea.com/ns/weblogic/90">
  <jndi-name>TmaxRA</jndi-name>
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-ejb-jar
 xmlns="http://www.bea.com/ns/weblogic/90"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.bea.com/ns/weblogic/90
 http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd">
  <weblogic-enterprise-bean>
    <ejb-name>TmaxListenerBean</ejb-name>
    <message-driven-descriptor>
     <resource-adapter-jndi-name>TmaxRA</resource-adapter-jndi-name>
    </message-driven-descriptor>
  </weblogic-enterprise-bean>
</weblogic-ejb-jar>