How to call a EJB session bean from PHP?

你离开我真会死。 提交于 2019-12-06 13:01:29

问题


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


回答1:


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.




回答2:


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>");
?>


来源:https://stackoverflow.com/questions/2979499/how-to-call-a-ejb-session-bean-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!