50
EGL Introduction IBM Toronto Lab IBM Rational Developer for System i for SOA Construction Version 7.1 Enterprise Generation Language (EGL) Creating and consuming Web Services Student Exercises Course code 51LC to 56LC Session Id 430247 520212 Tuesday, November 01, 2022 © COPYRIGHT IBM Corporation 2008 Page 1

EGL_V7.1_LAB_Web_Services.doc.doc

  • Upload
    zubin67

  • View
    795

  • Download
    0

Embed Size (px)

Citation preview

Page 1: EGL_V7.1_LAB_Web_Services.doc.doc

EGL Introduction IBM Toronto Lab

IBM Rational Developer for System i for SOA ConstructionVersion 7.1

Enterprise Generation Language (EGL) Creating and consuming Web Services

Student Exercises

Course code 51LC to 56LC Session Id 430247 520212

RDI SOA V7.1

Claus Weiss [email protected]

IBM Toronto Laboratory

Wednesday, April 12, 2023 © COPYRIGHT IBM Corporation 2008 Page 1

Page 2: EGL_V7.1_LAB_Web_Services.doc.doc

EGL Introduction IBM Toronto Lab

First Edition (March 2008)

The information contained in this document has not been submitted to any formal IBM test and is distributed on an "as is" basis without any warranty either express or implied. The use of this information or the implementation of any of these techniques is a customer responsibility and depends on the customer's ability to evaluate and integrate them into the customer's operational environment. While each item may have been reviewed by IBM for accuracy in a specific situation, there is no guarantee that the same or similar results will result elsewhere. Customers attempting to adapt these techniques to their own environments do so at their own risk.

Comments concerning this notebook and its usefulness for its intended purpose are welcome. You may send written comments to:

IBM Canada Software Solutions

8200 Warden Ave., Markham, Ontario, L6G 1C7

Attention: Claus Weiss, EGL introduction.

or email to: [email protected]

Copyright International Business Machines Corporation 2008 All rights reserved.

This material may not be reproduced in whole or in part without the prior written permission of IBM.

Note to U.S. Government Users - Documentation related to restricted rights - Use, duplication or disclosure is subject to restrictions

set forth in GSA ADP Schedule Contract with IBM Corp.

Wednesday, April 12, 2023 © COPYRIGHT IBM Corporation 2008 Page 2

Page 3: EGL_V7.1_LAB_Web_Services.doc.doc

EGL Introduction IBM Toronto Lab

Overall Lab Guide

The objective of this EGL lab is to have the students work with an EGL application that will be used as a Service and to use an existing Web Service in an EGL application. The lab is intended to allow hands on experience using the RDI SOA workbench with Rational Business Developer. It shows how easy it is to use Web Services in EGL regardless whether they are created in EGL as a Service or used in EGL applications. The first exercise creates an EGL application that can then be used as a Web Service. The second exercise uses an existing Web Service showing movies playing in US theaters and creates an EGL application that displays the data delivered from this Web Service.

It is assumed that the student is familiar with basic Windows UI operations such as working with the desktop and basic mouse operations such as opening folders and performing drag-and-drop operations. Experience with an Eclipse based workbench like WebSphere Development Studio Client (WDSC), Rational Developer for System i (RDI), or Rational Application Developer (RAD) is an asset but is not necessary.

The lab will have very detailed instructions on how to proceed. All students can finish the Lab on their own pace.

Note: The pictures in these labs show a similar application being built. Some of the names and icons may be different than the environment you are working with.

Wednesday, April 12, 2023 © COPYRIGHT IBM Corporation 2008 Page 3

Page 4: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Table of ContentsUsing Web Services in EGL................................................................................................5

The finished applications will contain the following web pages and capabilities.........................5Section 1 – Creating EGL Web Services.......................................................................................7

Creating the application.......................................................................................................8First Steps.......................................................................................................................................8Create an EGL web project..........................................................................................................10Section 2 – Consuming a 3rd Party Web Service..........................................................................23Create a new EGL Web project...................................................................................................24

Lab 7 Page 4

Page 5: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Using Web Services in EGL

This document provides basic procedures for creating and consuming web Services in EGL

