Previous     Contents     Index     DocHome     Next     
iPlanet Application Server Enterprise Connector for CICS Developer's Guide



Chapter 3   Programming Examples


This chapter describes the procedure for acquiring UIF objects and executing function objects.

The iPlanet Application Server Enterprise Connector for CICS executes CICS transactions on a remote CICS server. The servlet uses the CICS connector to access the CICS server.

This chapter contains the following section:



Data Objects

Data objects represent data in a hierarchal fashion; circular references are not allowed. UIF prevents a data object being used as an attribute of itself. Indirect circular references are not checked by UIF.


Caution

No error message is generated if an indirect circular reference is defined. Unpredictable results occur if a circular reference is used at runtime.



The data objects contain actual data and metadata.

UIF is used to access date through the data object interface. The data object interface:

  • presents a unified representation of backend data types

  • represents complex data

  • supports most common primitive data types.

Data objects are built from primitive types. A primitive data object contains a primitive value; e.g., integer, string. Arrays and structures are complex data objects.

The types of data objects are


Primitive Objects

A primitive data-type object contains a single value of one of the following types



Figure 3-1    Primitive Object


integer, float, double

Integer, float, and double-data type objects hold a value whose type corresponds to the java-data type.

When a primitive data object is assigned to a list, array, or structure, the data object is unwrapped and its value is copied into the list, array or structure. The data object itself is not used. When a primitive value is obtained by using an untyped get-method, such as getField(), getElem(), getAttr(), or getCurrent(), the returned value is wrapped in a primitive data object. In this case, the value is copied, thus, modifying the returned primitive data object does not change the source object.


fixed-length string, variable-length string

Strings correspond to the java-string data type A fixed-length string has a maximum length, whereas a variable-length string has no restrictions on its length.


fixed-size byte array, variable-size byte array

A fixed-size byte array has a maximum size, whereas a variable-size byte array has no restriction on its size.

When a new value replaces an old value, the old value is released. Thus, when a new value is assigned to a variable-length string or a variable-size byte array, the old value is released. When a new value is assigned to a fixed-length string or a fixed-size byte array, the new value is copied over the old one. In the case of a fixed-length string, the copied string is truncated to fit if necessary. In the case of a fixed-size byte array, a shorted array is zero filled on the right and a longer array is truncated to fit.

The maximum length of a fixed-length string and the maximum size of a fixed-size byte array are set when the string's initial value is specified; i.e. four characters in the following example;

list.addElemFString("abcd")

If a five character value is used, the value is truncated to four characters by dropping the fifth character.


Structure Objects

Structure objects contain other data objects or primitive values as fields. Each object within the structure object is referred to by a string that represents the field name. Field names have a maximum length of 32 characters. A structure's fields are heterogeneous.



Figure 3-2    Structure Object


Array Objects

An array object contains data objects or primitive values as elements in the object. array objects inherit from list objects. The difference between an array object and a list object is that the array's elements must be homogeneous. Each element within the array object is referred to by an integer that specifies its position in the array object.



Figure 3-3    Array Object


Type Information Objects

Type information objects are structured objects that contain the type information of a data object; i.e. a type information object might define the fields in a structure and their corresponding data types. Instances of data objects can be created of type information objects. Each of these instances contain a reference to a type of information object. Numerous data types can share the same type information object.

Table 3-1 Type Information Objects

DataObjectInfo Type

Target Object

IBSPDataObjectPrimitiveInfo describes the type number, size of value (if type is string or binary), and the default value.  

IBSPDataObjectPrimitive  

IBSPDataObjectStructureInfo describes the type info of all fields of the target structure. The type info of each field is in tern described by a type info object.  

IBSPDataObjectStructure  

IBSPDataObjectListInfo describes the initial capacity and maximal element count of the target list.  

IBSPDataObjectList  

IBSPDataObjectArrayInfo describes the initial capacity, maximal element count and the type info of elements of the target array.  

IBSPDataObjectArray  



API Naming Conventions



Methods in the API conform to a naming convention that specifies

  • operation

  • target

  • type

In the following example of the form <operation><target><type>:

getElemString()

get is the operation, Elem is the target, and String is the type.


Operation

There are many types of operations but the two most commonly used are


Target

The targets are

  • None (primitive)

  • Attr (complex DataObject such as a list, array, or structure) that uses path to address attribute.

  • Elem (list/array) uses index to address element

  • Field (structure) that uses name to address field

  • Current (itr) addresses object iterator is currently on


Type

The types of operations are

  • Int

  • Float

  • Double

  • String

  • FString

  • Binary

  • VBinary

  • DataObject

  • None


Attributes and Paths

In the API, methods of the IBSPDataObject interface do not distinguish between an element in an array and a field in a structure. In this case the element or field is referred to as an attribute.

The path to an element is its element number, beginning from zero. The path to a field is its field name.You may combine element numbers and field names to create paths to attributes in complex data objects, such as a field of a structure that contains a list of elements. In this case, you specify the path as the individual attributes separated by periods (.); i.e. use "field1.[01]" to identify the first element of a list at field1 in the structure.


Changing Data Types

If an attribute's type is primitive, it can not change. For example, the following code will cause an error because it tries to change the type of a primitive from an integer to a float:

list.addElemInt (100) ; // assume 100 is added to element 1

list.setElemFloat (1, 3.14) ; // fails because the type of element is int

You can change the data type of non-primitive, as in the following example:

list.addElemDataObject (aStruct) ; // add a structure is to element 1

list.setElemDataObject (1, array) ; // change to array succeeds



Working with Servlet Samples



To execute a CICS transaction from a servlet

  1. Acquiring the UIF Runtime Object

  2. Creating the Service Provider Object

  3. Creating the Function Object

  4. Setting Up and Executing the Function Object


Acquiring the UIF Runtime Object

The runtime object is the entry point into UIF. It is both the object factory and the access point for creating other objects.

The following is an example of acquiring a runtime object. Code Example 3-1 Acquiring the UIF Runtime Object

private IBSPRuntime getRuntime()

