Learn how IBM® Informix® 4GL functions can be deployed as Web services. Get an overview of a user interface (UI) tool called 'w4gl' and a back-end tool called 'w4glc' that is in-turn used by the 'w4gl'.

Share:

Srinivasan R. Mottupalli, Senior Software Engineer, IBM

Srinivasan MottupalliSrinivasan R. Mottupalli is a senior software engineer at IBM, ISL, Bangalore. He has worked on IDS, Extended Parallel Server (XPS), and Informix 4GL (I4GL) as a design and development engineer.



Gagan Maheshwari (gagmahes@in.ibm.com), Technical Lead, IBM

Gagan Maheshwari photoGagan Maheshwari is a technical lead at IBM. He has worked on IDS and Informix 4GL (I4GL) as a design and development engineer.



Vishwas T. Mahadevaiah (vishmaha@in.ibm.com), Software Engineer, IBM

Vishwas MahadevaiahVishwas T Mahadevaiah has worked in the IBM-IDS team as a software engineer for one and a half years. Vishwas was involved in implementing UTF8 and SOA support for Informix 4GL. He is also involved in DRDA-related releases.



12 February 2009

Also available in Chinese Japanese Spanish

Informix 4GL

Informix 4GL, or simply I4GL, supports a programming language for interacting with the Informix database servers. It provides a rich environment with forms and reports language for easy development of relational database applications. I4GL supports compilers that can convert the 4GL applications to C language as well as to the machine-independent p-codes that can later be executed using runner. For more information on 4GL, refer to the 4GL Reference Manual.


Web services and Service-Oriented Architecture (SOA)

Service-Oriented Architecture (SOA) is an architectural style that provides methods for systems development and integration, allowing different applications to exchange data with one another. It aims at loose coupling of services with operating systems, their programming languages, and other technologies with underlying applications. Web services are sellable functions that can be accessed independent of platforms and programming languages. These functions take a set of inputs and return a set of outputs to accomplish a specific task. For example, when credit card validation service is provided by various a third party, each use of such Web service incurs some cost to be paid by the consumer. SOA makes it less cumbersome for companies to simply link their business processes to their suppliers, vendors, and other business partners.


I4GL in an SOA environment

Using Informix 4GL's rich language support, it is easy to implement the user interface and the business logic that might involve embedding the SQL statements to access the database objects. Many Informix customers are using I4GL as their front-end tool to write the database applications. These applications contain both the interactive aspects as well as the business logic. Such business logic can be commonly used by many other applications. SOA complements the design of I4GL to deploy its function as Web services.

Figure 1 gives an architectural overview of I4GL-SOA.

Figure 1. Architectural overview of I4GL-SOA
Architectural overview of I4GL-SOA

I4GL is designed in such a way that a 4GL application can be converted into C programs that in turn can be linked with other C program. Similarly, I4GL functions can be called from any C application with the help of the APIs. This flexibility opens up an opportunity for 4GL functions to deploy or consume Web services through the Apache's AXIS2 C Web service API.

In order to consume or deploy 4GL functions as Web services, I4GL provides an interactive tool called 'w4gl' that collects the necessary inputs from the user and records them in the database. It will then pass the necessary information to a non-interactive tool called 'w4glc', which is a PERL script that can perform the requested operations. Since the tool maintains the database to store the information collected with W4GL, it's also possible to regenerate the services for deployment or consumption as needed.

I4GL as a service provider

Given the 4GL function that is to be deployed as a Web service, W4GL automatically generates the required skeletons, headers, and wrapper files that are required. You have to provide the Web service specification using a configuration file.


Architecture of 4GL-SOA

Figure 2 shows the architecture of the 4GL in an SOA environment. The user interface w4gl's responsibility is to accept the Web service definitions from the user and generate the configuration file. The back-end PERL script "w4glc" will refer this configuration file, generate the code, and provide the environment to deploy or consume the Web service, as instructed by the configuration file.

Figure 2. 4GL SOA architecture
4GL SOA architecture

Prerequisites

  • Informix 4GL 7.50.xC2 (Currently supported only on Linux® platform. This limitation is mainly due to the unavailability of AXIS2C on other platforms.)
  • JRE 1.4.2 or later
  • AXIS2C 1.5 (Bundled with 4GL 7.50.xC2 and later.)
  • PERL tool
  • IDS 9 or later (XPS should also be able to support this.)