The finished applications will contain the following web pages and capabilities

In the first section of this Lab, you will create an EGL web service and then test the service using the Web Service Explorer. The service will check for valid California zip codes.

Using the Web Service Explorer you will generate a very simple UI for testing the Service. It contains one input field to enter the zip code and will show a return code of 0 or -1 determined by your EGL service depending whether the zip code is a valid California code.

Here is the UI that gets generated by the Web Service Explorer to test the EGL Web Service.

In the second section of this Lab you will access an existing Web Service. The Service returns movies playing in a certain area of the US. It expects a postal code and a radius as input and will return a list of movie theaters in the area.

Lab 7 Page 5

Page 6: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Here is the UI that you will create with EGL

Now you know what you have to build in this Lab.

Let’s get started, just follow the detailed instruction in this lab script and you will learn how easy it is to write an EGL data access application.

Lab 7 Page 6

Page 7: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Creating and consuming Web Services with EGL EGL implements 2 categories of services:

EGL Service – a type of service for applications written entirely in EGL. EGL Web Service – a type of service that is created using EGL, but can be

accessed from both EGL and non-EGL clients.

This lab will show how to implement the creation and consuming of web services with EGL. Services differ from traditional monolithic programs in that they are modular, and conform to a formal specification for their data input/output (calling) mechanism. In so doing they become more useful building blocks for applications, with artifacts that can be easily deployed to different run-times, and are far easier to maintain and reuse.

These services can be developed with many different technologies and languages. However, it is useful to see what EGL and the Rational tools bring to the table as far as building, testing and deploying services. There are two broad categories of services which we will cover:

1. EGL Web Service – a type of service that is created using EGL, but can be accessed from both EGL and non-EGL clients

2. A non-EGL Web Service that can be called by an EGL client using an interface part created from the non-EGL service’s WSDL specification.

Overview of development tasks

1. In Section I we will build an EGL Web Service. At the end of this section you should be able to test the web services that you have created and deployed to WebSphere Application Server V6.1.

2. In Section II you will consume a 3rd party web service (not written in EGL). You will create an EGL client that will execute this web service that exists on the web.

Section 1 – Creating EGL Web Services

The steps you will perform in this section are:1. Configure a project for Web Services: You will create a project and set it’s

properties to allow Web Service development and testing.a. Specify Workspace Capabilitiesb. Specify Web Service-specific build options

2. Define an EGL Web Service: Here you will create a new EGL Service file.3. Code the Web Service Business Logic: In the EGL Service file you create, you will

add EGL functions and variables (statements), that perform the service (e.g. business logic) required by your application.

4. Generate the Web Service interactively: You will then test your Web Service interactively using the Web Service Explorer tools.

Lab 7 Page 7

Page 8: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Lab 7 Page 8

Page 9: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Creating the application

First Steps

You need to start the RDI SOA workbench and select a workspace that will contain all the files you use for your development project. You will use a new workspace so your environment fits the environment we used when we created this script.

Start RDI SOA V 7.1

Click Start All programs IBM Software Development Platform IBM Rational Business Developer for System i IBM Rational Business Developer for System i

When prompted for a workspace name

Enter a new name, like in the figure above, so you get a brand new workspace

Tip: Don’t worry about the directory path, accept the default, just specify a unique directory for the workspace.

Click OK

Lab 7 Page 9

Page 10: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

The workbench will show:

Click the x on the Welcome tab, to remove the Welcome page.

Lab 7 Page 10

Page 11: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Create an EGL web project

In the RDI SOA workbench you will be using the Web perspective with all the views and editors needed to work with a web application.

Switch to the Web perspective by:

Clicking on the open perspective icon on top right hand side of the workbench Selecting the Other… action from the context(pop up) menu

The Open Perspective dialog shows:

Select Web from the tree in the Open Perspective dialog

Now you are ready to create new EGL project.

Lab 7 Page 11

Page 12: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

On the the workbench menu, Click File New Other “

The Select a wizard dialog appears

:

Expand the EGL node Select EGL Project Click Next

Lab 7 Page 12

Page 13: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Name the project LAB71_Service.radio button Be sure to select the Web Project Click the Next button

