...

Consuming Services in Rich Client Applications using IBM Rational Application Developer

by user

on
Category: Documents
21

views

Report

Comments

Transcript

Consuming Services in Rich Client Applications using IBM Rational Application Developer
Consuming Services in Rich Client 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 Rich Client Applications Scenario
Page 1
Consuming Services in Rich Client Applications
Eclipse RCP is a platform for building and deploying rich client applications. The objective of the
Eclipse Rich Client Platform (RCP) is to enable Eclipse to be used in a wide range of end-user
applications that are not integrated development environments (IDEs). With the release of Eclipse
V3.1, it is easy to create RCP applications. This tutorial will guide you step by step in building
your very own RCP application which consumes an existing web service.
Page 2
EM Sandbox for Power
Rich Client Application
In this lab you will use Java Visual Editor in Rational Application Developer to build a
Rich Client Java application that invokes an RPG Web Service.
•
What you should be able to do:
o At the end of the lab, you should be able to:
• Create an SWT Java Visual Class
• Add a Web service Call
• Test the application
•
Introduction
o The steps in this lab are:
ƒ Create an SWT Java Visual Class
ƒ Create JavaServer Faces JSPs with web services components
ƒ Test the Application
•
Skill Prerequisites
o Prerequisite skills for this lab are:
ƒ Understanding of Java programming language concepts and beginner Java
programming skills
Consuming Services in Rich Client Applications Scenario
Page 3
Required Materials
o Client system requirements:
ƒ IBM Rational Application Developer V7.5
o
Page 4
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
EM Sandbox for Power
1.1
Review WSDL document
__1.
Type following URL in Internet Explorer and press Enter.
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>\RichClient_lab directory.
Consuming Services in Rich Client Applications Scenario
Page 5
__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
Page 6
EM Sandbox for Power
__3.
Scroll down to look at the FLIGHTS structure definition
__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.
Consuming Services in Rich Client Applications Scenario
Page 7
__5.
Let’s test the web service with Test Client deployed on the server. Please enter following
URL in the browser:
http://iseriesd.demos.ibm.com:59900/FS99ServiceClient/sampleFINDFLIGHTSServicesP
roxy/TestClient.jsp
__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.
To city: Albany
From City: Atlanta
Flight date: 09122010
Click Invoke.
Page 8
EM Sandbox for Power
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)
__7.
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
__8.
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)
Important!
Please make sure that Use this as a default and do not ask again is
NOT checked
__9.
On the Welcome page. Click X to close or press Workbench icon.
Consuming Services in Rich Client Applications Scenario
Page 9
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.
__10.
In current perspective (Remote System Explorer by default). Select Window => Open
Perspective => Other. Select Web Perspective and click OK.
__11.
In the Web Perspective, click on Servers tab (bottom of screen). Select WebSphere
Application Server 7.0 and press Start button.
__12.
You should see console view with startup messages. Once WebSphere Application
Server is started you will see Server view with status “Started”.
Page 10
EM Sandbox for Power
__13.
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.
Consuming Services in Rich Client Applications Scenario
Page 11
1.3
Create a Java Project
Open Java Perspective
__14.
Go to Window => Open Perspective => Other. In the Open Perspective window, select
Java and click OK.
Create a Java Project
__15.
Select File => New => Project. In the New Project dialog expand the Java node and
select Java Project and click Next.
__16.
On Create a Java Project screen, Enter Project Name: FSxxRichClient (Where xx is
your <team_number> and click Finish.
Page 12
EM Sandbox for Power
Create Visual Class
__17.
Select the FSxxRichClient project in the Project Explorer. Right mouse click and select
New = > Visual Class
Consuming Services in Rich Client Applications Scenario
Page 13
__18.
In Java Visual Class window, enter following details:
__a. Verify that Source folder is FSxxRichClient/src (where xx is your team number)
__b. Enter Name: Flight400SWTApplication
__c. Enter Package: com.ibm.flight400.swt
__d. Select Style: Expand SWT node and select Shell
__e. Check the public static void main (String[] args) checkbox under Which method
stubs would you like to create?
__f. Click Finish
Page 14
EM Sandbox for Power
__19.
The wizard displays a design pane for developing a Visual class. Notice that there is a
hidden Palette toolbar on the right side of the design pane.
Consuming Services in Rich Client Applications Scenario
Page 15
__20.
Page 16
Next, we will add some GUI components to the Shell (window) generated by the Visual
Class wizard. Click on the left arrow to expand the Palette. Now we can drag and drop
components onto the generated shell.
EM Sandbox for Power
Label Components
__21.
Click Label component (under SWT Controls) from Palette to select it. Move the cursor
(do not drag) and drop in the first cell in the grid as shown below:
__22.
In Bean Name dialog enter: labelFromCity and click OK.
Consuming Services in Rich Client Applications Scenario
Page 17
__23.
In the properties view, change following properties (use button on right of the property to
change it).
__a. text : From City and press enter or click outside that property field
__b. font: Arial, Bold,12
__c. foreground: COLOR_BLUE (or color of your choice)
Page 18
EM Sandbox for Power
__24.
Drop 2 more label components just below From City label (same grid column).
__a. To City label
__i.
Bean Name: labelToCity
__ii.
Text property: To City
__iii. font: Arial, Bold,12
__iv. foreground: COLOR_BLUE (or color of your choice)
__b. Departure date label
__i.
Bean Name: labelDepatureDate
__ii.
Text property: Departure Date
__iii. font: Arial, Bold,12
__iv. foreground: COLOR_BLUE (or color of your choice)
After all the three label components, your shell should like :
Consuming Services in Rich Client Applications Scenario
Page 19
Text Field Component
__25.
Click Text component (under SWT Controls) from Palette to select it. Move the cursor
(do not drag) and drop it in the second cell in the grid (next to From City label) as shown
below:
__26.
In the Bean Name dialog provide name for the bean (Field name): fromCity and click
OK. You may change the font and foreground property in the properties view.
Page 20
EM Sandbox for Power
__27.
Drop 2 more text components just below fromCity text (same grid column).
__a. To City text field
__i.
Bean Name: toCity
__b. Departure date field
__i.
Bean Name: depatureDate
After all the three text components, your shell should like :
Button Component
__28.
Click Button component (under SWT Controls) from Palette to select it. Move the cursor
(do not drag) and drop it in the third cell in the grid (next to fromCity text field) as shown
below:
__29.
In Bean Name dialog enter: buttonSearchFlights and click OK.
Consuming Services in Rich Client Applications Scenario
Page 21
__30.
In the properties view, change following properties:
__a. text : Search Flights and press enter or click outside that property field
__b. font: Arial, 10
Page 22
EM Sandbox for Power
__31.
Expand the size of the shell window to accommodate the button using the guides as
shown below:
__32.
Save your work by clicking on the save icon or File -> Save from menu.
Consuming Services in Rich Client Applications Scenario
Page 23
Test Visual Class
__33.
Let’s test the application to see how the Visual class would look like at run time. In the
Package Explorer expand the FSxxRichClient project and expand
com.ibm.flight400.swt package and right click on Flight400SWTApplication.java and
select Run As -> Java Application.
__34.
Application window is displayed:
__35.
Close the application window. Now let’s add some business logic to the application.
Page 24
EM Sandbox for Power
1.4
Add a Web Service Call
Add Web service proxy code
__1.
Select FSxxRichClient Project. Right mouse click, select New -> Other
__2.
On the New dialog, expand Web Services and select Web Service Client. Click Next.
__3.
In Web Service Client screen, select browse next to Service Definition.
Consuming Services in Rich Client Applications Scenario
Page 25
__4.
In Select Service Implementation screen, paste the WSDL URL from the earlier step:
Review WSDL document and click OK.
http://iseriesd.demos.ibm.com:59900/FS99Service/wsdl/FINDFLIGHTSServices.wsdl
__5.
Back in Web service client screen, click Finish.
__6.
You can view the generated classes in the Package Explorer.
Page 26
EM Sandbox for Power
Add Web service invocation code
__7.
Right click on the Search Flights button, select Events -> widgetSelected,
widgetSelected() is a method that will be invoked when a user clicks the Search Flights
button.
Consuming Services in Rich Client Applications Scenario
Page 27
__8.
Page 28
Code skeleton for processing button click event (called widgetSelected) is generated.
Ignore the syntax error (red cross) for now.
EM Sandbox for Power
__9.
Place a table onto the application window by selecting Table from SWT Controls in the
Palette View and dropping it to the Shell.
__10.
In Bean Name dialog enter: tableFSResults and click OK.
__11.
Save you work by going to File -> Save from the menu bar or by pressing CTRL+S on
the keyboard.
Consuming Services in Rich Client Applications Scenario
Page 29
Add Web service invocation code
__12.
Next, we will add some code that will invoke the Web service. Open
\<team_dir_local>\RichClient_lab\WebServiceInvokation.txt. In this file you will find
import statements that we need to add to the import part of the Java class, and
implementation of the widgetSelected() method. Add import statements to the imports
part of the Java class.
import iseries.wsbeans.findflights.*;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
Page 30
EM Sandbox for Power
__13.
Copy and paste implementation of the widgetSelected() method (replace the existing
implementation). The method calls a Web service and populates a table with results
returned by the Web service.
Consuming Services in Rich Client Applications Scenario
Page 31
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
try{
// Remove previous records
tableFSResults.removeAll();
// Create columns
TableColumn col1 = new TableColumn(tableFSResults,SWT.LEFT);
col1.setText("Flight no");
col1.setWidth(80);
TableColumn col2 = new TableColumn(tableFSResults,SWT.LEFT);
col2.setText("Arrival Time");
col2.setWidth(120);
TableColumn col3 = new TableColumn(tableFSResults,SWT.LEFT);
col3.setText("Arrival City");
col3.setWidth(35);
TableColumn col4 = new TableColumn(tableFSResults,SWT.LEFT);
col4.setText("Departure Time");
col4.setWidth(80);
TableColumn col5 = new TableColumn(tableFSResults,SWT.LEFT);
col5.setText("Departure City");
col5.setWidth(35);
TableColumn col6 = new TableColumn(tableFSResults,SWT.LEFT);
col6.setText("Airline");
col6.setWidth(80);
TableColumn col7 = new TableColumn(tableFSResults,SWT.LEFT);
col7.setText("Price");
col7.setWidth(45);
// Declare flight object
FLIGHTINFO flight = null;
// input parameters
FINDFLIGHTSInput inputData = new FINDFLIGHTSInput();
inputData.setFROMCITY(fromCity.getText());
inputData.setTOCITY(toCity.getText());
inputData.setFLIGHTDATE(departureDate.getText());
// Invoke the Web service
FINDFLIGHTSServicesProxy webService = new FINDFLIGHTSServicesProxy();
FINDFLIGHTSResult result = webService.findflights(inputData);
FLIGHTINFO[] result1 = result.getFLIGHTS();
// Create an array of table rows
//final TableItem[] items = new TableItem[result.getFLIGHTCOUNT()];
final TableItem[] items = new TableItem[50];
//for(int i=0;i<result.length;i++){
for(int i=0;i<50;i++){
flight = result1[i];
items[i] = new TableItem(tableFSResults, SWT.NONE);
items[i].setText(new String[] {flight.getFLIGHT(),
flight.getARRIVETIME(),flight.getARRIVECITY(), flight.getDEPARTTIME(),
flight.getDEPARTCITY(),flight.getAIRLINE(), flight.getPRICE()});
}
tableFSResults.setHeaderVisible(true);
tableFSResults.setLinesVisible(true);
}catch(Exception ex){
ex.printStackTrace();
}
}
__14.
Page 32
Save you work by going to File -> Save from the menu bar or by pressing CTRL+S on
the keyboard. Make sure there are no syntax errors.
EM Sandbox for Power
Expand Application window to accommodate table information.
__15.
Double click on Flight400SWTApplication.java window title to expand it.
__16.
Reduce the code view by using the guides
Consuming Services in Rich Client Applications Scenario
Page 33
__17.
Click on the outside window and use guides to expand the window
__18.
Right click on Table component and select Customize Layout.
Page 34
EM Sandbox for Power
__19.
In Customize Layout :tableFSResults first let’s expand the table field by pressing Grab
excess horizontal space.
__20.
Similarly grab excess vertical space.
Consuming Services in Rich Client Applications Scenario
Page 35
__21.
Page 36
Now fill horizontal and fill vertical to fill the component in the available space.
EM Sandbox for Power
__22.
After both vertical and horizontal expansion, you will see the table field is expanded as
follows:
__23.
Save your work by going to File -> Save from the menu bar or by pressing CTRL+S on
the keyboard.
__24.
Close the Flight400SWTApplication.java view.
Consuming Services in Rich Client Applications Scenario
Page 37
1.5
Run the Application
Run the Rich Client Application.
__25.
Page 38
In Package explorer, select FSxxRichClient Project. Click the Run icon.
EM Sandbox for Power
__26.
In the shell window, enter following inputs:
__a. From City: Albany
__b. To City: Atlanta
__c. Date: 09122010
__d. Click Search Flights.
__e. Results are displayed in a table
__27.
Click X to close the shell window.
Consuming Services in Rich Client Applications Scenario
Page 39
Congratulations!!!
You have completed this lab.
Page 40
EM Sandbox for Power
Notices
© Copyright IBM Corporation 1992, 2010 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 105041785 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, Minatoku 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 Rich Client Applications Scenario
Page 41
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 42
EM Sandbox for Power
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.
Consuming Services in Rich Client Applications Scenario
Page 43
Fly UP