{

   com.kivasoft.IContext _ctx =

   ((com.netscape.server.servlet.platformhttp.PlatformServletContext)

      getServletContext()).getContext();

   IBSPRuntime ibspruntime = access_cBSPRuntime.getcBSPRuntime
         (_ctx, null, null);

   return ibspruntime;   }

}



Creating the Service Provider Object

The service provider is the logical representation of a connection to a backend system. Typically, the service provider is not bound to a physical connection until it is absolutely necessary. A service provider must be enabled before it can be used.


Detailed Description of Service Provider

A service provider type represents a connection to a backend CICS system. It contains configuration information such as the kinds of data required to create a connection, e.g., host, port, user name, and password.

A service provider type may also specify additional information required to manage a connection.

The following diagram shows the parts of a service-provider type.

Figure 3-4    Service Provider Types

The following is an example of how to create a service provider object.

Code Example 3-2 Creating the Service Provider Object


private IBSPServiceProvider getServiceProvider(IBSPRuntime runtime)

{

   deb.println("Before createServiceProvider()");

   if (runtime != null)

      return runtime.createServiceProvider("CICS", "CICS_sp1");

   else

      deb.println("runtime is null");

   return null;

}


Parameter

Definition

CICS

Data source name

CICS_sp1

Service provider name


Creating the Function Object

A function object is a group of related operations that share a common state. In UIF, a function object is set up and associated with a service provider before the function object is executed.


Detailed Description of Function Object

A function-object contains operations. The operations contain data-block definition and a property set whose values define access to the target CICS transaction. The data objects contain actual data values which are in the format specified in a data type. The data object element under a function object template is a data object of a specified data type. It represents the parameter block for the operation and holds the input/output information during the execution of the operation.

The following diagram shows the parts of a function-object type.

Figure 3-5    Function-Object Type

The following is an example of how to create a function object. Code Example 3-3 Creating the Function Object

IBSPFunctionObject fn = null;

...

if(   runtime != null )

{

   deb.println("Before getServiceProvider()");

   sp = getServiceProvider(runtime);

   deb.println("After getServiceProvider()");

   if( sp != null )

   {

      deb.println("Before createFunctionObject()");

      fn = runtime.createFunctionObject("CICS", "phonebook");

   }

}


Parameter

Definition

CICS

Data source name

phonebook

Function name


Setting Up and Executing the Function Object

  1. Specify and enable the service provider.

  2. Prepare the function object, set up the property set, and set up the input parameters in the function object's data block.

  3. Execute the function object.

  4. Retrieve the output parameters from the function block.

  5. Disable the service provider.

The following is an example of setting up and executing a function object. Code Example 3-4 Setting Up and Executing the Function Object

   private dataRecord executePB(IBSPRuntime runtime, IBSPServiceProvider sp,

            String requestCode, dataRecord input) throws BspException

   {

      int hr = 1;

      IBSPFunctionObject fn = null;

      IBSPDataObject data = null, prop = null;

      String lastname = new String("");

      String firstname = new String("");

      String extension = new String("");

      String zipcode = new String("");

      dataRecord o_entry = null;

      if( (runtime != null) && (sp != null) )

      {

         fn = runtime.createFunctionObject("CICS", "phonebook");

         hr = sp.enable();

         if( fn != null )

         {

            hr = fn.useServiceProvider(sp);

            hr = fn.prepare(requestCode);

            data = fn.getDataBlock();

            if( data != null )

            {

               data.setAttrFString("INPUT.REQC", requestCode);

               data.setAttrFString("INPUT.LNAME",input.m_lastName);

               data.setAttrFString("INPUT.FNAME",input.m_firstName);

               data.setAttrFString("INPUT.EXTENTION",input.m_extension);

               data.setAttrFString("INPUT.ZIPC",input.m_zipcode);

               prop = fn.getProperties();

               if( prop != null )

               {

                  prop.setAttrInt("CONNECTION.StubReason",0 );

               }

               hr = fn.execute();

               if( hr == 0 )

               {

                  data = fn.getDataBlock();

                  if( data != null )

                  {

                     deb.println("MSG: "+data.getAttrFString("OUTPUT.MSG"));

                     deb.println("REQC: "+data.getAttrFString("OUTPUT.REQC"));

                     lastname = data.getAttrFString("OUTPUT.LNAME");

                     deb.println("LNAME: "+lastname);

                     firstname = data.getAttrFString("OUTPUT.FNAME");

                     deb.println("FNAME: "+firstname);

                     extension = data.getAttrFString("OUTPUT.EXTENTION");

                     deb.println("EXTENTION: "+extension);

                     zipcode = data.getAttrFString("OUTPUT.ZIPC");

                     deb.println("ZIPC: "+zipcode);

                     o_entry = new dataRecord(lastname, firstname, extension, zipcode);

                     o_entry.m_message = new String(data.getAttrFString("OUTPUT.MSG"));

                  }

                  prop = fn.getProperties();

                  if(prop != null)

                  {

                     deb.println("APPLID: "+prop.getAttrFString("CONNECTION.Applid"));

                     deb.println("LU: "+prop.getAttrFString("CONNECTION.LU"));

...

                     

                  }

               } // if(hr == 0)

               else

                  deb.println("Search Failed");

            } // if(data != null)

            else

               deb.println("Search Failed");

         } // if( fn != null )

         else

            deb.println("Search Failed");

         hr = sp.disable();

      } // if( (runtime != null) && (sp != null) )

      else

         deb.println("Search Failed");

      return o_entry;

   }




Samples



This section describes the three samples that are included: two Phonebook and one Telco.


Activating the Samples

  1. Open the browser.

  2. Type in: http://localhost/cicsSamples/index.html


Telco Sample and Programming Concepts

This sample is based on CICS and DB2 for OS/390.

The Telco sample application consists of seven (7) CICS programs that access DB2 tables.

The CICS install library contains three members:

  • CRETAB

  • BIND

  • CICSDEF2


Installing the Sample

  1. Create the sample DB2 database using the member CRETAB. It contains a JCL that creates the sample database.


    Note Please read the content of the file, and customize it to your environment if needed.



Code Example 3-5 IAS4CICS.V6R0M0.CICS.INST(CRETAB)


