< Previous | Next >

Lesson 1: Create an EGL web project for the service

EGL projects can act as services, as clients, or as both simultaneously. For this tutorial, you will create two projects: one to act as the service and one to act as the client. While you could put all the code into a single EGL project, using two projects demonstrates how EGL can call services in another application.

  1. Optionally, you may want to use a separate workspace while working on the tutorial so you do not interfere with any of your other projects. If you want to use a different workspace, follow these optional steps:
    1. In the workbench, click File > Switch Workspace. The Workspace Launcher window opens.
    2. Enter a new workspace location in the Workspace field.
    3. Click OK. The workbench reopens using the new workspace location. You can switch workspace locations at any time, and you can have as many workspace locations as you want.
  2. Switch to the web perspective:
    1. Click Window > Open Perspective > Other.
    2. From the list of perspectives, click Web. If you don't see the web perspective, select the Show all check box.
    3. Click OK.
  3. Make sure EGL is set up to automatically generate deployment descriptors. Deployment descriptors contain information that describes how EGL services will be made available to other applications and how EGL applications will find services provided by other applications.
    1. In the workbench, click Window > Preferences... > EGL.
    2. Under Default EGL Project Features Choices, make sure that Create an EGL deployment descriptor is selected. If not, click this field to select it.
    3. Click OK.
  4. In the workbench, click File > New > Project.
  5. In the New Project window, expand EGL and click EGL Project. If you don't see EGL Project, select the Show All Wizards check box. If you still don't see an EGL category or EGL Project, EGL is not installed on your system. Run the product setup again and select the Additional Feature item for EGL.
  6. Click Next.
  7. In the Project name field, give your project this name:
    EGLService
  8. Under EGL Project Types, click Web Project. This type of project allows you to use web page user interfaces.
  9. Click Next.
  10. Under Target Runtime, select a version of WebSphere Application Server.
  11. Make sure that Create a new build descriptor is selected. Build descriptors contain options for generating your program into another language. You do not need to worry about them at this point because the wizard will create an appropriate build descriptor for you. You do not need to use the advanced settings unless you use WAS and you have previously changed the default setting that adds the project to an EAR (Enterprise Application Resource). If you use WAS, your EGLService project must belong to an EAR. The workbench remembers this setting.
  12. You may see a window asking if you want to switch to the J2EE perspective. If you see this window, click No.
The new project appears in the Project Explorer view.
Project Explorer view showing the new project

Create the interface to define the service

EGL uses the term "interface" in the same way as object-oriented languages do. For EGL, an interface defines a plan for a service to follow. Specifically, an interface contains one or more function prototypes, or summaries of functions. These prototypes are not usable functions themselves, but they set out plans for the real functions.
For example, suppose you needed to write an application that performed mathematical operations like a calculator. You might start by listing all of the mathematical operations your application would need (such as addition, subtraction, and multiplication), without actually writing the code to perform these operations. In this case, you would name each operation and specify each operation's input and output parameters, but you would not start coding any logic. In this way, you would be listing the functions that the EGL service application would need in an interface. Such an interface might begin like this:
interface myCalculatorInterface

  //Function to add numbers together 
  function addNumbers(number1 decimal(10,2) in, 
    number2 decimal(10,2) in) returns (decimal(10,2));

  //Function to subtract numbers
  function subtractNumbers(number1 decimal(10,2) in, 
    number2 decimal(10,2) in) returns (decimal(10,2));

end

Then, when you are ready to begin coding the service, you can use this interface both as a starting point and as a test to make sure you are following your plan.

You will rarely be required to write an interface, but in general, using interfaces to describe your services is good programming practice:
  • The interface lets you plan the service ahead of time, and EGL warns you if the service deviates from the interface.
  • Interfaces provide a concise summary of a service, explaining what the service can do without providing all of the details of the service's implementation.
  • Interfaces can serve as requirements for development or compliance.
  1. In the Project Explorer view, right-click your EGLService project to select it.
  2. Click New > Other.
  3. In the New window, expand EGL and click Interface. Make sure you are using the Interface item under EGL and not the Interface item under Java™.
  4. Click Next.
  5. In the New EGL Interface window, make sure that your project's EGLSource folder is shown in the Source folder field. This field should say EGLService\EGLSource.
  6. In the Package field, type this name:
    interfaces
    EGL will create this new package because your project doesn't have a package with this name yet.
  7. In the EGL source file name field, type this name for the new interface:
    HelloInterface
    The New EGL Interface window looks like this:
    The New EGL Interface window
  8. Click Finish. The new interface is created and opens in the EGL editor. This interface contains one function prototype already, as a sample:
    function functionName(parameterName string in) returns (int);
  9. Delete this function prototype.
  10. Where the sample prototype was, insert this code for your own function prototype:
    function SayHello(name string in, city string in) returns (string);
  11. Save and close the file.
Following are some technical details about the code you just entered:
  • As explained above, this is not a complete piece of EGL logic. Instead, this function prototype describes a function that will be in the service. In this case, the prototype describes a function named SayHello.
  • The function accepts two pieces of input from the client, called parameters:
    • A string variable for a person's name
    • A string variable for a city
    The function will use these parameters to put together a piece of output to return to the client.
  • The code returns (string) indicates this return value and its type.

The interface looks like this:

The code of the EGL interface part

Create the service

  1. In the Project Explorer view, right-click your project and then click New > Service.
  2. In the New EGL Service window, make sure that your project's EGLSource folder is shown in the Source folder field. This field should say EGLService\EGLSource.
  3. In the Package field, type this name:
    services
  4. In the EGL source file name field, type this name for the new service:
    HelloService
  5. Next to Interfaces to implement, click Add.
  6. Type an asterisk * in the Choose Interfaces field. Your interface is shown in the Matching parts list.
  7. Click the HelloInterface from the Matching parts list to select it.
  8. Click OK. The interface is now shown in the Interfaces to implement list.
  9. Select the two check boxes to add deployment information to the deployment descriptor file. The New EGL Service window looks like this:
    The New Service wizard
  10. Click Finish. The new service is created and opens in the EGL editor. The service already contains a starter function based on the prototype in the interface.
  11. Remove the comment // TODO Auto-generated function, and in its place, type the following code:
    ReturnString string;
    ReturnString = name::", welcome to "::city::"!";
    return (ReturnString);
    This code creates a string variable and assigns it a value based on the parameters, such as "Jim, welcome to Chicago!" The :: code is a concatenation operator, which joins separate strings into a single string. The code looks like this:
    The code of the EGL service part
  12. Save and close the file.
< Previous | Next >

Feedback