31
Consuming Services in Browser Based Web Applications using IBM Rational Application Developer By Nitin Raut ([email protected] ) Certified Consulting IT Specialist IBM Corporation April 2010 Skill Level: Intermediate Consuming Services in Browser Based Web Applications Page 1

Consuming Services in Browser Based Web Applications using IBM

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Consuming Services in Browser Based Web Applications using IBM

Consuming Services in Browser Based Web Applications using IBM Rational Application Developer

By Nitin Raut ([email protected])

Certified Consulting IT Specialist

IBM Corporation

April 2010

Skill Level: Intermediate

Consuming Services in Browser Based Web Applications Page 1

Page 2: Consuming Services in Browser Based Web Applications using IBM

Consuming Services in Browser Based Web Applications JSF Web Service Client

In this lab you we will use Find Flights Web Service created earlier to create a JavaServer Faces Web Service Client.

• What you should be able to do: o At the end of the lab, you should be able to:

Create Faces JSP with Web Services Components Use various JavaServer Faces components Test the JavaServer Faces Application in WebSphere Application Server

Test Environment.

• Introduction o The steps in this lab are:

Explore Web Service Create JavaServer Faces JSPs with web services components Test JavaServer Faces Application in WebSphere Application Server Test

Environment. • Skill Prerequisites

o Prerequisite skills for this lab are:

Understanding of Java programming language concepts and beginner Java programming skills

Page 2 Consuming Services in Browser Based Web Applications

Page 3: Consuming Services in Browser Based Web Applications using IBM

Required Material o Client system requirements:

IBM Rational Developer for Power Systems (RDp) V7.5

o Lab information sheet:

Variable Description Demonet IBM i

<team_number> Team Number 99

<IBMi> IBM i hostname iseriesd.demos.ibm.com

<IBMi_userid> IBM i user ID SOADEMO

<IBMi_password> IBM i password demo4you

<app_lib> Application library FLGHT400

<app_lib_modules> Application Library - Modules FLGHT400M

<workspace> Workspace C:\PoT\SOAiV75\workspace

<team_dir_local> Team directory local C:\PoT\SOAiV75\teamxx

Consuming Services in Browser Based Web Applications Page 3

Page 4: Consuming Services in Browser Based Web Applications using IBM

1.1 Review WSDL document

__1. Type following URL in Internet Explorer and press Enter.

__a. If you running web service in WebSphere Application Server Test Environment in Rational Developer for Power Systems (RDp)

http://localhost:9081/FSxxService/services/FINDFLIGHTSServices/wsdl/FINDFLIGHTSServices.wsdl

(Replace appropriate values from lab information sheet)

OR

__b. If you are using web service on IBM i in demonet demo environment:

http://iseriesd.demos.ibm.com:59900/FS99Service/wsdl/FINDFLIGHTSServices.wsdl

Tip: These URLs are stored in wsdl_doc_url.txt file in \<team_dir_local>\JSFWebServiceClient_lab directory.

Page 4 Consuming Services in Browser Based Web Applications

Page 5: Consuming Services in Browser Based Web Applications using IBM

__2. You should see WSDL document listed in browser. It shows different methods implemented within the web service with the input and output parameters. E.g. In our example we have 2 methods:

findFlights and findFlights_XML This method has are 3 input parameters: FROMCITY, TOCITY and FLIGHTDATE

5 output parameters : FROMCITY, TOCITY, FLIGHTDATE, FLIGHTCOUNT, FLIGHTS

__3. Scroll down to look at the FLIGHTS structure definition

Consuming Services in Browser Based Web Applications Page 5

Page 6: Consuming Services in Browser Based Web Applications using IBM

__4. Scroll down to look for other details like Web Service name and end point

We will be using this WSDL document to build the JSF Web Service Client to consume the web service.

__5. If you are using web service deployed on System i on Demonet demo environment then you could test it with Test Client deployed on that server. Please enter following URL in the browser:

http://iseriesd.dfw.ibm.com:59900/FS99ServiceClient/sampleFINDFLIGHTSServicesProxy/TestClient.jsp

Page 6 Consuming Services in Browser Based Web Applications

Page 7: Consuming Services in Browser Based Web Applications using IBM

__6. Click on findflights or findflights_XML method and enter following input field values and click Invoke. You should see results in the result pane.

Consuming Services in Browser Based Web Applications Page 7

Page 8: Consuming Services in Browser Based Web Applications using IBM