//CRETAB JOB MSGCLASS=K
//************************************************************** ********
//* NAME = cretab *
//* *
//* DESCRIPTIVE NAME = create the DB2 Database for NAS for CICS *
//* SAMPLE APPLICATIONS *
//* *
//* VERIFY THAT THE DB2 LIBRARIES IN THE JOBLIB HAS A CORRECT NAME *
//* AND THAT THE DB2 LOAD LIBRARY IN THE RUN PROGRAM COMMAND IS *
//* CORRECT *
//* *
//************************************************************** ********
//JOBLIB DD DSN=DSN510.SDSNEXIT,DISP=SHR <=CHANGE
// DD DSN=DSN510.SDSNLOAD,DISP=SHR <=CHANGE
//CREATE EXEC PGM=IKJEFT01,DYNAMNBR=20
//SYSUDUMP DD SYSOUT=*
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
drop database dbnas;
drop stogroup sgnas1;
commit;
create database dbnas;

create stogroup sgnas1 VOLUMES(sunl01) vcat dbnas;
create tablespace ts0001 in dbnas segsize 4 using stogroup sgnas1
priqty 256
secqty 16;

create table nas.tcustomers
(
tel_Number char(13) not null with default,
first_Name char(15) not null with default,
last_Name char(15) not null with default,
billing_Address char(100) not null with default,
billing_City char(20) not null with default,
billing_State char(20) not null with default,
billing_Country char(20) not null with default,
billing_Zip_Code char(10) not null with default,
payment_Method smallint not null with default,
card_Number char(16) not null with default,
card_Holder_Name char(30) not null with default,
expiration_Date date not null with default,
card_Zip_Code char(10) not null with default
)
in dbnas.ts0001;


create unique index nas.icustomers1 on nas.tcustomers
(
tel_Number asc
)
cluster
using stogroup sgnas1;

insert into nas.tcustomers
values ('97299711234','Karen','Bold','10 Hasadnaot st.',
'Herzliya','','ISRAEL','46733',1,'5326100364236634',
'Karen Bold','01.01.2001',
'46733');

insert into nas.tcustomers
values ('97299711230','Dan','Smith','10 Hasadnaot st.',
'Herzliya','','ISRAEL','46733',2,' ',
' ','01.01.0001',
' ');




create table nas.tservices
(
service_Code smallint not null with default,
service_Name char(40) not null with default,
base_price decimal(7,2) not null with default,
price_per_call decimal(7,2) not null with default
)
in dbnas.ts0001;


create unique index nas.iservices1 on nas.tservices
(
service_Code asc
)
cluster
using stogroup sgnas1;

insert into nas.tservices
values (0,'Local call',20.00,0.05);

insert into nas.tservices
values (1,'Call Waiting',10.50,0.00);

insert into nas.tservices
values (2,'Caller ID',11.50,0.00);

insert into nas.tservices
values (3,'Follow me',03.50,1.50);

insert into nas.tservices
values (4,'Voice Dailing',05.50,0.75);


create table nas.tcCust_Services
(
Tel_Number char(13) not null with default,
service_Code smallint not null with default
)
in dbnas.ts0001;

create unique index nas.itcCusServ1 on nas.tcCust_Services
(
Tel_Number asc,
service_Code asc
)
cluster
using stogroup sgnas1;

insert into nas.tcCust_Services
values ('97299711234',1) ;

insert into nas.tcCust_Services
values ('97299711234',2) ;

insert into nas.tcCust_Services
values ('97299711234',3) ;

insert into nas.tcCust_Services
values ('97299711234',4) ;

insert into nas.tcCust_Services
values ('97299711230',2) ;

insert into nas.tcCust_Services
values ('97299711230',3) ;




create table nas.tCust_Charges
(
Tel_Number char(13) not null with default,
start_timestamp timestamp not null with default,
end_timestamp timestamp not null with default,
parter_Tel_Number char(13) not null with default,
service_Code smallint not null with default,
amount_charged decimal(7,2)
)
in dbnas.ts0001;

create index nas.itCustCharge1 on nas.tCust_Charges
(
Tel_Number asc
)
cluster
using stogroup sgnas1;

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-01-22.19.53.121334',
'1999-11-01-23.11.33.324544',
'97295551250',
0,
10
);

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-02-12.19.53.121334',
'1999-11-02-12.21.33.324544',
'97299711230',
0,
3.5
);

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-02-14.19.53.121334',
'1999-11-02-14.41.23.125464',
'97295551353',
0,
7.7
);

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-03-09.19.23.653234',
'1999-11-03-10.11.13.234324',
'16505556552',
0,
44.64
);

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-04-17.19.53.744352',
'1999-11-04-19.31.23.345344',
'97299711230',
0,
12.65
);

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-05-23.19.53.121334',
'1999-11-06-02.11.13.321234',
'97299711230',
0,
1.6
);

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-06-12.23.53.231124',
'1999-11-06-13.42.23.653244',
'97295552135',
0,
10
);

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-07-11.19.53.121334',
'1999-11-07-11.21.33.324544',
'97299711251',
0,
1.2
);

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-07-12.19.13.642334',
'1999-11-07-12.23.23.364225',
'97299711230',
0,
0.5
);

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-08-09.09.27.121334',
'1999-11-08-09.24.25.324544',
'97295553352',
0,
2.67
);

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-08-18.34.43.765224',
'1999-11-08-19.56.12.453544',
'97235551112',
0,
3.65
);


insert into nas.tCust_Charges
values ('97299711234',
'1999-11-08-18.34.43.765224',
'1999-11-08-19.56.12.453544',
'97235551112',
3,
1.50
);

insert into nas.tCust_Charges
values ('97299711234',
'1999-11-07-12.19.13.642334',
'1999-11-07-12.23.23.364225',
'97299711230',
4,
0.75
);


insert into nas.tCust_Charges
values ('97299711234',
'1999-11-03-09.19.23.653234',
'1999-11-03-10.11.13.234324',
'16505556552',
4,
0.75
);


