如何从 PHP 调用 EJB 会话 bean?

发布于 2024-09-04 12:13:13 字数 50 浏览 1 评论 0原文

有没有办法从 PHP 调用 EJB 会话 bean?有什么具体的功能可以做到这一点吗?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明月松间行 2024-09-11 12:13:13

并不真地。如果您可以进行 CORBA 调用,大多数容器都支持 CORBA 作为与远程 EJB 通信的协议,但我不推荐它。

您最好将 EJB 会话 Bean 调用公开为 SOAP Web 服务,或者简单地使用 Servlet 将其封装起来,并将其作为临时 Web 服务进行调用。

现在,如果您在 Java EE 服务器中运行 PHP(我相信 Resin 可以运行 PHP),那么您也许能够调用可以调用 EJB 方法的 Java 调用。

但是,坦率地说,Web 服务或临时 Web 外观可能是您通往成功的最佳且最快的途径(假设您被允许编写它们)。

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.

懒的傷心 2024-09-11 12:13:13

有一些库可以实现 Java/Php 桥接,例如 PHP/Java Bridge

因此,如果您使用的是 IBM WebSphere():

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

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>");
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文