Using the PHP SOAP Extension to Access the Adabas SOA Gateway

Page created by Ruth Duran
 
CONTINUE READING
Technical Article

Using the PHP SOAP Extension to Access the Adabas SOA
Gateway
By Stephen Wild
Technical Marketing Manager, Software AG Germany
January 2006

                                                          •
With PHP and the Adabas SOA Gateway you can                   SOAP (Simple Object Access Protocol), which
                                                              specifies messages flowing between a client and
dynamically generate Web pages from data stored in            server. The messages are formatted in XML.
Adabas. This article shows you how to install and             SOAP is independent of the platform,
configure the PHP SOAP extension on Windows®.                 programming language, network, and transport
Also, you'll gain an understanding of the PHP                 layer. This article discusses using SOAP over
scripting language by learning how to connect to,             HTTP.
insert data into, and select data from an Adabas
database using the SOA Gateway.                           •   WSDL (Web Services Description Language),
                                                              which is an XML-based language for describing a
Please note that all code samples contained within            Web service, including its location, formats,
this article are available for download on the                operations, parameters, and data types.
Developer Community forum for the Adabas SOA
Gateway.                                                  •   UDDI (Universal Description, Discovery and
                                                              Integration), which provides a way to store and
                                                              retrieve information about Web services in the
What is PHP?
                                                              network, using APIs and a UDDI Registry
Hypertext Preprocessor, PHP, is a popular server-             implementation.
side scripting language for creating dynamic Web
content. The PHP interpreter is available as source       This article includes examples of SOAP messages
code or as pre-compiled binaries for major platforms,     and WSDL documents, but not UDDI.
including most Linux™ distributions, Windows®, Mac
OS X, and iSeries™.
                                                          SOAP and PHP
The latest release is PHP 5 and it is seeing increasing   New in PHP 5 is a built-in SOAP extension. It is
adoption. PHP 5 introduces improvements to the            supplied as part of PHP, so you don't have to
object model; also, the underlying memory                 download, install, and manage a separate package. It
management has been redesigned with multi-                is the first SOAP implementation for PHP to be written
threading and performance in mind.                        in C, rather than in PHP, and the authors claim that it
                                                          is significantly faster as a consequence.
What are Web Service Technologies?
                                                          Installing the PHP SOAP Extension
The concept of Web services is to enable self-
contained, modular applications, where the client and     You should have PHP 5 up and running in your Web
the service are loosely coupled. For this article,        server, see the install.txt document in the PHP
though, you'll need to know a little about the major      distribution library (C:\php) for details. I did my
technologies:                                             experimentation with PHP 5.1.1 and Apache 2.0.55
                                                          on Windows XP Professional, which were the latest
                                                          releases at the time, and installed PHP as an Apache
1 of 5
Using PHP to Access Adabas SOA Gateway

module. The soap extension is shipped as part of
PHP 5, so you don't need to download anything extra,     Once you have installed the plug-in you can configure
but you may have to make some changes to enable          it via “Window -> Preferences” and then selecting
it. Which changes you need to make depend on             “PHPeclipse Web Development”. Another useful item
whether you downloaded the source code and               is to select “Window -> Show view” and select “PHP
compiled PHP yourself, or downloaded binaries.           Browser”. This opens a browser view in Eclipse and
                                                         saves you the bother of opening a separate browser
•   If you downloaded the PHP source code and            window.
    compiled it for your platform, you will probably
    need to rebuild, because ext/soap is not enabled     The Adabas SOA Gateway
    by default. Repeat your previous build process,      You can install and configure your own version of the
    adding the --enable-soap option to the configure     Adabas SOA Gateway, but I did my experimentation
    command.                                             using the version which is publicly available on the
                                                         Software AG web-site at http://193.26.193.104:8082.