//SYSTSIN DD *
DSN SYSTEM(DSN1)
RUN PROGRAM(DSNTIAD) PLAN(DSNTIA51) -
LIB('DSN510.RUNLIB.LOAD')
END
//


  1. Bind the CICS DB2 programs into packages and plan using the member BIND which creates the packages and plan.


    Note Please read the instruction in the JOB comment, and make any necessary customizations to your site.



Code Example 3-6 IAS4CICS.V6R0M0.CICS.INST(BIND)


//BIND JOB MSGCLASS=K
//************************************************************** ********
//* NAME = BIND *
//* *
//* DESCRIPTIVE NAME = BIND THE PACKAGES AND PLAN FOR THE NAS FOR CICS*
//* SAMPLE APPLICATIONS *
//* *
//* VERIFY THAT THE DB2 LIBRARIES IN THE JOBLIB HAS A CORRECT NAME, *
//* THAT THE DBRM LIB HAS THE NAME YOU CHOSE IN THE INSTALLATION *
//* AND THAT THE DB2 LOAD LIBRARY IN THE RUN PROGRAM COMMAND IS *
//* CORRECT *
//* *
//************************************************************** ********
//JOBLIB DD DSN=DSN510.SDSNEXIT,DISP=SHR <=CHANGE
// DD DSN=DSN510.SDSNLOAD,DISP=SHR <=CHANGE
//BIND EXEC PGM=IKJEFT01,DYNAMNBR=20
//DBRMLIB DD DSN=NAS.TESTPROG.DBRM,DISP=SHR <=CHANGE
//SYSUDUMP DD SYSOUT=*
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
GRANT BIND, EXECUTE ON PLAN NASSAMP TO PUBLIC;
//SYSTSIN DD *
DSN SYSTEM(DSN1)
BIND PACKAGE (NASCOL1) MEMBER(GCBILD ) ACT(REP) ISO(CS)
BIND PACKAGE (NASCOL1) MEMBER(GCSVC ) ACT(REP) ISO(CS)
BIND PACKAGE (NASCOL1) MEMBER(GETCDET ) ACT(REP) ISO(CS)
BIND PACKAGE (NASCOL1) MEMBER(GETSVLST ) ACT(REP) ISO(CS)
BIND PACKAGE (NASCOL1) MEMBER(UCSVC ) ACT(REP) ISO(CS)
BIND PACKAGE (NASCOL1) MEMBER(UPDCDET ) ACT(REP) ISO(CS)
BIND PACKAGE (NASCOL1) MEMBER(UPDPAYM ) ACT(REP) ISO(CS)
BIND PLAN(NASSAMP) PKLIST(NASCOL1.*) ACT(REP) ISO(CS)
RUN PROGRAM(DSNTIAD) PLAN(DSNTIA51) -
LIB('DSN510.RUNLIB.LOAD')
END
//



  1. Create resource definitions for the sample applications in CICS by running the CICSDEF2 member. The CICSDEF2 creates definitions for the Cobol programs and defines the db2entry for the transaction. Code Example 3-7 NAS4CICS.V4R1M0.SAMPLEJCL(CICSDEF2)


    //CICSDEF JOB CLASS=A,MSGCLASS=K
    //*
    //* SAMPLE JOB TO DEFINE THE NAS COMPONENTS TO CICS
    //* CHECK THE DSN= PARAMETERS FOR THE STEPLIB AND DFHCSD DD CARDS
    //* CHANGE 'CICSLIST' TO THE CICS STARTUP LIST NAME
    //* SEE NOTES FOR EACH SECTION BELOW (FILES, PROGRAMS, ETC.)
    //*
    //CSDUP EXEC PGM=DFHCSDUP
    //STEPLIB DD DSN=CICS.CICS.SDFHAUTH,DISP=SHR
    //DFHCSD DD DSN=CICS.DFHCSD,DISP=SHR
    //SYSPRINT DD SYSOUT=*
    //SYSIN DD *
    ***
    *** DEFINITIONS FOR PROGRAMS
    ***
    DEFINE PROGRAM(GCBILD ) GROUP(NAS) LANGUAGE(COBOL)
    DEFINE PROGRAM(GCSVC ) GROUP(NAS) LANGUAGE(COBOL)
    DEFINE PROGRAM(GETCDET ) GROUP(NAS) LANGUAGE(COBOL)
    DEFINE PROGRAM(GETSVLST ) GROUP(NAS) LANGUAGE(COBOL)
    DEFINE PROGRAM(UCSVC ) GROUP(NAS) LANGUAGE(COBOL)
    DEFINE PROGRAM(UPDCDET ) GROUP(NAS) LANGUAGE(COBOL)
    DEFINE PROGRAM(UPDPAYM ) GROUP(NAS) LANGUAGE(COBOL)
    ***
    *** DEFINITIONS FOR PROGRAMS
    ***
    DEFINE DB2ENTRY(SRVX) TRANSID(SRVX) PLAN(NASSAMP) GROUP(NAS)
    /*
    //




Telco Customer Service Example

The following Telco Customer Services window shows an example of using the model in a telephone service.


Logging In

  1. Type your telephone number and PIN number in the Login Menu dialog box

    .

  2. Click the Next button to display the Telco Customer Service Main Menu.

  3. Access Customer information from the main menu.


Accessing the Customer Details Dialog Box

Click on the Update Customer detail button.

The Customer Details dialog box, shown below, is used to update the name, address, and telephone number of the customer. Payment method, credit card number, and credit card expiration date are not displayed and cannot be changed.







Updating Customer Details

  1. Type the change in the appropriate text box. In the dialog box, below, a new billing address has been typed into the Billing Address text box: 22 Herzl St

    .

  2. Click the Update button to save the data.

  3. Click the Return button to redisplay the main menu.

  4. Press the Back button to return to the main menu.


Displaying the Customer Services

From the main menu press the Customer Services button.The following dialog box appears.


Displaying the Customer's Billing for Any Month

  1. Type the telephone number and billing month in the appropriate text boxes.

  2. Press the Get Billings button to display the billings, as shown below.

  3. Press the Get Billings button to see the billings, as shown below.


Code Samples

Code Example 3-8 TelcoServlet.java



/*

* @(#)TelcoServlet.java   1/11/99

*

* Copyright (c) 1996-1997 Sun Microsystems, Inc. All Rights Reserved.

*

* This software is the confidential and proprietary information of Sun

* Microsystems, Inc. ("Confidential Information"). You shall not

* disclose such Confidential Information and shall use it only in

* accordance with the terms of the license agreement you entered into

* with Sun.

*

* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE

* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE

* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR

* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES

* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING

* THIS SOFTWARE OR ITS DERIVATIVES.

*

* CopyrightVersion 1.0

*/

