How Do I: Use a Tuxedo Service in a Java Application

The Tuxedo Control allows you to create a web service or WebLogic Workshop application that uses one or multiple Tuxedo services in its business logic. The Tuxedo Control is a generic interface. To use the control to communicate with specific Tuxedo services, you must create a Control Extension (jcx file). The Control Extension is a Java interface that tells the Tuxedo Control the names of the Tuxedo services you want to invoke, the type of interaction the services require (service with reply, queued service, etc), and the Tuxedo buffer types the services expect as input. Your application invokes the methods defined by the Control Extension interface to invoke the Tuxedo services. After you create a Control Extension for a specific set of Tuxedo services, you can reuse the Control Extension in any application that needs to access those services. WebLogic Workshop does most of the work of creating a Control Extension for you.

In this section, the example shown represents creating a web service. The code for a web service is contained in a Java Web Service (JWS) file. A JWS file is a Java file in that it contains code for a Java class as well as implementation code intended specifically for a web service class targeted to run under WebLogic Server.

To create a web service that uses a Tuxedo service:

Set Up Your Environments

  1. Start the Tuxedo server that advertises the Tuxedo service you want to use.
  2. Start WebLogic Workshop. From the Start menu, choose Programs ->WebLogic Platform 8.1 ->WebLogic Workshop 8.1.
  3. Start WebLogic Server. You can confirm the status of WebLogic Server by checking the status bar at the bottom of WebLogic Workshop. If WebLogic Server is running, the status bar displays a green ball. If WebLogic Server is not running, the status bar displays a red ball. If the status bar shows a red ball and Server Stopped, then start WebLogic Server from the Tools menu. Choose Tools -> WebLogic Server -> Start WebLogic Server.

Create a Java Web Application

  1. Create or open a Webapp Application and Project in WebLogic Workshop.
  2. In the Enter a new folder name field, type the name of the folder where you want your web service to reside.
  3. image

  4. Click OK. The new folder appears inside the existing WebLogic Workshop Project folder in the Application tab.
  5. Right-click the new folder and select New -> Web Service or other application type you want. The New File dialog box displays.
  6. image

  7. In the upper left-hand pane, confirm that Web Services is selected. In the upper right-hand pane, confirm that Web Service is selected. In the File Name field, type the name of the web service. The File Name you enter becomes the name of the web service class WebLogic Workshop creates.
  8. Note: If you selected an alternative application type other than Web Service, confirm the selection and enter an appropriate File Name.

  9. Click Create. In the case of a Web Service, a new JWS file is created and displayed in the Design View.

Add a Tuxedo Control to Your Java Application

Controls act as interfaces between your web service and other data sources. Therefore, you want to add a Tuxedo Control to your web service to provide your web service with access to Tuxedo services.

Java Control Extensions (JCX File) define an interface, but no implementation. Using the control is a matter of declarative programming instead of procedural programming.

The tasks in this step are:

Use a Tuxedo Control Extension

In this task you will use a Tuxedo Control file and then add a method to the control file.

  1. Select the web service in which you want to use a Tuxedo service.
  2. Click the Design View tab.
  3. From the Insert menu, choose Controls -> Tuxedo. The Insert Control - Tuxedo dialog displays.
  4. image

  5. In Step 1 enter a variable name for the control.
  6. In step 2 click one of the following radio buttons:
  7. Click Use a Tuxedo Control already defined by a JCX file to use an existing Tuxedo Control file. Browse to the JCX file. If you select an existing JCX file, the remaining fields in the Tuxedo Control - Insert Tuxedo dialog become inactive.

    Click Create a new Tuxedo Control to use to create a new Tuxedo Control. You can follow the procedures described in How Do I: Create a Tuxedo Control, to create a new Tuxedo Control to use in your application.

Create a WebLogic Tuxedo Connector (WTC) Service

WTC acts as a gateway between the Tuxedo environment and WebLogic environment; therefore, a WTC service definition must exist that maps to the Tuxedo service you want to use in your web service.

Import the Tuxedo service that you want to use in your web service. For information on how to import WTC services, see How Do I: Configure a WTC Service.

Use Public Methods from the Control Extension

The Tuxedo Control provides the following public methods to use in your web service in addition to the methods defined by your control extension. If you want to use these methods you must call them explicitly.

Public Method
Description

getConnection()

Gets the WTC connection currently used by this control. This allows you to use more of the WTC APIs defined for a connection. getConnection() returns an instance of an ApplicationToMonitorInterface object that can be used to interact with Tuxedo through JATMI calls.

Note: This method will not allow you to terminate the connection or use tpacall with asynchronous calls.

Using the getConnection() method assumes that the developer has a working knowledge of WTC calls.

getMappingIssues()

Returns an array of MappingIssues associated with the last request made. Mapping issues are generated by the control when there is a discrepancy between the Java data type and the Tuxedo buffer.

gettpurcode()

Returns the tpurcode associated with the last exception that occurred.

gettperrno()

Returns the tperrno associated with the last request made by the control.

Use a Tuxedo Service from the Control Extension

Next you must incorporate one or more methods from the control extension just created in the previous step in your web service.

  1. Select the web service file (JWS).
  2. Click the Design View tab.
  3. From the Data Palette, drag a method from the control extension to the web service Design View. This adds a method to the web service that shows up as a SOAP service. The implementation of this service simply calls the Tuxedo Control extension; therefore, exposing the Tuxedo service as a web service.
  4. For the web service to provide additional processing before or after the call to the Tuxedo service or if the web service needs a different signature, click the Source View tab and edit the Java code as needed.

  5. From the menu, select File -> Save.

Test the Web Service Using Debugger

Next you will test your web service using debugger.

  1. From the Debug menu, select Start.
  2. The WebLogic Workshop test browser displays with a place to enter the parameters for the web service method that was previously added. Enter the appropriate parameters and click the method name button.
  3. Verify the results that return at the bottom of the page when the test browser refreshed the window.

Add a Method to a Web Service

Web services expose their functionality through methods. These methods allow clients to request something from the web service.

To enhance the web service and add a method:

  1. Select the web service to which you want to add a method and click the Design View tab.
  2. Note: It is helpful, but not required, to be in the Design View so you can see the changes as you add elements to your web service.

  3. From the Insert menu, select Method.
  4. Select the method you want to add to the web service and click Enter.
  5. Provide the implementation of the web service. Write the method code that performs the function of the web service. For example, implementation of the web service may require calling one or more controls.
  6. From the menu select File -> Save to save your work.

Related Topics