Creating EGL Web services
The steps you will perform in this section are:
-
Configure a project for Web services: Create a project and set its properties to allow Web service development and testing.
-
Specify workspace capabilities
-
Specify Web service-specific build options
-
Define an EGL Web service: Create a new EGL service file.
-
Code the Web service business logic: In the EGL Service file you create, add EGL functions and variables (statements) that perform the service (for example, business logic) required by your application.
-
Generate the Web service interactively: Test your Web service interactively using the Web Service Explorer tools.
You need to start the Rational Developer for System i SOA workbench, and select a workspace that will contain all of the files that you use for your development project.
First Steps
You will use a new workspace so that your environment matches that used when this script was created.
Start Rational Developer for System i SOA V7.1 (or later)
-
Click the Start > All programs > IBM Software Development Platform > IBM Rational Business Developer for System i > IBM Rational Business Developer for System i menu item, as shown in Figure 3.
Figure 3. Start Rational Developer for System i
-
When prompted for a Workspace name, enter a new name, as shown in Figure 4, so that you get a brand new workspace.
Figure 4. Workspace Launcher dialog
Tip: Don’t worry about the directory path: accept the default. Specify a unique directory for the workspace.
-
Click the OK button.
The workbench will look like that shown in Figure 5.
-
Click the x on the Welcome tab, to close the Welcome page.
Figure 5. Close the Welcome tab
Configure an EGL Web project
In the Rational Developer for System i SOA workbench, you will be using the Web perspective with all of the views and editors required to work with a Web application.
-
Switch to the Web perspective: Click the Open Perspective icon on the top right hand side of the workbench.
-
Select Other, as shown in Figure 6.
Figure 6. Switch to the Web perspective
The Open Perspective dialog displays.
-
Select Web from the list of perspectives, as shown in Figure 7.
Figure 7. Open Perspective dialog
You are now ready to create a new EGL project.
-
On the the workbench menu, click File > New > Other, as shown in Figure 8
Figure 8. Create a new project
-
in the Select a wizard dialog that appears (Figure 9).
-
Expand the EGL node.
-
Select EGL Project.
-
Click the Next button.
Figure 9. EGL Project wizard
-
In the New EGL Project (Figure 10):
-
Name the project LAB71_Service.radio button
-
Be sure to select the Web Project
-
Click the Next button
Figure 10. Enter the name and type for the project
Define an EGL Web service
-
Modify the default EGL Web project settings, as shown in Figure 11.
-
Select Create new project build descriptor.
-
Leave the Show Advanced Settings check box. clear.
-
Click the Finish button.
Figure 11. Specify Target Runtime and Build Descriptor Options
Check EGL build file to see if serverType property is defined:
- In Project Explorer, expand Lab71_Service project tree by clicking on the '+' sign.
- Lab71_Service -> EGLSource
- Double click on Lab71_Service.eglbld file
- Check if serverType property is defined as shown below:
Figure 11a. Check serverType property
- If this property is not defined, EGL code generation will fail in subsequent steps.
- To define serverType property do following steps:
- Uncheck Show only specified options check box to display all properties.
Figure 11b. Unchecking checkbox to display properties
- You should see all the properties. Scroll down to locate serverType property.
- Double click in the value field to select the serverType property. Click on the list box to set the property value as shown below:
Figure 11c. Select the serverType property
- Select WEBSPHERE6.X from the list since we will be using WebSphere Application Server V6.1 Test environment to deploy this web service.
Figure 11d. Select WEBSPHERE6.X from the list
- Save the EGL build file by pressing CTRL+S or from menu File -> Save option.
Code business logic
Next, create the service logic, which is supposed to run when somebody invokes this service.
To do this, create a file that contains the EGL logic, name this file, and place it into a package. You will use the New EGL Service Part wizard shown in Figure 12 to achieve this task.
-
Expand the new Lab71Service project
- Right-click the EGLSource folder and select: New > Service
Figure 12. Project Explorer
-
In the New EGL Service Part dialog shown in Figure 13,
-
Enter the Package name:
services.
-
Enter the EGL source file name:
zipService.
-
Click the Finish button.
Figure 13. Set EGL service part options
Next, create some logic in this source file to provide the functionality for this service. The service is very simple: it checks whether or not a ZIP code entry is a valid California ZIP code. Specifically, the logic checks that the input parameter value is between 90001 and 96000.
Add the source code shown in Listing 1 to zipService, which opened in the editor view.
Listing 1. Source to validate ZIP code
package services;
// service
service zipService
function caTestbk(zipIn char(5) in) returns(int)
if(zipIn >= "90001" && zipIn <= "96000")
return(0);
else
return(-1);
end
end
end
-
Save and generate the service by pressing Ctrl+S, then Ctrl+G.
Add service to an EGL file
To describe this service to the EGL environment, you need to add it to an EGL Deployment descriptor file, which has been created already during project creation.
-
do the following in the Project Explorer, as shown in Figure 14.
-
Expand the EGL Source directory.
-
Locate the Lab71Service.egldd file (not the eglbld file, which is the build descriptor).
-
Double-click the egldd file to open it in the editor.
Figure 14. Expand EGLSource in the Project Explorer
You will notice that there are five tabs at the bottom of the EGL Deployment Descriptor Overview dialog shown in Figure 15.
-
Click the Web Service Deployment tab.
Figure 15. Deployment Descriptor bindings, services, protocols, and imports
-
Click Add in the window that displays.
Figure 16. List service parts to generate as Web services
-
In the Add Web Services dialog shown in Figure 17, 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.
Figure 17. Generate to Web services
The Deployment descriptor has been automatically added 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.
-
Double-click the file to open it with the source editor.
Note that the deployment descriptor Lab71Service is already listed under options, as shown in Figure 18.
Figure 18. Build options
-
Close the editor.
Re-generate the project so that EGL can take this new information and apply it to the generated application.
-
Right-click the LAB7_Service project and click Generate, as shown in Figure 19.
Figure 19. Re-generate the project
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.
The WSDL (commonly pronounced "Wis Dul") can be opened in the WSDL editor. The file is located in the project in WebContent\WEB-INF\wsdl\.
Figure 20 provides an example of how the WSDL editor presents your WSDL file.
-
Double-click the WSDL file and look at it.
Figure 20. WSDL editor
 |
What you have done so far
You have now created an EGL Project and defined an EGL Web service. You have also added an entry in the deployment descriptor so that the service will be generated as a Web service.
|
|
|