package TelcoSample;

import java.io.*;

import com.kivasoft.IContext;

import javax.servlet.*;

import javax.servlet.http.*;

import java.util.*;

import javax.naming.*;

import javax.naming.spi.*;

import netscape.bsp.*;

import netscape.bsp.runtime.*;

import netscape.bsp.dataobject.*;

import netscape.bsp.BspException.*;

//    <form action="/NASApp/application name/PhoneBookServlet" method=get>

/**

* This is a simple example of an HTTP Servlet. It responds to the GET

* and HEAD methods of the HTTP protocol.

*/

public class TelcoServlet extends HttpServlet

{

   private TestDebug deb = new TestDebug("TelcoSample.log");

   private Context _context;

   protected String getInputString(HttpServletRequest   request, String parameterName)

   {

      // This method is useful since getValString returns null on

      // some platforms and an empty string on other platforms for

      // missing input parameters.   It also removes any whitespace

      // characters that the user my have inadvertantly entered.

      String parameter = request.getParameter(parameterName);

      if (parameter != null)

      {

         parameter = parameter.trim();

      }

      return parameter;

   }

   Context getContext()

      throws Exception, BspException

   {

      Hashtable env = new Hashtable(11);

      env.put(Context.INITIAL_CONTEXT_FACTORY, "com.kivasoft.eb.jndi.GDSInitContextFactory");

      if (_context == null)

      {

         _context = new InitialContext(env );

      }

      return _context;

   }

   private IBSPRuntime getRuntime() throws BspException

   {

      com.kivasoft.IContext _ctx =

         ((com.netscape.server.servlet.platformhttp.PlatformServletContext)

         getServletContext()).getContext();

      deb.println(" before access_cBSPRuntime.getcBSPRuntime ");

      IBSPRuntime ibspruntime = access_cBSPRuntime.getcBSPRuntime(_ctx, null, null);

      deb.println(" after access_cBSPRuntime.getcBSPRuntime ");

      return ibspruntime;

   }

   

   private IBSPServiceProvider getServiceProvider(IBSPRuntime runtime) throws BspException

   {

      deb.println("Before createServiceProvider()");

      IBSPServiceProvider ibspserviceProvider = null;

      IBSPDataObject ppConfig;

      if (runtime != null)

      {

         ibspserviceProvider = runtime.createServiceProvider("CICS", "CICS_sp1");

      deb.println("after createServiceProvider");

         ppConfig = ibspserviceProvider.getConfig();

      deb.println("after getConfig");

         //ppConfig.setAttrFString("host", " ");

         //ppConfig.setAttrFString("port", " ");

      }

      else

         deb.println("runtime is null");

      return ibspserviceProvider;

   }

   /**

    * Handle the GET and HEAD methods by building a simple web page.

    * HEAD is just like GET, except that the server returns only the

    * headers (including content length) not the body we write.

    */

   public void doGet (

      HttpServletRequest   request,

      HttpServletResponse   response ) throws ServletException, IOException

   {

    RequestDispatcher dispatcher=null;

    try

    {

      deb.println("4. Before sendRequest ");

      //get operation

      String oper = null;

      oper = getInputString(request,"UPDATE_CUSTOMER");

      if(oper == null)

         oper = getInputString(request,"SERVICES");

      if(oper == null)

         oper = getInputString(request,"UPDATE");

      if(oper == null)

          oper = getInputString(request,"UPDATE_SERVICES");

       if(oper == null)

          oper = getInputString(request,"BILLINGS");

      deb.println("5. Operation:"+oper);

      if(oper.equals("Update Customer details"))

      {

    deb.println("6. In Update Customer details");

    response.setContentType("text/html");

       dispatcher = getServletContext().getRequestDispatcher("/TelcoUpdcdetForm.jsp");

       sendRequest("getcdet",oper,request);

      }

      if(oper.equals("UPDATE"))

      {

       deb.println("6. In Update");

       String paymentMethod=getInputString(request,"payment_method_value");

       response.setContentType("text/html");

       dispatcher = getServletContext().getRequestDispatcher("/TelcoUpdcdetForm.jsp");

       sendRequest("updcdet",oper,request);

if(paymentMethod.length()!=0)

       sendRequest("updpaym",oper,request);

      }

      if(oper.equals("Services"))

      {

       deb.println("6. In Services");

       response.setContentType("text/html");

       dispatcher = getServletContext().getRequestDispatcher("/TelcoServicesForm.jsp");

       sendRequest("gcsvc",oper,request);

         sendRequest("getsvlst",oper,request);

      }

      if(oper.startsWith("Add")||oper.startsWith("Remove"))

      {

       deb.println("6. In "+oper+" Service");

       response.setContentType("text/html");

         dispatcher = getServletContext().getRequestDispatcher("/TelcoServicesForm.jsp");

          sendRequest("ucsvc",oper,request);

       sendRequest("getsvlst",oper,request);

       sendRequest("gcsvc",oper,request);

      }

      if(oper.equals("Billings"))

      {

       deb.println("6. In Billings");

       response.setContentType("text/html");

       dispatcher = getServletContext().getRequestDispatcher("/TelcoBillingsForm.jsp");

       // sendRequest("gcbild",oper,request);

      }

      if(oper.equals("Get Billings"))

{

    deb.println("6. In Get Billings");

    response.setContentType("text/html");

       dispatcher = getServletContext().getRequestDispatcher("/TelcoGetBillingsForm.jsp");

    sendRequest("gcbild",oper,request);

    }

deb.println("7. After sendRequest ");

    }

    catch(BspException BspError)

    {

    deb.println("BspException:"+BspError.getMessage());

    response.setContentType("text/html");

    dispatcher = getServletContext().getRequestDispatcher("/ExceptionForm.jsp");

    request.setAttribute("BspException",BspError.getMessage());

    }

    catch(Exception exception)

    {

    deb.println("Exception:"+exception.toString());

    response.setContentType("text/html");

    dispatcher = getServletContext().getRequestDispatcher("/ExceptionForm.jsp");

    request.setAttribute("Exception",exception.toString());

    }

    dispatcher.include(request, response);

    deb.println("8. before return ");

    return;

   }

public void sendRequest(String i_requestCode,String oper, HttpServletRequest    request) throws Exception

