Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with Php-Java Bridge

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.

like image 529
Scrappy Cocco Avatar asked Mar 22 '11 10:03

Scrappy Cocco


2 Answers

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.

like image 154
Costis Aivalis Avatar answered Sep 18 '22 15:09

Costis Aivalis


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";}
?>
like image 34
dfy7 Avatar answered Sep 22 '22 15:09

dfy7