magine a software project for which the front-end developers work with PHP and the back-end developers create Enterprise JavaBeans (EJBs). As the project evolves, the front-end applications need to speak to the back-end EJBs, but this can't be done in one simple step. So what's the solution? Well, exposing the EJBs as Web services enables PHP to work with them. This article provides just such a solution.
Many developers face the challenge of mixing Java and PHP, based on the numerous posts I see on different discussion forums asking, "How do I link PHP with EJB?!" The few answers they receive usually suggest using Web services, but they never offer a practical example. Because this problem has no easy solution, the practical example this article offers is complex, involving Java, PHP, and SOAP technologies. (IMHO, the process of exposing EJBs as Web services requires much more coverage than one article can offer.)
PHP developers who have tried to work with EJB know it is impossible unless the EJB components are exposed as Web services. In large organizations, these developers usually do not have the rights or permissions to manipulate existing EJBs or to create and deploy new ones. So, they need to request their "Application Deployer" managers to expose the EJBs. In smaller shops, some developers probably work with EJB as well as PHP. For those jacks of all trades, this article demonstrates how to:
- Configure an EJB component (a simple stateless session bean)
- Deploy it as a Web service with SOAP
- Modify their PHP code to access the EJB component
The following is a brief listing of all the technologies and software used in this article:
- J2SE (version 1.4.1) to create EJB components
- J2EE RI, which is in the J2EE package (version 1.3.1) as the application server
- Apache SOAP (version 2.3.1) to take advantage of SOAP technology
- Apache HTTP Server (version 1.3.31) to test the PHP code
- PHP (version 4.3.8)
- NuSOAP library for work with SOAP in PHP
Author's Note: This article is not a detailed manual for installing and configuring PHP software, nor is it a manual for EJB component development. For more detailed information on these subjects, consult their official documentation or any of the numerous books about them. The only purpose of this article is to show the reader how to access an EJB component from PHP code. By the way, I used the Windows operation system, but since this software is all cross-platform, you should not have any problems running it on UNIX, for example.
Before jumping into the code, take a look at Figure 1, which shows a high-level theoretical diagram of the solution that you will implement.
|Figure 1: Theoretical Diagram of Solution|