Now you have a chance to modify the default EGL web project settings.

Be sure to select Create new project build descriptor You can leave the Show Advanced Settings checkbox unselected. Click the Finish button

Lab 7 Page 13

Page 14: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Now you need to create the logic for this service, that is supposed to run when somebody invokes this serviceTo do this you need to create a file that contains the EGL logic and you need to name this file and place it into a package. You will use the New EGL Service Part wizard to achieve this task.

Expand the new Lab71Service project Right click over the EGLSource folder and select: New Service

Enter the package name: services Enter the source file name: zipService. Click the Finish button

Lab 7 Page 14

Page 15: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Now you will create some logic in this source file to provide the functionality for this service. The service is very simple; it checks a zip code entry whether it is a valid California zip code. Exactly, the logic checks that the input parameter value is between 90001 and 96000.

Add the following source code to zipService which opened in the editor view:

Save and generate the service by pressing Ctrl/S, then Ctrl/G.

To describe this service to the EGL environment you need to add it in an EGL Deployment descriptor file, which has been created already during project creation.

In Project Explorer

Lab 7 Page 15

package services;

// serviceservice zipService

function caTestbk(zipIn char(5) in) returns(int)if(zipIn >= "90001" && zipIn <= "96000")

return(0);else

return(-1);end

endend

Page 16: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Expand directory EGL Source Locate the Lab71Service.egldd file (not the eglbld file which is the build descriptor) Double click on the egldd file to open it in the editor.

You will notice, there are five tabs at the bottom:

Click the Web Service Deployment tab,

Lab 7 Page 16

Page 17: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Click Add, in the window that pops up.

Select the zipService in the EGL service parts found list Click ADD. The service is moved to the EGL service parts to be generated as web services list. Click Finish, Save and close the DeploymentDescriptor file.

The deployment descriptor has been added automatically to the build file .eglbd. This is necessary to make the Deployment descriptor known to the EGL build environment. You might want to check the Build descriptor:

In the EGL source directory find the LAB71_Service.eglbld file Open the file with the source editor by double clicking on it.

Lab 7 Page 17

Page 18: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

You notice that the deployment descriptor Lab71Service is already listed under options. Close the editor.Now you need to re-generate the project so EGL can take this new information and apply it to the generated application.

Right-click over the project LAB7_Service and click generate.

The generate action generates the complete Web Service including the WSDL file.The WSDL is a standard file format that describes a web service. You can hand over this WSDL file to people that want to use your Web Service. It describes the Service interface, the location of the service and other characteristics of the service.

Lab 7 Page 18

Page 19: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

The WSDL (commonly pronounced as “Wis Dul”) can be opened in the WSDL editor. The file is located in the project in WebContent\WEB-INF\wsdl\.Here is a sample how the WSDL editor presents our WSDL file

Feel free to double click the WSDL file and have a look.

What have you done so far?

You have now created an EGL Project and defined an EGL Web Service. You’ve also added an entry in the deployment descriptor so the service will be generated as a web service!

Test the Web Service – Interactively

First let’s make sure that the server is running.

Click on the Servers tab to select it Right click over WebSphere Application Server v6.1 Click Start in the context menu.

Lab 7 Page 19

Page 20: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Once the server has started (this may take several minutes), the console will show “Server server1 open for e-business” and the Servers tab will reflect started under the Status column.

Now you must add the project to the Server

Right click over WebSphere Application Server v6.1 Click Add and Remove Projects…on the context menuThe Add and Remove dialog will appear:

Lab 7 Page 20

Page 21: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

In the Available Projects list Select LAB71_Web_ServiceEAR Click Add >

The project will be moved to the right side of the window under Configured Projects Click Finish.

The Server will have to reconfigure itself, be patient!! Once it is finished (the console stops scrolling) you will be ready to test your service!

RDI SOA offers a nifty interactive Web Services test facility called the Web Services Explorer! You can use this tool to test your Web Service functionality effectively, before embedding calls to it from your service client! To start the Web Services Explorer go in the Project Explorer

Expand project Lab71Service Expand directory WebContent Expand directory WEB-INF Expand directory wsdl Right click on zipService.wsdl Select WebServices Test with Web Services Explorer

