Programming Component Interfaces in Java

This chapter discusses how to:

Click to jump to parent topicBuilding APIs in Java

If you plan to access your component interface from a Java external application, you must create a component interface API. The APIs are in the form of *.java source code files, which should be compiled into Java classes.

To build the component interface bindings:

  1. Open any component interface definition in PeopleSoft Application Designer.

    Use any component interface definition, because you can build APIs for all of them, regardless of which one is open.

  2. Select Build, PeopleSoft APIs.

    The Build PeopleSoft API Bindings dialog box appears.

  3. Select the Build check box in the Java Classes group box.

    For the target directory, enter the directory in which you want the Java class source files to be created.

  4. Click OK to build the bindings that you selected.

    The files that constitute the bindings are built in the location that you specified. If the operation is successful, a Done message appears in the PeopleSoft Application Designer Build window.

  5. Compile the APIs that you just generated.

    You could use one of these commands:

Click to jump to parent topicSetting Up the Java Environment

When deploying component interfaces on a local client machine or web server with Java bindings, you must have:

To set up your client machine to access the component interface API using Java:

  1. If it is not already installed on your system, install the Sun Microsystems JDK to enable the JVM.

    You can download the JDK to any location, for example c:\bea\jkd<version>.

  2. Set the environment variable PATH to include the directory containing jvm.dll.

    For example, you might set it at c:\bea\jkd<version>\jre\bin\client; or, if the PeopleTools install is done locally, the path is <PS_HOME>\jre\bin\client.

  3. Set the environment variable CLASSPATH to include:

Note. In previous releases, sites using UNIX servers received the following error message when invoking a component interface through the PeopleSoft Java Object Adapter (PSJOA): PSProperties not loaded from file. To resolve this issue, copy the pstools.properties file to the component interface execution directory.

Click to jump to parent topicGenerating Java Runtime Code Templates

To access a component interface through external APIs using Java, PeopleSoft Application Designer generates a template in the form of boilerplate Java code that you can adapt to your purposes.

External Java APIs are located in the <PS_CFG_HOME>\ExtAPI_Java directory.

This section describes how to generate the template code.

To generate a Java template for a component interface:

  1. Open a component interface definition in PeopleSoft Application Designer.

  2. Right-click anywhere in the definition view to display the menu.

  3. Select Generate Java Template.

    When the template is successfully generated, a message appears stating the name and location of the template file.

    Note. The template file is generated in the directory specified by the TEMP or TMP system environment variable on your client machine.

  4. Edit the generated file and modify the source code to suit your needs.

  5. Compile the source code to generate a class file.

    In the case of the example used in this manual, you could use this command:

    javac −classpath c:\temp;c:\pt8\class;c:\PT8\class\psjoa.jar SDK_BUS_EXP.java

Click to jump to parent topicUnderstanding the Java Template

You can use the Java template as a starting point for your Java program. This section contains a skeleton of the generated Java template for a component interface named SDK_BUS_EXP, which is part of the component interface SDK. The template has been edited for length.

Import all the required classes.