   {

    IBSPFunctionObject fn = null;

    IBSPDataObject data = null, prop = null;

    IBSPServiceProvider sp=null;

    int hr = 1;

    try

    {

      deb.println("i_requestCode : "+i_requestCode);

      deb.println(" Before getRuntime()");

      IBSPRuntime runtime = getRuntime();

      deb.println("After getRuntime()");

      if(   runtime != null )

      {

         deb.println("Before getServiceProvider()");

         sp = getServiceProvider(runtime);

         deb.println("After getServiceProvider()");

         if( sp != null )

         {

    deb.println("Telco "+i_requestCode);

          deb.println("Before createFunctionObject()");

          fn = runtime.createFunctionObject("CICS", i_requestCode);

          deb.println("After createFunctionObject()");

          hr = sp.enable();

          deb.println("After enable(), hr = "+hr);

          if( fn != null )

          {

            hr = fn.useServiceProvider(sp);

            deb.println("After useServiceProvider(), hr = "+hr);

            hr = fn.prepare(i_requestCode);

            deb.println("After prepare(), hr = "+hr);

            data = fn.getDataBlock();

            deb.println("After getDataBlock()");

            if( data != null )

            {

             setInputData(i_requestCode,data,oper,request);

             prop = fn.getProperties();

                deb.println("After getProperties()");

               if( prop != null )

               {

            

                  prop.setAttrInt("CONNECTION.StubReason",0 );

               }

               deb.println("Before execute()");

               hr = fn.execute();

               deb.println("After execute(), hr = "+hr);

               if( hr == 0 )

               {

                  data = fn.getDataBlock();

                  deb.println("After getDataBlock()");

                  if( data != null )

                  {

                     getOutputData(i_requestCode,data,request);

                  }

                  prop = fn.getProperties();

                  deb.println("After getProperties()");

                  if(prop != null)

                  {

                     deb.println("APPLID: "+prop.getAttrFString("CONNECTION.Applid"));

                     deb.println("LU: "+prop.getAttrFString("CONNECTION.LU"));

                     deb.println("TargetSYSID: "+prop.getAttrFString("CONNECTION.TargetSYSID"));

                     deb.println("TranName: "+prop.getAttrFString("CONNECTION.TranName"));

                     deb.println("TargetTranName: "+prop.getAttrFString("CONNECTION.TargetTranName"));

                     deb.println("Request: "+prop.getAttrFString("CONNECTION.Request"));

                     deb.println("Applind: "+prop.getAttrFString("CONNECTION.Applind"));

                     deb.println("RC: "+prop.getAttrFString("CONNECTION.RC"));

                     deb.println("RelayRC: "+prop.getAttrFString("CONNECTION.RelayRC"));

                     deb.println("StubRC: "+prop.getAttrFString("CONNECTION.StubRC"));

                     deb.println("StubReason: "+Integer.toString(prop.getAttrInt("CONNECTION.StubReason")));

                     deb.println("StubRequest: "+prop.getAttrFString("CONNECTION.StubRequest"));

                     deb.println("UseStub: "+prop.getAttrFString("CONNECTION.UseStub"));

                     deb.println(" * * * * * * ");

                  }

               } // if(hr == 0)

               else

                  deb.println("Search Failed");

            } // if(data != null)

            else

               deb.println("Search Failed");

          } // if( fn != null )

          else

            deb.println("Search Failed");

          hr = sp.disable();

          deb.println("After disable(), hr = "+hr);

       } // if(sp != null )

       else

          deb.println("Search Failed");

      } // if(runtime != null )

      else

         deb.println("Search Failed");

}

catch(BspException BspError)

{

if(sp!=null)

{

hr = sp.disable();

deb.println("After disable(), hr = "+hr);

}

throw(BspError);

}

catch(Exception Error)

{

if(sp!=null)

{

hr = sp.disable();

   deb.println("After disable(), hr = "+hr);

}

throw(Error);

}

return;

}

public void setInputData(String i_requestCode,IBSPDataObject data,String oper,HttpServletRequest request) throws BspException

{

deb.println("In start of setInputData");

if(i_requestCode.equals("getcdet"))

{

    data.setAttrFString("INPUT.INPUT-SEC.in-Tel-Number",getInputString(request,"ph one_num"));

}

if(i_requestCode.equals("updcdet"))

{

data.setAttrFString("INPUT.INPUT-SEC.in-request","UPDATE");

data.setAttrFString("INPUT.INPUT-SEC.in-Tel-Number",getInputString(request,"ph one_num"));

data.setAttrFString("INPUT.INPUT-SEC.in-First-Name",getInputString(request,"fi rstname_value"));

data.setAttrFString("INPUT.INPUT-SEC.in-Last-Name",getInputString(request,"las tname_value"));

data.setAttrFString("INPUT.INPUT-SEC.in-billing.in-billing-Address",getInputSt ring(request,"address_value"));

data.setAttrFString("INPUT.INPUT-SEC.in-billing.in-billing-City",getInputStrin g(request,"city_value"));

data.setAttrFString("INPUT.INPUT-SEC.in-billing.in-billing-State",getInputStri ng(request,"state_value"));

data.setAttrFString("INPUT.INPUT-SEC.in-billing.in-billing-Country",getInputSt ring(request,"country_value"));

data.setAttrFString("INPUT.INPUT-SEC.in-billing.in-billing-Zip-Code",getInputS tring(request,"zipcode_value"));

                  

}

if(i_requestCode.equals("updpaym"))

{

data.setAttrFString("INPUT.INPUT-SEC.in-Tel-Number",getInputString(request,"ph one_num"));

data.setAttrFString("INPUT.INPUT-SEC.in-First-Name",getInputString(request,"fi rstname_value"));

data.setAttrFString("INPUT.INPUT-SEC.in-Last-Name",getInputString(request,"las tname_value"));

         String paymentMethod=getInputString(request,"payment_method_value");

if(paymentMethod.equals("Credit Card"))

       data.setAttrInt("INPUT.INPUT-SEC.in-payment-Method",0);

else

    {

if(paymentMethod.equals("Checks"))

       data.setAttrInt("INPUT.INPUT-SEC.in-payment-Method",1);

}

data.setAttrFString("INPUT.INPUT-SEC.in-credit-Card-Number",getInputString(req uest,"credit_num_value"));

data.setAttrFString("INPUT.INPUT-SEC.in-expiration-Date",getInputString(reques t,"exp_date_value"));

data.setAttrFString("INPUT.INPUT-SEC.in-billing-Zip-Code",getInputString(reque st,"zipcode_value"));

            

}

if(i_requestCode.equals("getsvlst"))

{

    String name="INPUT.DFHCOMMAREA.OUTPUT-SEC.out-Services";

IBSPDataObject in_array=null;

    in_array=data.getAttrDataObject(name);

      

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

    {

       ((IBSPDataObjectArray )in_array).addElem();

      

}

}

if(i_requestCode.equals("gcsvc"))

{

data.setAttrFString("INPUT.DFHCOMMAREA.input-sec.in-Tel-Number",getInputString (request,"phone_num"));

}

if(i_requestCode.equals("ucsvc"))

{

data.setAttrFString("INPUT.DFHCOMMAREA.input-sec.in-Tel-Number",getInputString (request,"phone_num"));

    if(oper.startsWith("Add"))

    {

data.setAttrFString("INPUT.DFHCOMMAREA.input-sec.in-request","ADD");

data.setAttrInt("INPUT.DFHCOMMAREA.input-sec.in-service-Code",(Integer.valueOf (oper.substring(3))).intValue());

    }

    else

    {

data.setAttrFString("INPUT.DFHCOMMAREA.input-sec.in-request","REMOVE");

data.setAttrInt("INPUT.DFHCOMMAREA.input-sec.in-service-Code",(Integer.valueOf (oper.substring(6))).intValue());

    }

}

if(i_requestCode.equals("gcbild"))

{

data.setAttrFString("INPUT.input-sec.in-Tel-Number",getInputString(request,"ph one_num"));

    data.setAttrFString("INPUT.input-sec.in-month-and-year",getInputString(request ,"month_year_value"));

String line=getInputString(request,"line_value");

    if(line.length()==0)

       line="0";

data.setAttrInt("INPUT.input-sec.from-line-number",(Integer.valueOf(line)).int Value());

      

}

deb.println("In end of setInputData");

}

   

public void getOutputData(String i_requestCode,IBSPDataObject data,HttpServletRequest request) throws BspException

{

deb.println("In start of getOutputData");

if(i_requestCode.equals("getcdet"))

{

request.setAttribute("phone_num",data.getAttrFString("INPUT.INPUT-SEC.in-Tel-N umber"));

request.setAttribute("message_value",data.getAttrFString("OUTPUT.OUTPUT-SEC.OU T-MSG"));

request.setAttribute("lastname_value",data.getAttrFString("OUTPUT.OUTPUT-SEC.O UT-LASTNAME"));

    request.setAttribute("firstname_value",data.getAttrFString("OUTPUT.OUTPUT-SEC. OUT-FIRSTNAME"));

    request.setAttribute("address_value",data.getAttrFString("OUTPUT.OUTPUT-SEC.OU T-billing.OUT-billing-Address"));

request.setAttribute("city_value",data.getAttrFString("OUTPUT.OUTPUT-SEC.OUT-b illing.OUT-billing-City"));

request.setAttribute("state_value",data.getAttrFString("OUTPUT.OUTPUT-SEC.OUT- billing.OUT-billing-State"));

request.setAttribute("country_value",data.getAttrFString("OUTPUT.OUTPUT-SEC.OU T-billing.OUT-billing-Country"));

request.setAttribute("zipcode_value",data.getAttrFString("OUTPUT.OUTPUT-SEC.OU T-billing.OUT-billing-Zip-Code"));

                        

}

if(i_requestCode.equals("updcdet"))

{

request.setAttribute("phone_num",data.getAttrFString("INPUT.INPUT-SEC.in-Tel-N umber"));

request.setAttribute("firstname_value",data.getAttrFString("INPUT.INPUT-SEC.in -First-Name"));

request.setAttribute("lastname_value",data.getAttrFString("INPUT.INPUT-SEC.in- Last-Name"));

request.setAttribute("address_value",data.getAttrFString("INPUT.INPUT-SEC.in-b illing.in-billing-Address"));

request.setAttribute("city_value",data.getAttrFString("INPUT.INPUT-SEC.in-bill ing.in-billing-City"));

request.setAttribute( "state_value", data.getAttrFString("INPUT.INPUT-SEC.in-billing.in-billing-State"));

request.setAttribute( "country_value", data.getAttrFString("INPUT.INPUT-SEC.in-billing.in-billing-Country"));

request.setAttribute( "zipcode_value", data.getAttrFString("INPUT.INPUT-SEC.in-billing.in-billing-Zip-Code"));

    request.setAttribute("message_value",data.getAttrFString("OUTPUT.OUTPUT-SEC.OU T-MSG"));

}

if(i_requestCode.equals("updpaym") )

{

request.setAttribute("message_value1",data.getAttrFString("OUTPUT.OUTPUT-SEC.O UT-MSG"));

}

if(i_requestCode.equals("getsvlst"))

{

    request.setAttribute("message_value",data.getAttrFString("OUTPUT.DFHCOMMAREA.O UTPUT-SEC.OUT-MSG"));

int services_num=data.getAttrInt("OUTPUT.DFHCOMMAREA.OUTPUT-SEC.number-of-services ");

request.setAttribute("services_num",new Integer(services_num));

   Vector services_list=new Vector(0);

   Services service=null;

deb.println("before array");

IBSPDataObject outputArray=data.getAttrDataObject("OUTPUT.DFHCOMMAREA.OUTPUT-SEC.out-Services ");

deb.println("after array");

IBSPDataObject outputStruct;

   deb.println("services num="+services_num);

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

   {

outputStruct= ((IBSPDataObjectArray )outputArray).getElemDataObject(i);

service=new Services(outputStruct.getAttrInt("out-service-Code"),

outputStruct.getAttrFString("out-service-Name"),

outputStruct.getAttrFString("out-base-price"),

outputStruct.getAttrFString("out-price-per-call"));

deb.println("before set element"+i);

services_list.addElement((Object)service);

deb.println("after set element"+i);

   }

   request.setAttribute("services_list",services_list);

}

if(i_requestCode.equals("gcsvc"))

{

request.setAttribute("message_value1",data.getAttrFString("OUTPUT.OUTPUT-SEC.O UT-MSG"));

    int services_num=data.getAttrInt("OUTPUT.OUTPUT-SEC.number-of-services");

request.setAttribute("customer_services_num",new Integer(services_num));

Vector customer_services_list=new Vector(0);

    Services service=null;

IBSPDataObject outputArray=data.getAttrDataObject("OUTPUT.OUTPUT-SEC.out-Services");

    IBSPDataObject outputStruct;      

    deb.println("services num="+services_num);

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

    {

outputStruct= ((IBSPDataObjectArray )outputArray).getElemDataObject(i);

               

service=new Services(outputStruct.getAttrInt("out-service-Code"),

    outputStruct.getAttrFString("out-service-Name"),

    outputStruct.getAttrFString("out-base-price"),

    outputStruct.getAttrFString("out-price-per-call"));

deb.println("before set element"+i);

customer_services_list.addElement((Object)service);

deb.println("after set element"+i);

    }

request.setAttribute("customer_services_list",customer_services_list);            

}

if(i_requestCode.equals("ucsvc") )

{

request.setAttribute("message_value2",data.getAttrFString("OUTPUT.OUTPUT-SEC.O UT-MSG"));

}

if(i_requestCode.equals("gcbild"))

{

   

request.setAttribute("message_value",data.getAttrFString("OUTPUT.OUTPUT-SEC.OU T-MSG"));

request.setAttribute("amount_billed_value",data.getAttrFString("OUTPUT.OUTPUT- SEC.out-amount-billed"));

request.setAttribute("amount_payed_value",data.getAttrFString("OUTPUT.OUTPUT-S EC.out-amount-payed"));

//get calls

    int calls_num=data.getAttrInt("OUTPUT.OUTPUT-SEC.out-number-of-calls");

request.setAttribute("calls_num",new Integer(calls_num));

Vector calls_list=new Vector(0);

    Call_details call=null;

IBSPDataObject outputArray=data.getAttrDataObject("OUTPUT.OUTPUT-SEC.out-calls");

    IBSPDataObject outputStruct;      

    deb.println("calls num="+calls_num);

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

    {

outputStruct= ((IBSPDataObjectArray )outputArray).getElemDataObject(i);

deb.println("get"+i);

    call=new Call_details(outputStruct.getAttrFString("out-date"),

    outputStruct.getAttrFString("out-time"),

    outputStruct.getAttrFString("out-partner-phone"),

outputStruct.getAttrFString("out-duration"),

    outputStruct.getAttrFString("out-charge"),

    outputStruct.getAttrFString("out-calls-service-name"));

deb.println("before set element"+i);

calls_list.addElement((Object)call);

deb.println("after set element"+i);

    }

    request.setAttribute("calls_list",calls_list);   

                

//get services

int services_num=data.getAttrInt("OUTPUT.OUTPUT-SEC.out-number-of-services");

request.setAttribute("services_num",new Integer(services_num));

Vector services_list=new Vector(0);

    Service_details service=null;

outputArray=data.getAttrDataObject("OUTPUT.OUTPUT-SEC.out-services");

          

    deb.println("services num="+services_num);

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

    {

outputStruct= ((IBSPDataObjectArray )outputArray).getElemDataObject(i);

               

service=new Service_details(outputStruct.getAttrInt("out-service-code"),

    outputStruct.getAttrFString("out-service-name"),

    outputStruct.getAttrFString("out-svc-charge"));

deb.println("before set element"+i);

services_list.addElement((Object)service);

deb.println("after set element"+i);

    }

   request.setAttribute("services_list",services_list);

}

    deb.println("In end of getOutputData");

}

}