•   If you downloaded pre-compiled platform              This server provides views of the standard
    binaries, they may have ext/soap compiled in but     “Employees” and “Vehicles” files. The Employees
    not loaded, so you'll need to update your PHP        service I used is described by the
    configuration to load ext/soap. Edit your php.ini,   adabas/Employees?WSDL.
    and look for the Dynamic Extensions section.
    Here you'll need to add a line that causes the
                                                         Create a PHP Project in Eclipse
    extension to be loaded automatically.
                                                         I did my development in Eclipse and my first step was
    On Windows, this will be:                            to create a new source folder and PHP project to
    extension=php_soap.dll                               contain all the source files. Do this by selecting the
                                                         PHP Perspective and then “New -> Project” in the
    On UNIX:                                             Navigator pane and select “PHP project”. Give the
    extension=php_soap.so                                project a name and unselect the “Use default” box.
                                                         Browse to the default location of your Apache html
    And if you haven't previously loaded any optional    documents, in my case this was C:\Program
    extensions, you may also have to set the             Files\Apache Group\Apache2\htdocs and create a
    extension_dir directive to point to the              new folder “MyPHP”.
    directory containing the extension libraries,
    including php_soap, for example:                     You are now ready to create your first PHP script.
                                                         Select “New -> PHP file” in the Navigator pane and
    extension_dir="C:/php/ext/"                          give it an appropriate name.
    (use forward slashes even on Windows)
                                                         Application Overview
    Don't try to put directory information in the        The diagram below gives an overview of the structure
    extension directive; use extension_dir if            of the client application we will construct; although
    necessary.                                           this is a classic three-tier application, in our model two
                                                         of the tiers live on the local machine.
