Skip to main content

skip to main content

developerWorks  >  Rational | Information Management  >

Create a J2C application for an Information Management System (IMS) phonebook transaction using IMS TM Resource Adapter

developerWorks
Go to the previous pagePage 5 of 8 Go to the next page

Document options
PDF format - Fits A4 and Letter

PDF - Fits A4 and Letter
2957 KB (46 pages)

Get Adobe® Reader®


My developerWorks needs you!

Connect to your technical community


Rate this tutorial

Help us improve this content


Task 4 (Optional): Create a Web service to invoke the J2C bean

In the previous sections, you installed a J2C Resource Adapter, created a J2C bean that executed against the IMS sample transaction: IVTNO. You also created a simple JSP TestClient that tested your J2C bean. In this optional section, you will wrap the J2C bean as a Web service, and then test it by using the generated WSDL file. You will then generate a Web service client and test it as well.

What is a Web service?

Web services are self-contained, self-describing modular applications that can be published, located, and invoked across the Web. Businesses can dynamically mix and match Web services to perform complex transactions with minimal programming. Web services allow buyers and sellers all over the world to discover each other, connect dynamically, and execute transactions in real time with minimal human interaction.

The following standards play key roles in Web services: Web Services Description Language (WSDL) and Simple Object Access protocol (SOAP).

Creating a Web service

  1. In the Project Explorer view, navigate to the J2C bean implementation class that was created previously.

  2. Expand J2CPhoneBook > Java Resources: src > sample.ims, as shown in Figure 51.

Figure 51. View of the J2CPhoneBook project in Project Explorer
project explorer on left, code on right
  1. Right-click the PhoneBookImpl.java and select New > Other from the context menu, as shown in Figure 52:

Figure 52. Right-clicking the PhoneBookImple.java file
menu command
  1. In the New wizard screen, select Web Page, Web Service, or EJB from J2C Java Bean and click Next, as shown in Figure 53:

Figure 53. Selecting the wizard to wrap the J2C Java bean into a Web service
list of available wizards
  1. Press Browse to look up the J2C bean Implementation class, as shown in Figure 54:

Figure 54. Clicking Browse to select the J2C bean
choose J2C bean implementation class
  1. Type P, select the PhoneBookImpl class in package sample.ims and click OK, as shown in Figure 55:

Figure 55. Selecting the PhoneBookImpl class
select matching type
  1. This returns the fully-qualified implementation class in the dialog, as shown in Figure 56.

  2. Press Next to continue.

Figure 56. The PhoneBookImpl class selected
bean full path shows in dialog
  1. Select Web Service as the J2EE Resource Type, as shown in Figure 57.

  2. Click Next, and then Finish. The J2EE Resource from a J2C Java Bean wizard will now create the necessary J2EE resources for the Web service implementation. This might take a few moments.

Figure 57. Selecting Web Service as the resource type
choose J2EE Resource Type
  1. Examine the generated J2EE resources for Web services.

  2. Expand J2CPhoneBook > WebContent > WEB-INF > wsdl. Note the generated PhoneBookImpl.wsdl file and associated xml mapping files, as shown in Figure 58:


Figure 58. Generated J2EE resources for Web services based on the PhoneBookImpl J2C bean
resource in tree view
  1. Double-click the PhoneBookImpl.wsdl file to open up the WSDL editor. Observe the visual representation of the wsdl file in the Design view, as shown in Figure 59. There is also a source view, if you prefer.

Note that the Web service operation is runPhoneBook and that the operation has one input and one output, and that these map to the INPUTMSG and OUTPUTMSG defined previously.


Figure 59. PhoneBookImpl.wsdl in the Design view
design view selected, source view available
What is WSDL?

Web Services Description Language (WSDL) is an XML-based open specification that describes the interfaces to and instances of Web services on the network. Businesses can make the WSDL documents for their Web services available though UDDI, WSIL, or by broadcasting the URLs to their WSDL via email or Web sites.

  1. Note that the http://localhost:portnumber/... is generated. This tutorial uses port 9082.
    1. If the port number is not 9082, in the Design view, click the http that is displayed in http://localhost:portnumber/J2C....
    2. Click the Properties tab and change the port number to 9082, as shown in Figure 60.
    3. Save the changes (Ctrl+S).


Figure 60. Port number to use for this tutorial
select port details in Properties view
  1. Close the PhoneBookImpl.wsdl editor by pressing Ctrl+Shift+F4.



Back to top


Testing the Web service using Web Service Explorer

In this part of the tutorial, you will use the Web Services Explorer to test your Web service.

  1. Make sure that WebSphere Application Server is running. You will test your Web service using the WebSphere Application Server test environment. Using the Servers view, note the Status. If the WebSphere Application Server is not running, press the green arrow on the Servers tab to start it, as shown in Figure 61. This will take a few moments.

Figure 61. Starting the WebSphere Application Server
Servers view
  1. From the Project Explorer view, right-click the PhoneBookImpl.wsdl file and select Web Services > Test with Web Services Explorer, as shown in Figure 62.

Figure 62. Testing with Web Services Explorer
menu command
  1. The Web Services Explorer window will launch. It contains two views: a Navigator view and an Actions view. To make more space, maximize the window by double-clicking the title, as shown in Figure 63:

Figure 63. Double-clicking the Web Services Explorer tab to maximize the window
red arrow points to tab
  1. The Actions view specifies both the operations and endpoints for the Web service. The Endpoint is defined as http://localhost:9082/J2CPhoneBook/services/PhoneBookImpl. Note that this is the location of the Web service and that it points to the WebSphere Application Server running on your local workstation and listening on port 9082, as shown in Figure 64:

Figure 64. The location of the Web service
WSDL Binding Details
  1. Click the runPhoneBook operation, as shown in Figure 65:

Figure 65. The runPhoneBook operation for the Web service in Web Services Explorer
Available Operations
  1. This will invoke the WSDL operation, as shown in Figure 66:

Figure 66. The WSDL operation
runPhoneBook options
  1. Enter the necessary information to run the IVTNO transaction, as shown in Figure 67. These will be the same parameters used for TestClient.jsp:
    1. in__ll: 59
    2. in__zz: 0
    3. in__trcd: IVTNO
    4. in__cmd: DISPLAY
    5. in__name1: LAST1


  2. Click Go to run the Web service:

Figure 67. Specifying the values for the parameters and clicking Go to run the service
select Actions and click Go
  1. The Web service executes, and the results are displayed in the runPhoneBookResponse object, as shown in Figure 68. Scroll through the Status window or resize the window, as necessary, to see the results:

Figure 68. Resizing to maximize the Status window
stretch status boundaries
  1. Click the Source link to display the Web service results in the Form view, as shown in Figure 69:

Figure 69. Clicking the Source link in the Status window
red arrow points to link
  1. This will display the actual SOAP response and SOAP request envelope. Scroll down to see the data being transmitted to and from IMS, as shown in Figure 70:

Figure 70. SOAP request and response envelopes
red arrows point to slider bars
What is SOAP?

Simple Object Access Protocol (SOAP) is an XML-based standard for messaging over HTTP and other Internet protocols. It is a lightweight protocol for the exchange of information in a decentralized, distributed environment. It is based on XML, and consists of three parts:

  • An envelope that defines a framework for describing what is in a message and how to process it.
  • A set of encoding rules for expressing instances of application-defined data types.
  • A convention for representing remote procedure calls and responses.
  1. Close all open editor windows (pressing Ctrl+Shift+F4 will accomplish this).


Back to top


Generating a Web service client and using it to test the Web service

In this part of the lab exercise, we will generate Web service client and test it with your Web service.

  1. Make sure that WebSphere Application Server is running. Using the Servers view, note the Status. If the WebSphere Application Server is not running, press the green arrow on the Servers tab to start it, as shown in Figure 71. This will take a few moments.

Figure 71. Starting the WebSphere Application Server
red arrow points to green forward start icon
  1. From the Project Explorer view, right click the PhoneBookImpl.wsdl file and select Web Services > Generate Client, as shown in Figure 72.

Figure 72. Generating a Web service client
menu command
  1. The Web Service Client dialog opens. Move the slider all the way up to the Test client position so that the tool not only generates the client, but also deploys and tests it.

  2. Click the Client project: J2CPhoneBook link, as shown in Figure 73:

Figure 73. Configuring a client project for J2CPhoneBook
Web service options
  1. In the following dialog, change the client project name from J2CPhoneBook to J2CPhoneBookWeb and click OK, as shown in Figure 74:

Figure 74. Specifying the name for the client project
specify client project settings
  1. You will return to the Web Service Client form. Click Next. The dialog shown in Figure 75 displays:

Figure 75. Web service proxy page
output folder and security configuration
  1. Accept the defaults and click Next. If you see the warning shown in Figure 76, click Yes All:

Figure 76. Enabling automatic file overwriting
red arrow points to Yes All button
  1. On the dialog shown in Figure 77, clear all of the methods by clicking Deselect All, and then select only the runPhoneBook(sample.ims.data.INPUTMSG) method. That is the only method that you want to expose to your Client:

Figure 77. Selecting methods to expose
Test the generated proxies
  1. Click Finish. The warning shown in Figure 78 is normal. Click OK if it displays:

Figure 78. Clicking OK to ignore the warning
JSP client does not support type
  1. If you moved the slider to the Test Client position in Step 3, the client tool will generate the Web service client, deploy it into WebSphere Application Server and run it from the built-in Web browser, as shown in Figure 79:

Figure 79. The Web Services Test Client view
runPhoneBook link displays in Methods frame

The resulting JSP component looks exactly like the one in Step 4 in Task 3: Deploy and test your application > Testing your application.. The difference is in the way the JSP component calls the Java bean’s runPhoneBook() method, invoking it through a Web service instead of calling it directly.

  1. Follow steps 6-9 in Task 3: Deploy and test your application > Testing your application again to test the Web service client.

  2. When you are done testing, in the Server view, click the red square icon to stop the WebSphere Application Server, as shown in Figure 80:

Figure 80. Stopping the WebSphere Application Server
red arrow points to red square stop icon
  1. Close all open editor windows (pressing Ctrl+Shift+F4 to accomplish this).

You have completed the optional Web service generation part of the J2C bean tutorial.



Back to top



Go to the previous pagePage 5 of 8 Go to the next page