Skip to main content

skip to main content

developerWorks  >  Rational | SOA and Web services  >

Creating and Consuming Web Services Using IBM Rational Business Developer (EGL)

developerWorks
Go to the previous pagePage 6 of 9 Go to the next page

Document options
PDF format - Fits A4 and Letter

PDF - Fits A4 and Letter
3428 KB (9 pages)

Get Adobe® Reader®


My developerWorks needs you!

Connect to your technical community


Rate this tutorial

Help us improve this content


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,

  1. Right click WebContent, and select New > Web Page, as shown in Figure 42.

Figure 42. Create a new Web page
menu command
  1. In the New Web Page dialog that displays (Figure 43):
    1. Specify the file name as moviePage.jsp.
    2. Pick any template under Sample Templates > Family A (no navigation) > A_green.htpl
    3. Clear the Link page to template option.
    4. Click the Finish button.

Figure 43. Select name, location, and template for a new Web page
Template in tree view on left, Preview on right

The page will now be created and open in the content view.

  1. Add Let’s Go To The Movies as header text after the heading.
  1. Press the Enter key twice, to add some blank lines on the page, as shown in Figure 44.

Figure 44. Content view
graphic and text
  1. Right-click anywhere on the page and select Edit Page Code, as shown in Figure 45.

Figure 45. Edit the code
menu command
  1. The JSF Page Handler for moviePage.jsp opens in the content area (Figure 46).
    1. Add 3 variables
      • zipCode string;
      • radius int;
      • theaters Theater?[0];
    2. 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.
    3. Also, specify that theaters is a dynamic array by specifying the square brackets [0]. The zero indicates that the array initially has zero elements.
    4. Add a function with the name findmovies().

Figure 46. Modify the code
code listing

In this function, you will invoke the GetTheatersAndMovies Web service, 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.

  1. Inside the findMovies function:
    1. Add the movieInformationSoap variable (use content assist for the type and the attribute).
    2. Add the one assignment statement (use content assist to create the statement).
    3. Save the moviePage.egl Page Handler file.
    4. Fix any problems that display.
  1. Then after the page handler source is error free:
    1. Click the moviePage.jsp tab at the top of the content area to return to the page designer view.
    2. Save the file to refresh and synchronize the tools.

Add controls to the Web page

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,

  1. Press the control button and select:
    • the radius variable
    • the zipCode variable,
    • the findMovies function.
  1. With all three items selected, drag them onto the page, as shown in Figure 47.

Figure 47. Drop to insert new controls
drag from tree view to content area
  1. In the Configure Data Controls dialog that displays (Figure 48):
    1. Select Updating an existing record, which will cause an input field to be created.
    2. Click Options.
  1. Because you have your own button to add, you don’t need the default buttons, so clear the boxes next to Submit Button and Delete Button.
  2. Click the OK button, then the Finish button.

Figure 48. Specify columns to display and how to display them
Options dialog on top of Insert Control dialog
  1. Specify the same exact things when the next window displays. The page should now look like that shown in Figure 49.

Figure 49. Updated content view
Radius and ZipCode fields with findMovies button
  1. To add the output fields that are returned from the service, drag theaters onto the page underneath the findMovies button, as shown in Figure 50.

Figure 50. Add output fields
drag from lower left to uppder right
  1. In the window that displays, select Displaying an existing record (read-only).


Back to top


Configure the array

Because the theaters record contains the Movies variable (which is an array), you need to specify how this array should look like on the page.

  1. To do this, click the ellipsis next to Multi-Column Data in the Movies (Movie[]) row, as shown in Figure 51.

Figure 51. Configure Data Controls
radio button options and check box columns
  1. The same window displays, but with different Columns to display.
    1. Select Displaying an existing record (read-only)
    2. Click the Finish.
  1. You will now be focused on the previous window where you clicked the ellipsis, Click the Finish button there as well.
  1. Your page should now look like that shown in Figure 52.

Figure 52. Updated page
Content view with output fields


Back to top


Add the application to the server

  1. At the bottom of the workbench in the server view:
    1. Right click the server
    2. Select Add and Remove Programs, as shown in Figure 53.

Figure 53. Add a project to the server
menu command
  1. Select Lab7WebServiceEAR from Available projects.
  2. Press the Add button to add it to Configured projects, as shown in Figure 54.
  3. Click Finish.

Figure 54. Add and Remove Projects dialog
Select from left and add to right
  1. Back in page designer, right-click anywhere on the moviePagepage,jsp and select Run on Server, as shown in Figure 55.

Figure 55. Run on server
menu command

The Web page appears in the build in the workbench browser.

  1. Enter a ZIP code (27518 is Raleigh, NC if you don’t know a valid ZIP code).
  2. Enter a distance in miles for the radius to be used (for example 10).
  3. You should see a couple of movie theaters in the region of your ZIP code and the movies they are playing today, as shown in Figure 56.

Figure 56. Query results
theater and movies

Most likely, you’ll be interested in something other than the movies playing today in your 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 in Rational Business Developer.

What you have done so far

You have now generated code from a third party WSDL and created a Web page to test it, using Rational Business Developer. You also coded EGL business logic to run your page.

Going forward, you can use the skills you learned in this tutorial, and you can start implementing SOA-based applications written in EGL.



Back to top



Go to the previous pagePage 6 of 9 Go to the next page