Installing the PHP Eclipse Plug-in
I did my development using the PHP Eclipse plug-in,      In practice the Apache Web-Server would more likely
this is not absolutely necessary but using Eclipse       live on either a separate middle tier machine or even
does make development life very simple. You can          on the same machine as the Adabas SOA Gateway
install the Eclipse plug-in by simply adding the PHP     server.
Eclipse plug-in update site
(http://download.pipestone.com/eclipse/updates/) to      For performance reasons the SOA Gateway and the
the Eclipse configuration manager and following the      Adabas database server itself should reside on the
instructions.                                            same machine.
2 of 5
Using PHP to Access Adabas SOA Gateway

                    Local machine                                 Remote Machine

         Browser

                                                         Adabas SOA
                                                         Gateway

                           Apache and
                           PHP                                                 Adabas
                                                                               Database

Create the PHP SOAP Client                                Now we have instantiated our client we want to see
The soap class we'll use to represent the Adabas          what methods it provides and what parameters are
Service is the SoapClient. We know that our               required. We can do this by studying the WSDL
application server is serving up the WSDL at              directly, but this can prove to be a bit tedious.
http://193.26.193.104:8082/adabas/Employees?WSD           Fortunately we can get PHP and the instantiated
L, so we can create our first SoapClient by looking up    SoapClient class to do most of the work for us:
the WSDL file:
                                                            $functions = $soapclient->__getFunctions();
 $soapclient = new SoapClient(                              print_r($functions);
 "http://193.26.193.104:8082/adabas/Employees?WSDL");

                                                          If you run this as a console application (via “Run”) the
                                                          output is much better formatted than running it in the
                                                          PHP browser. You should see the following:

  Array
  (
      [0]   =>   adabasEmployeesElementType list(adabasEmployeeKeyType $adabasEmployeeListKey)
      [1]   =>   adabasEmployeesElementType get(adabasEmployeePrimaryKeyType $adabasEmployeeGetKey)
      [2]   =>   operationResult delete(adabasEmployeePrimaryKeyType $adabasEmployeeDeleteKey)
      [3]   =>   operationResult add(adabasEmployeesType $adabasEmployees)
      [4]   =>   operationResult update(adabasEmployeesType $adabasEmployeesUpdate)
  )

3 of 5
Using PHP to Access Adabas SOA Gateway

This tells us that the service described by the WSDL
provides five operations; list, get, delete, add and
update; it also tells us the required parameters and
the responses given.

We can also get a description of the input and output
parameters by calling the __getTypes class:

 $types = $soapclient->__getTypes();
 print_r($types);

The output displayed is :

 Array
 (
     [0] => struct adabasEmployeesElementType {
  adabasEmployeesType adabasEmployees;
 }
     [1] => struct adabasEmployeesType {
  adabasEmployeeType adabasEmployee;
 }
     [3] => struct adabasEmployeeType {
  string personnel_id;
  string first_name;
  string middle_name;
  string name;
  string mar_stat;
  string sex;
  string address_line;
  string city;
  string zip;
  string country;
  string area_code;
  string phone;
  string dept;
  string job_title;
  income income;
  string leave_due;
  string leave_taken;
  leave_booked leave_booked;
  string lang;
 }
     [6] => struct adabasEmployeePrimaryKeyType {
  string personnel_id;
 }
     [7] => struct adabasEmployeeKeyType {
  string personnel_id;
  string name;
  string city;
  string dept;
  string job_title;
  string lang;
 }
 )

4 of 5
Using PHP to Access Adabas SOA Gateway

Using this information we can construct our first                               Note here though that the input array is a selection
simple call to the “get” operation.                                             list:

First, we need to construct an array of the required                               $AdabasEmployeeGetKey = array ('personnel_id'=> null,
input parameters:                                                                                 'name' => null,
                                                                                                  'city' => "DARMSTADT",
                                                                                                  'dept' => null,
  $AdabasEmployeeGetKey = array ('personnel_id'=>                                                 'job_title' => null,
  50005500);                                                                                      'lang' => null,
                                                                                                  );

And then invoke the operation as a method of the
soapclient class:
                                                                                The call is similar:
  $Adabasresponse = $soapclient-
  >get($AdabasEmployeeGetKey);                                                     $Adabasresponse = $soapclient->list($AdabasEmployeeGetKey);

Now it is just a matter of taking the returned object                           But the returned object is an array of employee
and outputting the required results in a table:                                 elements:

                                                                                   $EmployeesArray = $Adabasresponse->adabasEmployees-
  $Employee = $Adabasresponse->adabasEmployees-
                                                                                   >adabasEmployee;
  >adabasEmployee;

  echo "";
  echo "Personnel                                                       Set up the table and loop through the array of
  IDNameCityJob                                      elements printing out the information required:
  Title";
  echo "",                                                                     echo "";
     "$Employee->personnel_id",                                           echo "Personnel
     "$Employee->first_name $Employee->name",                             IDNameCityJob Title";
     "$Employee->city",
     "$Employee->job_title",                                              foreach ($EmployeesArray as $adabasEmployee)
     "";                                                                      {
  echo "";                                                                    echo "",
                                                                                      "$adabasEmployee->personnel_id",
                                                                                      "$adabasEmployee->first_name $adabasEmployee-
Run this in the built in PHP Browser or an external                                >name",
browser: http://localhost/MyPHP/PHPASG_get.php                                        "$adabasEmployee->city",
                                                                                      "$adabasEmployee->job_title",
In a similar fashion we can construct an invocation of                                "";
the “list” operation:                                                              }
                                                                                   echo "";
  $soapclient = new SoapClient(
  "http://193.26.193.104:8082/adabas/Employees?WSDL");

                                                                                                                   Software AG
                                                                                                                   Corporate Headquarters
                                                                                                                   Uhlandstraße 12.
                                                                                                                   D-64297 Darmstadt/Germany
                                                                                                                   T: +49-61 51-92-0
5 of 5   Copyright © Software AG and/or its suppliers, Uhlandstraße 12, D-64297 Darmstadt, Germany.
         All rights reserved.
                                                                                                                   www.softwareag.com
         Software AG and/or all Software AG products are either trademarks or registered trademarks
         of Software AG. Other products and company names mentioned herein may be the trademarks
         of their respective owners.
You can also read