Program design database

Program design database is not new to I4GL. This database contains some special tables used by the I4GL tool.

The same database is also used by the W4GL tool to store its special tables. These tables contain the user inputs from w4gl with respect to the Web services and its definitions, and stores them in the tables for any future generation.

By default, the name of the program design database is "syspgm4gl". However, the required database name can be supplied through the environment variable called PROGRAM_DESIGN_DBS. The name specified by this environment variable has higher precedence. The database design is given below.

For example:

 export PROGRAM_DESIGN_DBS=mydb
Figure 3. Program design database
Program design database

Configuration file

Configuration file contains the specifications of a particular Web service. This is used by the w4glc tool to generate the code and to perform the requested tasks, such as deployment or packaging.

This configuration file is generated by the W4GL tool (with extension .4cf), and the parameters in this configuration file are populated by reading the program design database (see the sample configuration file in Listing 1).

All these parameter values are populated through the W4GL tool before generating the configuration file. Upon request to deploy, this configuration file is passed to the PERL script (w4glc) to deploy the given 4GL function as a Web service.

Having these data persistent in the program design database enables you to regenerate the configuration file whenever you need and to redeploy as necessary. This is particularly useful during the maintenance of the Web server.

Listing 1 shows a sample configuration file created by W4GL.

Listing 1. Configuration file
[SERVICE]
     TYPE=publisher
     INFORMIXDIR=/tools_4xpm/sqldist
     DATABASE=i4glsoa
     CLIENT_LOCALE=en_us.utf8
     DB_LOCALE=en_us.utf8
     I4GLVERSION=7.50.xC2
     WSHOME=/work/axisdist
     WSVERSION=AXIS2C
     TMPDIR= /tmp/w4gl
     PORTNO= 9090
     INFORMIXSERVER = ids_11.50
     INFORMIXSQLHOSTS = /work/env/sqlhosts
     SERVICENAME= ws_visa_valid
     [FUNCTION]
          NAME= validate_visa_card
          INPUT= CHAR(16), CHAR(5), CHAR(3)
          OUTPUT= CHAR(8)
     [END-FUNCTION]
     [DIRECTORY]
          NAME= /work/4glApp
          FILE= visaverify.4gl
     [END-DIRECTORY]
[END-SERVICE]

Let's take a look at the parameters in the configuration file:

  • [SERVICE] … [END-SERVICE]: This block contains all the parameters to deploy a single function as Web service.
  • TYPE: Determines the type of operation — 'publisher' or 'consumer'.
  • DATABASE: Name of the database that the 4GL function might have used.
  • I4GLVERSION: The version of 4GL, for auditing.
  • WSHOME: Path of the Web service installation directory.
  • WSVERSION: Version of the Web server, for auditing.
  • TMPDIR: Temporary work directory to keep the generated intermediate files.
  • PORTNO: Port number to which the axis server listens to.
  • SERVICENAME: Represents the name of the service to be published.
  • [FUNCTION] … [END-FUNCTION]: A block containing details of function that is being deployed.
    • NAME: Name of the 4GL function.
    • INPUT: Data types of the input arguments to this 4GL function; must have one-to-one correspondence from left to right, and must match the count of arguments, as in the function definition.
    • OUTPUT: Data types of result returned from this 4GL function; must have one-to-one correspondence from left to right, and must match the count of arguments, as in the function definition.
  • [DIRECTORY] … [END-DIRECTORY]: A block containing the list of files that needs to be compiled and their objects that have to be bundled for the Web service deployment.
    • NAME: Absolute directory path where the source file (4gl, C, or ESQL/C files) is present.
    • FILE: Name of the file(s) (4gl, C, or ESQL/C files) present under the above directory.
  • CLIENT_LOCALE: Represents locale for the 4GL.
  • DB_LOCALE: Represents locale for the database.
  • INFORMIXSERVER: Name of the Informix Server.
  • INFORMIXSQLHOSTS: Absolute path of the Informix sqlhosts file.

PERL script

The Perl script (w4glc) located in the $INFORMIXDIR/bin directory is the worker behind the scenes of W4GL tool. It is a non-interactive program. It can also be independently used if one can write his own configuration file. However, it is recommended to populate the program design database and generate the configuration file using the W4GL tool so that the same configuration files can be regenerated and redeployed in case of any loss or migration of the deployed Web services.

