Reputation: 1259
Is there any way to call an EJB session bean from PHP? Are there any specific functions to do that?
Upvotes: 1
Views: 3412
Reputation: 118784
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 Java EE 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.
Upvotes: 3
Reputation: 40199
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>");
?>
Upvotes: 1