import java.io.*; import psft.pt8.joa.*; import PeopleSoft.Generated.CompIntfc.*; public class SDK_BUS_EXP { public static ISession oSession; ..... public static void main (String args[]) { try { //***** Set Connect Parameters ***** String strServerName, strServerPort, strAppServerPath; String strUserID, strPassword; ..... //Build Application Server Path strAppServerPath = strServerName + ":" + strServerPort;

Note. To enable Jolt failover and load balancing in the PeopleSoft Pure Internet Architecture, you can supply multiple application server domains for the strAppServerPath variable. Separate the domain names with a comma, and make sure that no spaces are included, for example, strAppServerPath = //APPSRVR1:8000,//APPSRVR2:9000

Create the PeopleSoft Session object to enable access to the PeopleSoft system.

The Session object controls the environment and enables you to do error handling for all APIs from a central location.

//***** Create PeopleSoft Session Object ***** oSession = API.createSession();

Connect to the application server by using the connect method of the Session object.

//***** Connect to the App Server ***** //if the Jolt Password is to be provided, switch to the the second //version of the statement below if (!oSession.connect(1, strAppServerPath, strUserID, strPassword, null)) { //if (!oSession.connectS(1, strAppServerPath, strUserID, //strPassword, null, strJoltPwd)){ System.out.println("\nUnable to Connect to the Application Server. Please verify it is running"); ErrorHandler(); return; }

If the application server is configured to use a domain connection password other than the default value, use the connectS method, currently shown commented out in the previous Java template example, instead of the Connect method. The connectS method takes in all the same parameters as the Connect method, plus a domain Connection password as an additional parameter:

connectS(1, strAppServerPath, strUserID, strPassword, null, strJoltPwd);

You define the domain connection password using the DomainConnectionPwd field in the Security section of the application server configuration file, configuration.properties.

See DomainConnectionPwd, Configuring Domain Connection Password.

Get a reference to the component interface providing its name. (A runtime error occurs if the component interface does not exist.)

ISdkBusExp oSdkBusExp; String ciName; ciName = "SDK_BUS_EXP"; oSdkBusExp = (ISdkBusExp) oSession.getCompIntfc(ciName); if (oSdkBusExp == null) { System.out.println("\nUnable to Get Component Interface " + ciName); ErrorHandler(); return; } //***** Set the Component Interface Mode ***** oSdkBusExp.setInteractiveMode(false); oSdkBusExp.setGetHistoryItems(true); oSdkBusExp.setEditHistoryItems(false);

Set the keys for the component interface. In this example, SDK_EMPLID is the Get key.

//***** Set Component Interface Get/Create Keys ***** String strSdkEmplid; System.out.print("\nEnter SdkEmplid: "); strSdkEmplid = inData.readLine(); oSdkBusExp.setSdkEmplid(strSdkEmplid);

The get() method retrieves data from the database, associated with the key values.

//***** Execute Get ***** if (!oSdkBusExp.get()) { System.out.println("\nNo rows exist for the specified keys. \nFailed to get the Component Interface."); ErrorHandler(); return; } .....

Get and print properties at level 0.

System.out.println("oSdkBusExp.SdkName: " + oSdkBusExp.getSdkName()); .....

Similar code is generated for the properties SDK_BIRTHDATE and SDK_DEPTID.

Get collection at level 1 (SDK_BUS_EXP_PER).

ISdkBusExpSdkBusExpPerCollection oSdkBusExpPerCollection; ISdkBusExpSdkBusExpPer oSdkBusExpPer; oSdkBusExpPerCollection = oSdkBusExp.getSdkBusExpPer();

Get and print properties at level 1.

for (int i17 = 0; i17 < oSdkBusExpPerCollection.getCount(); i17++) { oSdkBusExpPer = oSdkBusExpPerCollection.item(i17); System.out.println("oSdkBusExpPer.SdkExpPerDt: " + oSdkBusExpPer.getSdkExpPerDt()); .....

Similar code is generated for the properties SDK_EMPLID and SDK_BUS_EXP_SUM in the SDK_BUS_EXP_PER collection.

Get collection at level 2 (SDK_BUS_EXP_DTL).

ISdkBusExpSdkBusExpPerSdkBusExpDtlCollection oSdkBusExpDtlCollection; ISdkBusExpSdkBusExpPerSdkBusExpDtl oSdkBusExpDtl; oSdkBusExpDtlCollection = oSdkBusExpPer.getSdkBusExpDtl();

Get and print properties at level 2.

for (int i211 = 0; i211 < oSdkBusExpDtlCollection.getCount(); i211++) { oSdkBusExpDtl = oSdkBusExpDtlCollection.item(i211); System.out.println("oSdkBusExpDtl.SdkChargeDt: " + oSdkBusExpDtl.getSdkChargeDt()); .....

Similar code is generated for the properties SDK_EMPID, SDK_EXP_PER_DT, SDK_EXPENSE_CD, SDK_EXPENSE_AMT, SDK_CURRENCY_CD, SDK_BUS_PURPOSE, and SDK_DEPTID.

} }

Disconnect from the Application server by using the disconnect method of the Session object. This method clears the buffers and releases the memory.

//***** Disconnect from the App Server ***** oSession.disconnect(); return; } catch (Exception e) { e.printStackTrace(); System.out.println("An error occurred: "); ErrorHandler(); } } }