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
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:
- Download the file TravelBooking.zip to a temporary directory.
- 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
- On the Select page of the Import Wizard, choose Project Interchange as the import source and click Next.
Figure 3. Import wizard dialog
- 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
- Click Select All to select all projects.
- 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.
- Double-click on the TravelBooking module in the Business Integration view to open the Assembly Diagram.
Figure 5. Assembly Diagram of the TravelBooking module
- Right-click on the TravelBooking component in the Assembly Diagram. Select Export => Web Service Binding.
Figure 6. Context menu of the TravelBooking component
- Click Yes, when you see the dialog that asks whether a WSDL file should be automatically created.
- Select soap/http as the transport protocol and click OK.
Figure 7. 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
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:
- Navigate to the Interfaces section in the Business Integration view.
- Right-click on the TravelBooking interface. From the context menu, select Open With => Text Editor.
Figure 9. Context menu of the TravelBooking interface
- Add the attribute
elementFormDefault="qualified" to the inline schema definition.
Figure 10. TravelBooking interface displayed in the text editor
- Press Ctrl+S to save your changes.
- Navigate to the Data Types section in the Business Integration view.
- 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
- Add the attribute
elementFormDefault="qualified" to the schema definition.
Figure 12. TravelBookingRequest data type displayed in the text editor
- 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.
- 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
- On the Select page of the Export wizard, choose EAR file and click Next.
Figure 14. Export dialog
- On the EAR Export page, specify a destination for the EAR file to be created and click Finish.
Figure 15. EAR export details dialog
Installing the TravelBooking application
To be able to install the TravelBooking application, make sure that WebSphere Process Server is up and running:
- Open a Web browser and enter the URL: http://localhost:9060/ibm/console for the WebSphere Administrative Console.
- 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
- 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.
- 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
- 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
- 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
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
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.
Download
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
|