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.
In the Project Explorer view, navigate to the J2C bean implementation class that was created previously.
- Expand J2CPhoneBook > Java Resources: src > sample.ims, as shown in Figure 51.
Figure 51. View of the J2CPhoneBook project in Project Explorer
- 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
- 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
- Press Browse to look up the J2C bean Implementation class, as shown in Figure 54:
Figure 54. Clicking Browse to select the J2C bean
P, select the PhoneBookImpl class in package sample.ims and click OK, as shown in Figure 55:
Figure 55. Selecting the PhoneBookImpl class
This returns the fully-qualified implementation class in the dialog, as shown in Figure 56.
- Press Next to continue.
Figure 56. The PhoneBookImpl class selected
Select Web Service as the J2EE Resource Type, as shown in Figure 57.
- 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
Examine the generated J2EE resources for Web services.
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
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
Note that the http://localhost:portnumber/... is generated. This tutorial uses port 9082.
- If the port number is not 9082, in the Design view, click the http that is displayed in http://localhost:portnumber/J2C....
- Click the Properties tab and change the port number to 9082, as shown in Figure 60.
Save the changes (Ctrl+S).
Figure 60. Port number to use for this tutorial
Close the PhoneBookImpl.wsdl editor by pressing Ctrl+Shift+F4.
In this part of the tutorial, you will use the Web Services Explorer to test your Web service.
- 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
- 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
- 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
- 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
- Click the runPhoneBook operation, as shown in Figure 65:
Figure 65. The runPhoneBook operation for the Web service in Web Services Explorer
- This will invoke the WSDL operation, as shown in Figure 66:
Figure 66. The WSDL operation
Enter the necessary information to run the IVTNO transaction, as shown in Figure 67. These will be the same parameters used for TestClient.jsp:
- Click Go to run the Web service:
Figure 67. Specifying the values for the parameters and clicking Go to run the service
- 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
- 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
- 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
- Close all open editor windows (pressing Ctrl+Shift+F4 will accomplish this).
In this part of the lab exercise, we will generate Web service client and test it with your Web service.
- 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
- 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
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.
- Click the Client project: J2CPhoneBook link, as shown in Figure 73:
Figure 73. Configuring a client project for J2CPhoneBook
In the following dialog, change the client project name from
J2CPhoneBookWeband click OK, as shown in Figure 74:
Figure 74. Specifying the name for the client project
- You will return to the Web Service Client form. Click Next. The dialog shown in Figure 75 displays:
Figure 75. Web service proxy page
- Accept the defaults and click Next. If you see the warning shown in Figure 76, click Yes All:
Figure 76. Enabling automatic file overwriting
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
- Click Finish. The warning shown in Figure 78 is normal. Click OK if it displays:
Figure 78. Clicking OK to ignore the warning
- 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
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.
Follow steps 6-9 in Task 3: Deploy and test your application > Testing your application again to test the Web service client.
- 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
- 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.