Code Example 3-9 Service Class



package TelcoSample;

public class Services
{
public String service_code = "";
public String service_name="";
public String price ="";
public String price_unit="";

public Services(int code,String name,String in_price,String in_price_unit)
{
service_code=String.valueOf(code);
service_name=new String(name);
price=new String(in_price);




"> Service Class Code Sample. Code Example 3-9 Service Class


package TelcoSample;

public class Services
{
public String service_code = "";
public String service_name="";
public String price ="";
public String price_unit="";

public Services(int code,String name,String in_price,String in_price_unit)
{
service_code=String.valueOf(code);
service_name=new String(name);
price=new String(in_price);







Code Example 3-10 Service Detail Class code Sample



package TelcoSample;

public class Service_details
{
public String out_service_code = "";
public String out_service_name="";
public String out_charge="";

public Service_details(int service_code,String service_name,String charge)
{
out_service_code=String.valueOf(service_code);
out_service_name=new String(service_name);
out_charge=new String(charge);
}
}


"> Service Detail Class Code Sample Code Example 3-10 Service Detail Class code Sample


package TelcoSample;

public class Service_details
{
public String out_service_code = "";
public String out_service_name="";
public String out_charge="";

public Service_details(int service_code,String service_name,String charge)
{
out_service_code=String.valueOf(service_code);
out_service_name=new String(service_name);
out_charge=new String(charge);
}
}





Previous     Contents     Index     DocHome     Next     
Copyright © 2000 Sun Microsystems, Inc. Some preexisting portions Copyright © 2000 Netscape Communications Corp. All rights reserved.

Last Updated June 09, 2000