Listing 2. Syntax
w4glc { [-help] [-version] | [-silent] [-force] [-check] [-generate]
[-compile] [-deploy] [-package] } <cfgfile>

Note: w4glc may have additional options that are related to consumption. Those options are beyond the scope of this article.

  • silent - The silent option suppresses all the messages from the compiler.
  • force - This option forces when there are any existing files or directories that can be silently reused.
  • check - This option performs the basic sanity checking on the supplied configuration file. The checks ensure the existence of the source file(s) and directory, and that the environment is set properly.
  • generate - This option generates the code (deployment or consumption) and depends on the TYPE supplied in the configuration file. These files are needed to support the proposed Web service.
  • compile – This option makes the compilation of all the generated files and creates object files. It also generates the shared object that can be readily deployed.
  • deploy – This option copies the objects and other files necessary to the Web services directory. The Web server, when restarted, will refer to this directory and recognize the newly deployed Web service.
  • package – This option permits you to prepare materials on a development machine for later deployment on a production machine. The files are packaged into a compressed tar file (either gzip or bzip2) or into a zip file so that the material can be copied to a new machine.

W4GL tool

The W4GL tool is written using Informix 4GL. This tool helps manage data within the program design database. It also provides options to package the Web service so that the service can be taken to another machine (provided it is of same configuration and platform). The idea is, since the data is available in the database, the same service can be generated for various platforms using W4GL on those respective platforms.

Figure 4. Hierarchical menu layout of W4GL tool
Hierarchical menu layout of W4GL tool

Populating Web service information

The W4GL interactive tool allows you to populate the Web service information into the database. It also provides the interface to generate configuration files and deploy them as a Web service. Before adding a Web service, you must add the host name of an application server and the application server on which the service needs to be deployed.

Adding a host name

You need to add the host name where the application server is running and where the service needs to be deployed, as shown in Listing 3. The host name can be a DNS name or an IP address. You also need to provide the absolute path of the temporary directory where the intermediate files of the Web service will be created. Upon pressing escape key (Esc), to commit the changes, the machine id is automatically generated.

Listing 3. Adding a host name
+------------------------------------------------------------------------------+
|HOST NAME:   Query  Next  Previous  Add  Modify  Remove  Exit                 |
|See existing Host name details.                                               |
|--------------------------------[ syspgm4gl ]-------------------[Help: CTRL-W]|
|                                                                              |
|                              HOST INFORMATION                                |
|                                                                              |
| Machine ID           [          3]                                           |
| Host Name            [service.server.test.com                    ]           |
| Temporary Directory  [/tmp/w4gl                                          ]   |
|                      [                                                   ]   |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
| A new host name was added.                                                   |
+------------------------------------------------------------------------------+

Adding an application server

The application server details must also be populated with the appropriate environment and the host name that was added earlier where the app-server is running.

Adding a Web service

Listing 4 illustrates the addition of a new Web service called "ws_visa_valid". This screen takes all the necessary information about the Web service, such as the name of the 4GL function that needs to be deployed as a Web service, its input parameters, output parameters, and the files that this 4GL function depends on. Upon giving all the details, the exit option prompts you to either save or discard the changes.

Listing 4. Adding a Web service
+------------------------------------------------------------------------------+
|ADD:   Detail  Input  Output  File  Exit                                      |
|Add the files associated with this web service.                               |
|--------------------------------[ syspgm4gl ]-------------------[Help: CTRL-W]|
| Service ID       [    2]                                                     |
| Service Name     [ws_visa_valid                                            ] |
| Function Name    [validate_visa_card                                       ] |
| Notes            [                                                         ] |
|                  [                                                         ] |
|                  [                                                         ] |
|                  [                                                         ] |
| [ 3] Input parameters                 [ 1] Output parameters                 |
| [ 1][CHAR(16)                        ][ 1][CHAR(8)                         ] |
| [ 2][CHAR(5)                         ][  ][                                ] |
| [ 3][CHAR(3)                         ][  ][                                ] |
| [  ][                                ][  ][                                ] |
| [  ][                                ][  ][                                ] |
| [  ][                                ][  ][                                ] |
| [  ][                                ][  ][                                ] |
| [  ][                                ][  ][                                ] |
|                                                                              |
| 1 output parameters added.                                                   |
+------------------------------------------------------------------------------+

