Browse DevX
Sign up for e-mail newsletters from DevX


Use SOAP to Access EJB Components with PHP : Page 5

PHP code on the front end and EJBs on the back end—how do you make them talk to each other? Apply a little SOAP. Exposing the EJBs as Web services enables PHP to work with them, and SOAP is the key.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Create a PHP Client to Access Your Bean
The next goal is to create a PHP client for your stateless session bean. The client will communicate with the bean by using SOAP. Assuming you successfully downloaded, installed, and configured Apache HTTP Server and PHP to "see" each other, you just need to download NuSOAP. The only thing you need to do to install it is copy file nusoap.php into the directory where you put your simple PHP code (in this case, it is C:\Program Files\Apache Group\Apache\htdocs\zzz\). Put the code for the PHP client into the same directory, and call all the PHP material (– soap_client.php) with the following code:

<?php require_once('nusoap.php'); $soapclient = new soapclient('http://localhost:8000/servlet/rpcrouter'); $x = $soapclient->call('say', array(), 'urn:demo'); print_r($x); ?>

Pretty simple, isn't it? Now it's show time! Just check that everything is as it should be:

  • The J2EE RI server is still running.
  • The Apache HTTP server is running (and configured properly to understand PHP code).
  • All the source code is where it should be.
  • Everything is properly deployed (you should not find any mistakes if you followed all steps above).

Open your browser and type the URL: http://localhost/zzz/soap_client.php. You should see the screenshot below.

Click to enlarge
Figure 12: Deployment Progress

Mission Accomplished
Congratulations! You were able to run your own PHP code, which successfully accessed your EJB component. I hope this solution will help you in the future. Feel free to contact me, if you will have any problems with the this example. I can help you either eliminate them or at least find your mistakes. Remember, while you have J2EE RI running, you can see all the debug messages. They'll tell you what's happening and where you have any problems. These messages are pretty clear, so they can be a great help.

Alexey Prokhorenko is a software and Web developer with more than six years development experience in complex, database-driven Web applications.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date