The Web Services Explorer will appear in the browser in the Content Area.

Lab 7 Page 21

Page 22: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Expand zipServiceBinding Click on the caTestbk method which is the service you are going to test.In the Actions dialog Enter a valid California zip code 93000 Click GoOn the bottom Status dialog you will see the result from the Web Service

You will get a return value of zero

Try the same with an input value of 99999 and the return value will be -1. These results are being expected since this is how you coded the service.

What have you done so far?

Lab 7 Page 22

Page 23: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

You have now created a “Web” service and tested it using the Web Services Explorer.

You can now install the EAR file on your production server and change the WSDL file to reflect the new location of the service and give the WDSL to potential user of the service. This will allow these folks to create applications easily that use this service.

In the next section we show you how to take a WSDL and create an EGL application that uses the service described in the WSDL.

Lab 7 Page 23

Page 24: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Section 2 – Consuming a 3rd Party Web Service

The steps we will perform in this section are:1. Get a third party WSDL file from the internet.2. Generate Web Service and Client bindings.

a. This will generate code that will allow you to access the functions defined in the WSDL.

3. Test the 3rd party web service by creating a web page.Let’s get started by finding a service and it’s WSDL file.

Find the Service

You can speed up this process by using the WSDL we provide on your disk and proceed to heading: Create an EGL Web Project.

We are now going to consume a 3rd party web service. To do this you must have a working internet connection! Point your browser to www.xmethods.net.

On the homepage, click [View the Full List].

Lab 7 Page 24

Page 25: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

1. Find Ignyte’s Retrieve Theaters and Movie Showtimes and click on the link.

Right-click on the link in the row labeled WSDL and select Save Link As.

Save the file to your C:\ drive. Make sure to select “All Files” as the file type and save the file as a dot wsdl.

Now that you have a WSDL that describes a service that provides information about movies played in a certain area of the United States, you can write an EGL application that displays the data provided by this service.

Create a new EGL Web project

In the RDI SOA workbench in the web perspective

Select File New Project EGL EGL project

Lab 7 Page 25

Page 26: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Name it Lab7_Web_Service Make sure Web Project is selected. Click Next>

Make sure WAS 6.1 is the selected target runtime. Click Finish

On the next page Now you need to create a services package, this package will contain the service information that EGL will extract from the WSDL file, it will also contain the WSDL file itself.

Lab 7 Page 26

Page 27: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Right-click over the EGL Source folder Select New EGL Package

Enter the Package name: services Click FinishNow you need to copy the wsdl file, that you downloaded before, into this package

In Windows Explorer, expand the C: drive

Lab 7 Page 27

Page 28: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Right mouse click over the moviefunction.wsdl on the C:\ drive Select copy Now in the RDI SOA workbench Right-click over the services package under the LAB7_Web_Service project and

select Paste.

If you pasted the WSDL in the correct location, it should have now appear in the services folder

Now you are ready to extract the services information from the WSDL file.

Lab 7 Page 28

Page 29: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Go back to the services package Right-click over the moviefunctions.wsdl file Select EGL Services Create EGL Client Interface from the context menus

In the upcoming dialog

Click Next>

Lab 7 Page 29

Page 30: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Here you could de-select the function GetUpComingMovies since we are only interested in the function GetTheatersandMovies, but leave the default.

Click Next> You are now at the New EGL Web Client Binding view.

The Lab7_WebService deployment descriptor is the default to add the binding to, accept the defaults.

Click Finish

Lab 7 Page 30

Page 31: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

An interface to a 3rd Party Web Service is created, you can now use this service and reference it in (call from) your EGL client business logic. This EGL source file containing the interface information of this service will be opened in the content area. It is called moviefunctions.egl and is contained in the com.ignyte.www package.With all service information now available you need to re-generate the project so EGL can take this new information into consideration for this project.

Right click over the project and click Generate.After the generation is finishied.

Create a Web Page Using the Service

Let’s now create a web page that utilizes this external service. From the LAB7_Web_Service project,

Lab 7 Page 31

Page 32: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Right click over WebContent, and select New Web Page.

