Bankapp Web Service
This sample shows using the Tuxedo services of the bankapp sample as shipped with Tuxedo. It provides BankCtrl.jcx, a pre-configured Java Control Extension, that uses the DEPOSIT, WITHDRWAL, TRANSFER, INQUIRY, OPEN_ACCT, and CLOSE_ACCT services. For each of these services, an operation is defined in the Java Control Extension interface providing an easy to use mechanism for accessing these services.
Concepts Demonstrated By This Sample
Defining the method signatures in the JWS and JCX files to ensure correct mapping among the incoming web document, the application's Java data types, and the Tuxedo buffer.
To Run the Sample
Before running the bankapp sample, be sure you have accomplished the tasks defined in "Getting Started with the Tuxedo Control." This includes making sure you have modified the DMCONFIG and UBBCONFIG files to run the bankapp sample. Also, refer to the README file in <BEA_HOME>/weblogic81/samples/partners/Tuxedo/setup/bankapp directory. This README file explains what you must do to set up bankapp on the Tuxedo side.
- Start the Tuxedo server that advertises the services in the bankpapp application.
- Start WebLogic Workshop. From the Start menu, choose Programs ->WebLogic Platform 8.1 ->WebLogic Workshop.
- From the File menu, select New -> Application to create a new Application in WebLogic Workshop.
- In the New Application dialog, select All in the left pane and select Empty Application in the right-pane. Type bankapp in the Name field. Browse to an appropriate temporary directory for this sample.
- Click Create.
- Right-click on the bankapp in the Application tab. Select New ->Project.
- In the New Project dialog, select Web Services in the left pane. Type TestWS in the Project Name field.
- Click Create.
- Right-click on TestWS project in the Application tab and select New -> Folder.
- Create a folder labeled controls.
- Expand the TestWS node in the Application pane by clicking the + sign in front of TestWS. Right-click on TestWS and select New -> Web Service. A file creation wizard displays. Type bankapp.jws for the file name and click Create.
- Import the BankCtrl.jcx and bankflds.java files to the controls folder. Right-click on the controls folder and select Import. In the Import Files dialog, browse to <BEA_HOME>/weblogic81/samples/partners/Tuxedo/TuxSampleCode/bankapp/BankWS/controls directory and select BankCtrl.jcx and bankflds.java and click Import.
- Open the controls folder and double-click the BankCtrl.jcx file.
- Click the Source View tab. Edit the source code with the following change.
Change the method signature (source line) to:
public void OPEN_ACCT ();
to:
public OPEN_ACCT_RETURN OpenAccount (String LAST_NAME,
String FIRST_NAME,
String MID_INIT,
String SSN,
String ADDRESS,
String PHONE,
String ACCT_TYPE,
Integer BRANCH_ID,
String SAMOUNT);
- Select bankapp.jws from the Application pane and click the Design View tab.
- From the Data Palette, select Controls -> Add -> Tuxedo. The Insert Control - Tuxedo dialog displays.
In Step 1 enter a variable name for the control.
In step 2 click Use a Tuxedo Control already defined by a JCX file to use an existing Tuxedo Control file. Browse to controls/BankCtrl.jcx file.
Click Create to add the methods to the control.
- Edit the JWS file by inserting the control methods. In the Data Palette, expand the node for the control variable you created by clicking on the + sign. With the Design View of bankapp.jws in the central pane, drag and drop each of the six control methods onto the design pane. WebLogic Workshop creates web service methods to invoke the control methods.
- Add the following code to the bankapp.jws to change the Transfer service. The changes allow the XML sent to the web service and the XML returned from the service to reflect more clearly the nature of the data being sent. The Tuxedo input buffer has a single field with two occurrences to represent the source and target account IDs. Similarly, the return buffer has a single field with two occurrences to represent the source and target account balances. These multiple occurrence fields are most naturally represented as arrays in Java. The arrays are translated into separately named Java fields to make the XML representation clearer.
Enter a new nested class declaration for the return value of Transfer:
public static class TransferBalances
{
public String FROM_BALANCE;
public String TO_BALANCE;
public TransferBalances (String fromBal, String toBal)
{
FROM_BALANCE = fromBal;
TO_BALANCE = toBal; }
}
Change the definition of Transfer created by WebLogic Workshop to the following:
public TransferBalances Transfer(Integer fromAcct, Integer toAcct, String SAMOUNT)
{
controls.BankCtrl.Accounts inputAccts;
controls.BankCtrl.Balances retval;
TransferBalances tbal;
inputAccts = new controls.BankCtrl.Accounts(fromAcct, toAcct);
retval = bankSvc.Transfer(inputAccts, SAMOUNT);
tbal = new TransferBalances(retval.SBALANCE[0], retval.SBALANCE[1]);
return tbal;
}
- From the Debug menu, select Start.
- When the test browser displays, enter text in the fields and click the OpenAccount button.
- The results display at the bottom of the browser window when the browser refreshes.
Related Topics