1.2 Start Rational Developer for Power Systems (RDp)

Skip to next section if ….

You are already in Rational Developer for Power Systems and you have started WebSphere Application Server Test Environment

Start Rational Developer for Power Systems (RDp)

__1. Go to Start => All Programs => IBM Software Development Platform => IBM Rational Developer for Power Systems Software V7.5 => IBM Rational Developer for Power Systems Software

__2. In the workplace launcher window, enter <workspace> (shown by default) in the workspace field and press OK. (Please make sure that Use this as a default and do not ask again is NOT checked). Note: if not prompted for the workspace go to the next step.

Important! Please make sure that Use this as a default and do not ask again is NOT checked

__3. On the Welcome page. Click X to close or press Workbench icon.

Page 8 Consuming Services in Browser Based Web Applications

Page 9: Consuming Services in Browser Based Web Applications using IBM

Start WebSphere Application Server Test Environment

Start WebSphere Application Server Test Environment This is very important before invoking the web services wizard, as the wizard will fail.

__4. In current perspective (Remote System Explorer by default). Select Window => Open Perspective => Other. Select Web Perspective and click OK.

__5. In the Web Perspective, click on Servers tab (bottom of screen). Select WebSphere Application Server 7.0 and press Start button.

__6. You should see console view with startup messages. Once WebSphere Application Server is started you will see Server view with status “Started”.

Consuming Services in Browser Based Web Applications Page 9

Page 10: Consuming Services in Browser Based Web Applications using IBM

__7. Another way to make sure WebSphere Application Server Test Environment is started is to see the console view with message “Server server1 open for e-business”.

Troubleshooting If the WebSphere Application Server Test Environment does not start. Please check server connection type and admin port. To check configuration, double click on WebSphere Application Server 7.0 under server view. You may manually provide the connections settings and select SOAP connector port instead of RMI port which is more compatible with firewalls. Click on X and save the configuration when prompted.

Page 10 Consuming Services in Browser Based Web Applications

Page 11: Consuming Services in Browser Based Web Applications using IBM

1.3 Create a Web Project

Open Web Perspective

__1. Go to Window => Open Perspective => Other. In the Open Perspective window, select Web and click OK.

Create a Web Project

__2. Create a Web project: Select File => New => Dynamic Web Project

Consuming Services in Browser Based Web Applications Page 11

Page 12: Consuming Services in Browser Based Web Applications using IBM

__3. In New Dynamic Project windows,

Enter Project Name: FSxxClient (where xx is your team number)

Select Target Runtime : WebSphere Application Server V7.0

Select Configuration : Java Server Faces IBM Enhanced Project (Since we will be creating JSF pages, this adds IBM Enhanced faces support to the project)

Enter EAR Project Name : FSxxClientEAR (where xx is your team number)

click Next.

__4. On Configure web module settings window, it allows you to change the context root and other parameters for the project. Click Next.

__5. On JSF Capabilities window, you can configure JSF libraries, JSF Configuration file etc. Click Finish.

Page 12 Consuming Services in Browser Based Web Applications

Page 13: Consuming Services in Browser Based Web Applications using IBM

__6. Under Project Explorer Expand Dynamic Web Projects => FSxxClient project => Click on WebContent folder.

Create a Faces JSPs

__7. From the menu bar, go to File -> New -> Web Page

Consuming Services in Browser Based Web Applications Page 13

Page 14: Consuming Services in Browser Based Web Applications using IBM

__8. In the New Web Page window,

Enter File Name : FSJSFClient Make sure JSP under Basic Templates is selected

Click Finish.

__9. Type heading Flights Search Web Service Client and press Enter.

Page 14 Consuming Services in Browser Based Web Applications

Page 15: Consuming Services in Browser Based Web Applications using IBM

__10. Select text “Flights Search Web Service Client” by pressing SHIFT+ARROW key on the keyboard and click on the Properties view at the bottom.

Consuming Services in Browser Based Web Applications Page 15

Page 16: Consuming Services in Browser Based Web Applications using IBM

__11. The properties view allows you change the properties for the selected component in the edit window. Select Heading 1 in paragraph field. You may also change the color and the font.

Page 16 Consuming Services in Browser Based Web Applications

Page 17: Consuming Services in Browser Based Web Applications using IBM

__12. Press down arrow to keep the cursor below the heading. In the Palette view, expand Data and Services drawer.

__13. In the Palette View, select Web service under Data and Services and drop it onto the JSF page at the cursor position.

