Skip to main content

skip to main content

developerWorks  >  WebSphere | SOA and Web services  >

Access WebSphere Process Server V6.0 business processes with PHP

developerWorks
Document options

Document options requiring JavaScript are not displayed

Discuss

Sample code


Rate this page

Help us improve this content


Level: Intermediate

Martin Smolny (Martin.Smolny@de.ibm.com), Software engineer, IBM
Marc Schwind (Marc.Schwind@de.ibm.com), Software engineer, IBM

15 Feb 2006

This article shows how to access Business Process Execution Language (BPEL) based applications running in IBM WebSphere Process Server Version 6.0 from a PHP Hypertext Preprocessor (PHP) Server.

Introduction

Business Process Execution Language (BPEL) is an XML-based language for defining business processes. IBM® WebSphere® Process Server contains a service-oriented architecture (SOA) based implementation enabling the execution of business processes specified in BPEL.

PHP is a popular open source scripting language. It is often used for dynamic Web content like Web portals or Web-based client applications. The code is embedded in HTML and interpreted by the server similar to Java™ Server Pages (JSP).

In many companies, the external Web site is developed and maintained by external agencies. In these agencies, PHP is often used to realize interactive features of the Web site, for example, a contact form or a search function. If one of these companies needs to start a business process or interact with one from the external Web site interface, it is faced with the challenge of how to access WebSphere Process Server 6.0 business processes with PHP. This article demonstrates a sample realization and shows circumventions for potential pitfalls.

Prerequisites

You need to install:

  • XAMPP for Linux 1.4.12 or higher as PHP server.
  • IBM WebSphere Process Server 6.0.0 or higher to run business processes.
  • WebSphere Integration Developer 6.0.0 or higher to create the sample business process.

Architecture

The component executing business processes in WebSphere Process Server is implemented using Java and J2EE. Since PHP is mostly written in C, integrating these different platforms becomes a challenge. First, we need to find a way to interface with a business process from PHP. Preferably, a platform independent communication protocol should bridge these different platforms. Web services using the Simple Object Access Protocol (SOAP) provide this functionality.

With WebSphere Process Server, you can install business processes as SOAP Web services. These Web services have an interface defined in Web Service Definition Language (WSDL). Starting with Version 5, PHP contains functions for SOAP; therefore PHP can invoke Web services.

The basic architecture that accesses business processes running in WebSphere Process Server from PHP uses SOAP, as shown in Figure 1.


Figure 1. Business processes running in WebSphere Process Server started from PHP using SOAP
Business processes running in WebSphere Process Server from PHP using SOAP

Implementating the scenario

In this section, you'll learn how to:

  • Create the business process.
  • Add the Web Service Export to the TravelBooking process.
  • Tweak the generated files for PHP interoperability.
  • Export the TravelBooking application as an Enterprise Archive.
  • Install the TravelBooking application.
  • Create the PHP SOAP client.

Creating the business process

A discussion of the BPEL editor in WebSphere Integration Developer is beyond the scope of this article. Therefore, we will use the TravelBooking sample application that is part of the Samples Gallery provided on the Business Process Choreographer Samples Web site for this article. If you are interested in learning how to develop business process-based applications, the Business Process Choreographer Samples Web site is a good starting point. For this article, it is sufficient to import the sample workspace, TravelBooking.zip, as described below:

  1. Download the file TravelBooking.zip to a temporary directory.
  2. From WebSphere Integration Developer, right-click to see the Business Integration view the context menu and select Import.

    Figure 2. Context menu of the Business Integration view
    Context menu of the Business Integration view
  3. On the Select page of the Import Wizard, choose Project Interchange as the import source and click Next.

    Figure 3. Import wizard dialog
    Import Wizard dialog
  4. From the Import Projects page in the From zip file field, enter the path to the zip file that you downloaded in step 1.

    Figure 4. Import Project Interchange dialog
    Import Project Interchange dialog
  5. Click Select All to select all projects.
  6. Click Finish.

Adding the Web Service Export to the TravelBooking process

So far, we have imported a fully functional process application. You can export it from WebSphere Integration Developer as an EAR file and install it to a WebSphere Process Server without modification. Though to be available as a Web service, it is necessary to add an additional artifact to the application, a so-called Web Service Export. An Export is a client interface rendering of a business process component.

  1. Double-click on the TravelBooking module in the Business Integration view to open the Assembly Diagram.

    Figure 5. Assembly Diagram of the TravelBooking module
    Assembly Diagram of the TravelBooking module
  2. Right-click on the TravelBooking component in the Assembly Diagram. Select Export => Web Service Binding.

    Figure 6. Context menu of the TravelBooking component
    Context menu of the TravelBooking component
  3. Click Yes, when you see the dialog that asks whether a WSDL file should be automatically created.
  4. Select soap/http as the transport protocol and click OK.

    Figure 7. Select Transport dialog
    Select Transport dialog