This example added a Web service named "ws_visa_valid" with three input parameters and one output parameter.


Generating the configuration file

After adding the Web service information, you need to generate the configuration file in order to deploy the Web service. All these details can be retrieved by activating a pop-up window.

Listing 5. Generate configuration file
+------------------------------------------------------------------------------+
|INSTALL:   Generate  Deploy  Package  Exit                                    |
|Generate the configuration file for a web service.                            |
|--------------------------------[ syspgm4gl ]-------------------[Help: CTRL-W]|
|                                                                              |
|                           GENERATE CONFIGURATION                             |
|                                                                              |
| Service ID [   2]   Machine ID [   3]   Server ID [   0]  Database ID [   1] |
|                                                                              |
| Service Name    [ws_visa_valid                                             ] |
| Host Name       [service.server.test.com                                   ] |
| Temp Directory  [/tmp/w4gl                                                 ] |
|                 [                                                          ] |
| App-Server Name [axis_server                                               ] |
| Port Number     [  9090]                                                     |
| Database Name   [i4glsoa                                                   ] |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
| Ctrl+B = List of Web services. Press Esc to Accept or Ctrl+C to Cancel.      |
+------------------------------------------------------------------------------+

Deploying the 4GL function

After setting up all the master details, the Web service information, and the generation of a configuration file, the deploy option allows you to deploy the required Web service.

Use the configuration file generated earlier to deploy the Web service, as shown in Listing 6.

Listing 6. Deploying a Web service
+------------------------------------------------------------------------------+
|INSTALL:   Generate  Deploy  Package Exit                                     |
|Deploy the web service.                                                       |
+------------------------------------------------------------------------------+
|                                                                              |
|                     CONFIGURATION TO DEPLOY                                  |
|                                                                              |
| File Name [ws_visa_valid_ service.server.test.com.4cf           ]            |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
| Configuration file ws_visa_valid_ service.server.test.com.4cf deployed       |
|                                                                              |
+------------------------------------------------------------------------------+

After each deployment, the Web service needs to be restarted so that the new deployed service will be available for consumption from other applications.


Consuming the deployed 4GL function as a Web service

The deployed Web service can be consumed from any application written in other languages, such as Java™, C, PHP, and other modern languages. 4GL 7.50.xC2 comes with a demonstration program "i4glsoademo", which uses a C interface to consume the Web service. After setting the environment, invoke the "i4glsoademo" program that passes a zip code and retrieves the corresponding city and state from the 4GL function deployed as a Web service.


Packaging a Web service

The packaging option helps you to migrate your Web services to different hosts of the same operating system and configuration. It takes the Web service name and packages it to a shippable file.

Listing 7. Packaging a Web service
+------------------------------------------------------------------------------+
|INSTALL:  Generate   Deploy   Package   Exit                                  |
|Package the web service.                                                      |
+------------------------------------------------------------------------------+
|                                                                              |
|                     SERVICE NAME TO PACKAGE                                  |
|                                                                              |
| Service Name [ws_visa_valid                                        ]         |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
| The web service has been successfully packaged.                              |
|                                                                              |
+------------------------------------------------------------------------------+

Stored procedures as Web services

Enablement of the 4GL function as a Web service also opened up a possibility to consume the stored procedures as a Web service using the 4GL functions. Listing 8 provides an example.

Listing 8. Stored procedure
CREATE FUNCTION  LOG10(val  INTEGER)
     DEFINE retval DECIMAL(16,10);

     CALL SPL_LOGN(val, 10) RETURNING retval;

     RETURN retval;
END FUNCTION

Limitations

  • Currently available only on the Linux platform, but is expected to be available on other platforms.
  • Complex data types supported in 4GL are not yet supported to deploy as a service. For example, RECORD and BLOB.

Conclusion

Utilizing the existing 4GL functions as Web services opens up many possibilities for making use of them in any modern language. Existing Informix 4GL customers continue to enjoy the ease of coding using 4GL, yet make them available to the language of their choice to support their Web applications by accessing these Web services. Consumption of Web services from within the 4GL code is another way to leverage the existing Web services that might have been coded in other languages.

Resources

Learn

Get products and technologies

  • Build your next development project with IBM trial software, available for download directly from developerWorks.

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Information management on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management, SOA and web services
ArticleID=369408
ArticleTitle=Deploy 4GL functions as Web services
publish-date=02122009