BEA Logo BEA Tuxedo Release 7.1

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

 

   Tuxedo Doc Home   |   Jolt   |   Topic List   |   Previous   |   Next   |   Contents   |   Index

   Using BEA Jolt

Reusing Objects

The following listing, Extending Jolt Remote Service (extendSample.java), illustrates one way to subclass the JoltRemoteService class. In this case, a TransferService class is created by subclassing the JoltRemoteService class. The TransferService class extends the JoltRemoteService class, adding a Transfer feature that makes use of the BEA Tuxedo BANKAPP funds TRANSFER service.

The following listing uses the extends keyword from the Java language. The extends keyword is used in Java to subclass a base (parent) class. The following code shows one of many ways to extend from JoltRemoteService.

Extending Jolt Remote Service (extendSample.java)


/* Copyright 1999 BEA Systems, Inc. All Rights Reserved */

import java.net.*;
import java.io.*;
import bea.jolt.*;

/*
* This Jolt sample code fragment illustrates how to customize
* JoltRemoteService. It uses the Java language "extends" mechanism
*/
class TransferService extends JoltRemoteService
{
public String fromBal;
public String toBal;

    public TransferService( JoltSession session )
{
super("TRANSFER", session);
}

    public String doxfer( int fromAcctNum, int toAcctNum, String amount )
{
/* Clear any previous input parameters */
this.clear();

        /* Set the input parameters */
this.setIntItem("ACCOUNT_ID", 0, fromAcctNum);
this.setIntItem("ACCOUNT_ID", 1, toAcctNum);
this.setString("SAMOUNT", amount );

        try
{
/* Invoke the transfer service. */
this.call(null);

            /* Get the output parameters */
fromBal = this.getStringItemDef("SBALANCE", 0, null);
if (fromBal == null)
return "No balance from Account " +
fromAcctNum;
toBal = this.getStringItemDef("SBALANCE", 1, null);
if (toBal == null)
return "No balance from Account " + toAcctNum;
return null;
}
catch (ApplicationException e)
{
/* The transaction failed, return the reason */
return this.getStringDef("STATLIN", "Unknown reason");
}
}
}

class extendSample
{
public static void main( String args[] )
{
JoltSession s_session;
String host;
short port;
TransferService xfer;
String failure;

        if (args.length != 2)
{
System.err.println("Usage: reuseSample host port");
System.exit(1);
}

        /* Get the host name and port number for initialization. */
host = args[0];
port = (short)Integer.parseInt(args[1]);

        /* Prepare to connect to the Tuxedo domain.  */
JoltSessionAttributes attr = new JoltSessionAttributes();
attr.setString(attr.APPADDRESS,"//"+ host+":" + port);

        String username = null;
String userrole = "sw-developer";
String applpasswd = null;
String userpasswd = null;

        /* Check what authentication level has been set. */
switch (attr.checkAuthenticationLevel())
{
case JoltSessionAttributes.NOAUTH:
break;
case JoltSessionAttributes.APPASSWORD:
applpasswd = "secret8";
break;
case JoltSessionAttributes.USRPASSWORD:
username = "myName";
userpasswd = "BEA#1";
applpasswd = "secret8";
break;
}

        /* Logon now without any idle timeout (0). */
/* The network connection is retained until logoff. */
attr.setInt(attr.IDLETIMEOUT, 0);
s_session = new JoltSession(attr, username, userrole,
userpasswd, applpasswd);

        /*
* TransferService extends from JoltRemoteService and uses the
* standard BEA Tuxedo BankApp TRANSFER service. We invoke this
* service twice with different parameters. Note, we assume
* that "s_session" is initialized somewhere before.
*/

        xfer = new TransferService(s_session);
if ((failure = xfer.doxfer(10000, 10001, "500.00")) != null)
System.err.println("Tranasaction failed: " + failure);
else
{
System.out.println("Transaction is done.");
System.out.println("From Acct Balance: "+xfer.fromBal);
System.out.println(" To Acct Balance: "+xfer.toBal);
}

        if ((failure = xfer.doxfer(51334, 40343, "$123.25")) != null)
System.err.println("Tranasaction failed: " + failure);
else
{
System.out.println("Transaction is done.");
System.out.println("From Acct Balance: "+xfer.fromBal);
System.out.println(" To Acct Balance: "+xfer.toBal);
}

    } 
}