Your Assembly Diagram should now show a Web Service Export connected to the interface of the TravelBooking component as shown in Figure 8.



Figure 8. Assembly Diagram of the TravelBooking module with added Web Service Export
Assembly Diagram of the TravelBooking module with added Web Service Export

Tweaking the generated files for PHP interoperability

The default child elements in the body of SOAP messages are unqualified, that is, the elements do not have a namespace prefix.


Listing 1. Unqualified elements in the SOAP body
				
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
      <book>
        <request>
          <destination>New York</destination>
        </request>
      </book>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
    

The optional XML Schema attribute elementFormDefault allows you to specify whether or not you should use full-qualified elements in the SOAP message. Normally using full-qualified elements is not a good idea because this causes overhead and bloats the SOAP message. Unfortunately, the PHP SOAP client implementation in XAMPP for Linux 1.4.12 seems not to honor this attribute and always expects full-qualified elements to be present in the SOAP message.

The generated WSDL files for the process components created above do not specify the elementFormDefault attribute, so this results in the default behavior without namespace prefixes. Thus, you need to edit the WSDL files and add the attribute by hand. The value has to be set to qualified to ensure that the exchanged SOAP messages will have full-qualified elements as shown below.


Listing 2. Full-qualified elements in the SOAP body
				
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
                   xmlns:ns1="http://bpc/samples" 
                   xmlns:ns2="http://bpc/samples/TravelBooking">
  <SOAP-ENV:Body>
    <ns2:book>
      <ns2:request>
        <ns1:destination>New York</ns1:destination>
      </ns2:request>
    </ns2:book>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
    

Follow these steps to tweak the generated WSDL file:

  1. Navigate to the Interfaces section in the Business Integration view.
  2. Right-click on the TravelBooking interface. From the context menu, select Open With => Text Editor.

    Figure 9. Context menu of the TravelBooking interface
    Context menu of the TravelBooking interface
  3. Add the attribute elementFormDefault="qualified" to the inline schema definition.

    Figure 10. TravelBooking interface displayed in the text editor
    TravelBooking interface displayed in the text editor
  4. Press Ctrl+S to save your changes.
  5. Navigate to the Data Types section in the Business Integration view.
  6. Right-click on the TravelBookingRequest data type. From the context menu, select Open With => Text Editor.

    Figure 11. Context menu of the TravelBookingRequest data type
    Context menu of the TravelBookingRequest data type
  7. Add the attribute elementFormDefault="qualified" to the schema definition.

    Figure 12. TravelBookingRequest data type displayed in the text editor
    TravelBookingRequest data type displayed in the text editor
  8. Press Ctrl+S to save your changes.

Exporting the TravelBooking application as an Enterprise Archive

The creation of the TravelBooking application is now complete. The next step is to export it as an EAR file for installation into WebSphere Process Server.

  1. Right-click on the project TravelBooking in the Business Integration view. From the context menu choose Export.

    Figure 13. Context menu of the Business Integration view
    Context menu of the Business Integration view
  2. On the Select page of the Export wizard, choose EAR file and click Next.

    Figure 14. Export dialog
    Export dialog
  3. On the EAR Export page, specify a destination for the EAR file to be created and click Finish.

    Figure 15. EAR export details dialog
    EAR export details dialogn

Installing the TravelBooking application

To be able to install the TravelBooking application, make sure that WebSphere Process Server is up and running:

  1. Open a Web browser and enter the URL: http://localhost:9060/ibm/console for the WebSphere Administrative Console.
  2. Log in to the WebSphere Administrative Console and click on Applications => Install New Application. Specify the path to the TravelBooking application EAR file created before. Click Next.

    Figure 16. Administrative Console - Install New Application
    Administrative Console - Install New Application
  3. On the following panels, there are lots of options regarding the installation of EAR files. The discussion of these options is out of the scope of this article. The defaults are sufficient for the used sample application. Just step through these panels by clicking Next. On the last page click Finish.
  4. After the installation has finished, the message "Application TravelBookingApp installed successfully." is displayed as shown below. Click Save to Master Configuration.

    Figure 17. Administrative Console - Application installed successfully
    Administrative Console - Application installed successfully
  5. Newly installed Enterprise Applications need to be started manually. Navigate to Applications => Enterprise Applications. Mark the checkbox in front of the application TravelBookingApp. Click Start.

    Figure 18. Administrative Console - Start Application
    Administrative Console - Start Application
  6. Open another Web browser window and navigate to the WSDL to verify the installation by using the following URL:
    http://localhost:9080/TravelBookingWeb/sca/TravelBookingExport/wsdl/TravelBookingExport_TravelBookingHttp_Service.wsdl
    You should see the WSDL for the TravelBooking business process displayed in your browser.