Consuming Services in Browser Based Web Applications Page 17

Page 18: Consuming Services in Browser Based Web Applications using IBM

__14. In Add Web Service dialog, click Add under select a service box.

__15. Web services discovery dialog is displayed. Click the Web Services from a known URL link. Also, you can search for web services deployed and running in your current workspace.

Page 18 Consuming Services in Browser Based Web Applications

Page 19: Consuming Services in Browser Based Web Applications using IBM

__16. Enter following URL and click Go.

__a. If you running web service in WebSphere Application Server Test Environment in Rational Developer for Power Systems (RDp)

http://localhost:9081/FSxxService/services/FINDFLIGHTSServices/wsdl/FINDFLIGHTSServices.wsdl

OR

__b. If you are using web service deployed on IBM i in Demonet demo environment:

http://iseriesd.dfw.ibm.com:59900/FS99Service/wsdl/FINDFLIGHTSServices.wsdl

Tip: Copy the URL from the browser window which was used in the previous step.

__17. You will see web services details with port information. To explore the web service click Details.

Consuming Services in Browser Based Web Applications Page 19

Page 20: Consuming Services in Browser Based Web Applications using IBM

__18. This will launch Web Services Explorer in the browser. You will see the methods and end point information. Click findFlights to test that method.

Enter FLIGHTDATE: 09122010 (Cannot be today’s date)

Enter TOCITY: Atlanta

Enter FROMCITY: Albany

Click Go. You should see 9 flights returned in the status pane.

__19. You may also test findflights_XML method which returns XML document.

Page 20 Consuming Services in Browser Based Web Applications

Page 21: Consuming Services in Browser Based Web Applications using IBM

__20. To look at the SOAP Messages (Request Envelope and Response Envelope), click on Source link in the Status pane.

__21. Close the Web Services Explorer browser window.

Consuming Services in Browser Based Web Applications Page 21

Page 22: Consuming Services in Browser Based Web Applications using IBM

__22. Back in Web Service Discovery dialog, click Add to Project.

__23. In Add web service window, Select the findFlights() method on the Web services wizard page. Click Next.

Page 22 Consuming Services in Browser Based Web Applications

Page 23: Consuming Services in Browser Based Web Applications using IBM

__24. On the Input form page, it shows the input fields which will be placed on the Input form. Select the fields and change the sequence as below. Click Options.

__25. In the Options dialog, change the label for Submit button to Search Flights and click OK.

__26. Back in Input Form window, click Next.

Consuming Services in Browser Based Web Applications Page 23

Page 24: Consuming Services in Browser Based Web Applications using IBM

__27. In Result form window, it shows the fields to display.

Remove the check mark next to FROMCITY, TOCITY and FLIGHTDATE fields.

Place FLIGHTCOUNT field before FLIGHTS field by using the arrow key button on the left.

Click Finish.

__28. JSF Web services wizard generates input and output fields on the JSF page.

__29. Save you work by going to File -> Save from the menu bar or by pressing CTRL+S on the keyboard.

Page 24 Consuming Services in Browser Based Web Applications

Page 25: Consuming Services in Browser Based Web Applications using IBM

Change Input and Result form

__30. Update labels next to the input fields to make them more readable. You may also select the text and change the properties like format, font, color etc. in properties view.

Consuming Services in Browser Based Web Applications Page 25

Page 26: Consuming Services in Browser Based Web Applications using IBM

__31. Update the labels on the output table. Select the column heading and change the value in the properties view.

__32. Save you work by going to File -> Save from the menu bar or by pressing CTRL+S on the keyboard.

__33. Click on ‘X’ to close FSJSFClient edit window.

Page 26 Consuming Services in Browser Based Web Applications

Page 27: Consuming Services in Browser Based Web Applications using IBM

1.4 Test JavaServer Faces Application in WebSphere Application Server Test Environment In this step, we will run the Application in WebSphere Application Server Test Environment..

__1. In the Project Explorer view, under FSxxClient => WebContent node, right click on FSJSFClient.jsp and select Run -> Run on Server option.

Consuming Services in Browser Based Web Applications Page 27

Page 28: Consuming Services in Browser Based Web Applications using IBM

__2. In the Server selection window, choose an existing server and select WebSphere Application Server V7.0 under localhost and click Finish.

__3. After a while, you should see a browser displaying the FSJSFClient page with input form.

Double click Web Browser window title to expand the window. Enter following inputs:

From City: Albany

To City: Atlanta

Date: 09122010 (Cannot be today’s date)

Click Search Flights.

__4. Double click on the Web Browser window title to go back to original size.

Congratulations!!! You have completed this lab.

Page 28 Consuming Services in Browser Based Web Applications

Page 29: Consuming Services in Browser Based Web Applications using IBM

Notices © Copyright IBM Corporation 1992, 2009 All rights reserved.

U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP

Schedule Contract with IBM Corp.

This information was developed for products and services offered in the U.S.A. IBM may not offer the

products, services, or features discussed in this documentation in other countries. Consult your local IBM

representative for information on the products and services currently available in your area. Any

reference to an IBM product, program, or service is not intended to state or imply that only that IBM

product, program, or service may be used. Any functionally equivalent product, program, or service that does not infringe any IBM intellectual property right may be used instead. However, it is the user’s

responsibility to evaluate and verify the operation of any non-IBM product, program, or service.

IBM may have patents or pending patent applications covering subject matter described in this

documentation. The furnishing of this documentation does not give you any license to these patents. You can send license inquiries, in writing, to:

IBM Director of Licensing IBM Corporation

North Castle Drive

Armonk, NY 10504-1785 U.S.A.

For license inquiries regarding double-byte (DBCS) information, contact the IBM Intellectual Property

Department in your country or send inquiries, in writing, to:

IBM World Trade Asia Corporation

Licensing

2-31 Roppongi 3-chome, Minato-ku Tokyo 106, Japan

The following paragraph does not apply to the United Kingdom or any other country where such

provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION

PROVIDES THIS PUBLICATION ″AS IS″ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR

IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF

NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some

states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this

statement may not apply to you.

This information could include technical inaccuracies or typographical errors. Changes are periodically

made to the information herein; these changes will be incorporated in new editions of the publication.

IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this

publication at any time without notice.

Consuming Services in Browser Based Web Applications Page 29

Page 30: Consuming Services in Browser Based Web Applications using IBM

Any references in this information to non-IBM Web sites are provided for convenience only and do not in any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of the materials for this IBM product and use of those Web sites is at your own risk.

Licensees of this program who wish to have information about it for the purpose of enabling: (i) the

exchange of information between independently created programs and other programs (including this

one) and (ii) the mutual use of the information which has been exchanged, should contact:

Intellectual Property Dept. for WebS phere Software IBM Corporation

3600 Steeles Ave. East

Markham, Ontario

Canada L3R 9Z7

Such information may be available, subject to appropriate terms and conditions, including in some cases,

payment of a fee.

The licensed program described in this documentation and all licensed material available for it are

provided by IBM under terms of the IBM Customer Agreement, IBM International Program License

Agreement or any equivalent agreement between us.

Any performance data contained herein was determined in a controlled environment. Therefore, the

results obtained in other operating environments may vary significantly. Some measurements may have

been made on development-level systems and there is no guarantee that these measurements will be the

same on generally available systems. Furthermore, some measurements may have been estimated through

extrapolation. Actual results may vary. Users of this document should verify the applicable data for their

specific environment.

Information concerning non-IBM products was obtained from the suppliers of those products, their

published announcements or other publicly available sources. IBM has not tested those products and

cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM

products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of

those products.

All statements regarding IBM’s future direction or intent are subject to change or withdrawal without

notice, and represent goals and objectives only.

Copyright license

This information contains sample application programs in source language, which illustrates

programming techniques on various operating platforms. You may copy, modify, and distribute these

sample programs in any form without payment to IBM, for the purposes of developing, using, marketing or distributing application programs conforming to the application programming interface for the operating platform for which the sample programs are written. These examples have not been thoroughly tested under all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.

Each copy or any portion of these sample programs or any derivative work, must include a copyright

notice as follows:

© (your company name) (year). Portions of this code are derived from IBM Corp. Sample Programs. ©

Copyright IBM Corp. 1992, 2009. All rights reserved

Page 30 Consuming Services in Browser Based Web Applications

Page 31: Consuming Services in Browser Based Web Applications using IBM

Consuming Services in Browser Based Web Applications Page 31

Trademarks and service marks

The following terms are trademarks or registered trademarks of International Business Machines

Corporation in the United States, other countries, or both.

• i5/OS • IBM • OS/400 • Rational • WebSphere

Microsoft, Windows, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both.

Other company, product or service names may be trademarks or service marks of others.