views:

109

answers:

2

Is there any way to call an EJB session bean from PHP? Are there any specific functions to do that?

+2  A: 

Not really. If you can make CORBA calls, most container support CORBA as a protocol to talk to a remote EJB, but I wouldn't recommend it.

You'd have better luck exposing the EJB Session Bean call as a SOAP Web Service, or simply facade it with a Servlet and invoke that as an ad hoc web service.

Now, if you're running PHP within a JEE server (Resin I believe can run PHP), then you might be able to invoke a Java call that can call an EJB Method.

But, frankly, the web service or ad hoc web facade is likely your best, and quickest path to success, assuming you're allowed to write them.

Will Hartung
It's Caucho's Quercus that will run PHP. It doesn't have to be hosted in Resin. http://quercus.caucho.com/
Trevor Tippins
A: 

There are some libraries that do Java/Php bridge implementation, such as PHP/Java Bridge.

So if you were using IBM WebSphere (source):

<?php
   // Get the provider URL and Initial naming factory
   // These properties were set in the script that started the Java Bridge
   $system = new Java("java.lang.System");
   $providerUrl = $system->getProperty("java.naming.provider.url");
   $namingFactory = $system->getProperty("java.naming.factory.initial");
   $envt = array(
     "javax.naming.Context.PROVIDER_URL" => $providerUrl,
     "javax.naming.Context.INITIAL_CONTEXT_FACTORY" => $namingFactory,);
   // Get the Initial Context
   $ctx = new Java("javax.naming.InitialContext", $envt);
   // Find the EJB
   $obj = $ctx->lookup("WSsamples/BasicCalculator");
   // Get the Home for the EJB
   $rmi = new Java("javax.rmi.PortableRemoteObject");
   $home = $rmi->narrow($obj, new Java("com.ibm.websphere.samples.technologysamples.ejb.stateless.basiccalculatorejb.BasicCalculatorHome"));
   // Create the Object
   $calc = $home->create();
   // Call the EJB
   $num = $calc->makeSum(1,3);
   print ("<p> 1 + 3 = $num </p>");
?>
Mohamed Mansour
Will this work with more complex structures than a simple "num"?
Pascal Thivent