Creating the PHP SOAP client

This section discusses the use of the SOAP client API available in PHP to be able to access the TravelBooking application. You can download the full source code of the PHP client application in the download section below. XAMPP for Linux 1.4.12 was used as PHP runtime platform.

As Web services are fully described by their WSDL, it is easy to introspect them and create a SOAP client. The PHP class SoapClient leverages the information provided by the WSDL and accepts the URL of the WSDL as an argument.


Listing 3. Creating a SoapClient object
				
<?php 
$client = new SoapClient("http://localhost:9080/TravelBookingWeb/sca/TravelBookingExport/wsdl/TravelBookingExport_TravelBookingHttp_Service.wsdl");
?>
    

To get an overview of available operations and needed input and output parameters the PHP class SoapClient offers the methods __getFunctions() and __getTypes().


Listing 4: Dumping available operations and parameters
				
<p>Available operations:</p>
<pre>
  <?php
    var_dump($client->__getFunctions());
  ?>
</pre>
<p>Available/needed types:</p>
<pre>
  <?php
    var_dump($client->__getTypes());
  ?>
</pre>
    

Either by looking at the WSDL manually or by using the described functions from above, it is easy to prepare the input parameters and call the operation of the Web service. It is important to notice that the actual method used for invocation is named exactly the same as the operation described on the WSDL interface. The PHP SOAP client is able to dynamically offer the Web service operations as a PHP method on the $client object.


Listing 5: Creating the parameter array and invoking the Web service
				
<?php
$params = array("request" =>
              array("residence"         => $_GET['residence'],
                    "destination"       => $_GET['destination'],
                    "dateOfDeparture"   => $_GET['dateOfDeparture'],
                    "dateOfReturn"      => $_GET['dateOfReturn'],
                    "creditCardNumber"  => $_GET['creditCardNumber'],
                    "creditCardCompany" => $_GET['creditCardCompany'],
                    "departureAirport"  => $_GET['departureAirport'],
                    "departureTime"     => $_GET['departureTime'],
                    "airline"           => $_GET['airline'],
                    "hotelCompany"      => $_GET['hotelCompany'],
                    "carRentalCompany"  => $_GET['carRentalCompany'],
                    "carCategory"       => $_GET['carCategory']));
$result = $client->book($params);
?>
    

The $result object now contains the output of the Web service call. The inline schema in the WSDL for the response of the Web service defines only one single simple type element named information. Similar to the dynamically created book() method on the $client object we can use this to get the result value.


Listing 6: Displaying the result
				
<p>The process answered: <i><?= $result->information ?></i></p>
    

Only these lines of code are necessary to create a SOAP client in PHP to access business processes running in WebSphere Process Server V6.0. Of course, a real implementation would need error checking code to make the access more robust.

Testing the scenario

The following screenshots show the successful invocation of the business process running in WebSphere Process Server from the PHP Web site.

This is the data that you can use to start the process:


Figure 19. Input form for the PHP sample
Input form for the PHP sample

After successful invocation, the following result page is displayed. To demonstrate, some technical information like the output of SoapClient->__getFunctions() and SoapClient->__getTypes() is printed at the beginning:


Figure 20. Result page of the PHP sample
Result page of the PHP sample

Conclusion

Using a SOA technology like SOAP, you can easily connect different technologies like PHP and business processes. One minor pitfall is that PHP does not honor the elementFormDefault attribute correctly, but it can be circumvented easily.

SOA allows you to protect your investment in, for example, your current PHP Web site, but also benefit from the latest technology by accessing business processes in WebSphere Process Server V6.0.




Back to top


Download

DescriptionNameSizeDownload method
Sample PHP application for this articlephp-source.zip3KBFTP|HTTP|Download Director
Information about download methods


Resources

Learn

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


Discuss


About the authors

Martin Smolny works on the WebSphere Business Process Choreographer team in Boeblingen, Germany. He has worked on different IBM products and has seven years of experience in business integration software. Martin completed his studies of Information Technology in Stuttgart.


Marc Schwind joined IBM two years ago and works as a Software Developer for the WebSphere Business Process Choreographer team at the IBM development lab in Boeblingen, Germany. He completed his studies of Information Technology in Stuttgart.




Rate this page


Please take a moment to complete this form to help us better serve you.



 


 


Not
useful
Extremely
useful
 


Share this....

digg Digg this story del.icio.us del.icio.us Slashdot Slashdot it!



Back to top


This is the first trademark attribution statement. This is the second trademark attribution statement. Other company, product, or service names may be trademarks or service marks of others.