Working with Php-Java Bridge

巧了我就是萌 提交于 2019-12-18 16:56:13

问题


I am having trouble setting up the Php-Java Bridge setup properly.

I will explain what I have done.

  • My site is in pure php
  • For our payment transaction process we need to set up a php-java bridge
  • I followed this link to setup the bridge PHP-JAVA BRIDGE INSTALATION.
  • Here I learned that I need to have a private jvm to install the bridge.
  • So 1st i installed apache-tomcat-6.0.14 in Private JVM using my c-panel. After instalation it asked me to Map a domain to private JVM. So I mapped my domain example.com (which is the only option available) to it.
  • Then it asked to enable a traffic redirection from Apache web server to my Java application server (there was a check box and i clicked it)
  • Finally it asked me to deploy the WAR File (JavaBridge.WAR was my file) and everthing seems fine
  • Now when i go to http://example.com/JavaBridge/ I could see the javabridge examples and it works fine.

SO FAR SO GOOD

Now my problem starts here when I try to access a java class file from php. A sample test.php is what I create and put the following code into it.

  <?php
        require_once("http://example.com:portnumber/JavaBridge/java/Java.inc");
        $System = java("java.lang.System");
        echo $System->getProperties(); //This Part echo's correctly and shows the data so it means i can access Java.inc Correctly

        $path_e24class = getcwd(). '/e24PaymentPipe.class'; //This part fails both test.php and java class file e24PaymentPipe.class are in the same directory in publich_html folder
        java_require($path_e24class);
        $pipe = new Java("e24PaymentPipe");
        $pipe->setAction("1");
?>

My site contents reside in the public_html folder and the WAR file are deployed in private jvm.

These are the error message am getting.

  1) Warning: java_require() not supported anymore. Please use tomcat or jee hot deployment instead 
  Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new e24PaymentPipe. Cause: java.lang.ClassNotFoundException: e24PaymentPipe VM:  1.6.0_22@http://java.sun.com/" at: #-10 
 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358) #-9 
 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) #-8 
 java.lang.Class.forName0(Native Method) #-7 
 java.lang.Class.forName(Class.java:247) #-6 
 php.java.bridge.Util.classForName(Util.java:1518) #-5 
 php.java.bridge.JavaBridge.CreateObject(JavaBridge.java:445) #-4 
 php.java.bridge.Request.handleRequest(Request.java:458) #-3 
 php.java.bridge.Request.handleRequests(Request.java:500) #-2 
 php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) #-1 
 php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:60) #0 
 http://example.com:portnumber/JavaBridge/java/Java.inc(232): java_ThrowExceptionProxyFactory->getProxy(3, 'java.util.Prope...', 'T', false) #1

Finally I don't know much about the java. So am stuck here not knowing what to do.


回答1:


Here is a great step by step tutorial you can follow, which shows everything required! It is a little old (2007) but helped me a while ago.

There is also another option. You can install Apache Tomcat and deploy your war there. You can have even multiple tomcat instances simultaneously with your httpd running at the same time on the same machine, as long as you respect the port settings. You can even front them with Apache httpd.




回答2:


you can try this:

  1. package your code to jar, and copy it to java.ext.dirs which you can found in JavaBridge.log
  2. copy the related class libraries to java.ext.dirs
  3. restart the service of JavaBridge

good luck!

<?php require_once("JavaBridge/java/Java.inc"); 
     try {    
     $hd = new java("hdfs.HDFS");    
     $hd->get("hdfs://master:9000/user/hadoop/test-in/logo_cn.png", "/home/hadoop/1.png");
    } catch (JavaException $ex) {  echo "An exception occured: "; echo $ex; echo "<br>\n";}
?>



回答3:


You can use this php implementation on github that works with php 5.3.

See credits on the git readme for more information.




回答4:


You can try this; put the JavaBridge.jar in tomcat's lib folder e.g. apache-tomcat-7.0.12/lib.

Restart tomcat server and then,

$pipe = new java("com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe");
$pipe->setAction("1");

This way I created the php version of the object.




回答5:


Why don't you put the e24PaymentPipe class in your Java application's classpath and skip the two lines below:

// $path_e24class = getcwd(). '/e24PaymentPipe.class';
// java_require($path_e24class);

$pipe = new java("fully.qualified.classpath.e24PaymentPipe");

You are mixing PHP side and Java side operations. in theory the java_require (which is deprecated) was designed to work on the Java side. You are specifying a PHP side path.




回答6:


You can save yourself a lot of grief by using a pure PHP implementation of the e24PaymentPipe library.

Disclaimer

The link is to my github repo of the library, but I did not write it. See the readme in for original credits.



来源:https://stackoverflow.com/questions/5389689/working-with-php-java-bridge

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