In the dialog that pops up,

Specify the file name as moviePage.jsp. Pick any template under Sample Templates Family A (no navigation)

A_green.htpl Uncheck Link page to template. Click Finish.

The page will now be created and open in the content view. Add some header text as follows:

Lab 7 Page 32

Page 33: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

After the heading Let’s Go To The Movies Click the Enter key twice, to add some blank lines on the page Right-click anywhere within the page and select Edit Page Code.

The JSF Page Handler for moviePage.jsp is now open in the content area

Change code according to the next picture:

Lab 7 Page 33

Page 34: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Add 3 variables zipCode, radius, theaters.

We suggest to use content assist (ctrl + spacebar) when specifying the data type for the variable theaters this will add the import statement automatically to this EGL page handler file. Also specify that theaters is a dynamic array by specifying the square brackets [0], the zero indicates that the array initially has zero elements. Add a function with the name findmovies()

In this function you will invoke the web service GetTheatersAndMovies which is defined in the moviefunctions.egl source that got created for you. First you have to declare a variable that points to the interface description MovieInformationSoap for this web service which is contained in moviefunctions.egl.

Inside the findMovies function: Add variable movieInformationSoap use content assist for the type and the

attribute. Add the one assignment statement, use content assist to create the statement Save the Page Handler file moviePage.egl. Fix any problems that get displayed

Lab 7 Page 34

Page 35: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Then after the page handler source is error free

Click the moviePage.jsp tab at the top of the content area to return to the page designer view.

Save the file to refresh/synchronize the tools.

You now need to fill the web page with controls,You need two input fields for specifying which zip code area the theaters should be selected from and what the radius should be that you are interested in. You also need a button on the page to invoke the search for movie theaters (your findMovies function). From the Page Data view at the left bottom side of the workbench,

Press/hold the control button and select the variables radius zipCode, and the function findMovies.

Lab 7 Page 35

Page 36: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

With all three items selected, drag them onto the page.

In the window that pops up

Select ¤ Updating an existing record, which will cause an input field to be created.

Click Options Since you have your own button to add you don’t need the default buttons, so:

Uncheck the boxes next to Submit Button and Delete Button, Click Finish.

Specify the same exact things when the next window pops up.

The page should now look as follows:

Lab 7 Page 36

Page 37: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

To add the output fields that are returned from the service:

Drag theaters onto the page underneath the findMovies button.

In the window that pops up,

Lab 7 Page 37

Page 38: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Select ¤ Displaying an existing record (read-only). Since the theaters record contains the variable Movies, which is an array, you will have to specify how this array should look like on the page, to do this: Click the ellipsis next to Multi-Column Data in the Movies (Movie[]) row.

The same window will pop up but with different Columns to display. Select ¤ Displaying an existing record (read-only) Click Finish.

You will now be focused on the previous window where you clicked the ellipsis, Press Finish there as well.

Your page should now look as follows:

Lab 7 Page 38

Page 39: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Add the application to the server

At the bottom of the workbench in the server view

Right click on the server Select Add and Remove Programs

Lab 7 Page 39

Page 40: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Select the Lab7WebServiceEAR Press the Add> button, to add it to the Configured projects Click Finish

Back in page designer

Lab 7 Page 40

Page 41: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

Right-click anywhere on the moviePagepage,jsp Select Run on Server…

The web page appears in the build in the workbench browser

Enter a zip code, 27518 is Raleigh, NC if you don’t know a valid zip code Enter a distance in miles for the radius to be used for example 10 .

Lab 7 Page 41

Page 42: EGL_V7.1_LAB_Web_Services.doc.doc

RBDe V 7 POT IBM

You should see a couple of movie theaters in the region of your zip code and the movies they are playing today.Most likely you’ll be interested in something else the movies playing today in you business application, but this could be any web service. You now know how to access web services from EGL and can use this in your own business applications.

What have you done so far?

You have now generated code from a third party WSDL and created a web page to test it! You also coded EGL business logic to run your page.

Congratulations, we hope you can make use of the skills you learned in this Lab and now you can start implementing SOA based applications written in EGL

Lab 7 Page 42