6

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.

ssuperczynski
  • 3,190
  • 3
  • 44
  • 61
Scrappy Cocco
  • 1,192
  • 3
  • 21
  • 38

6 Answers6

3

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.

Flexo
  • 87,323
  • 22
  • 191
  • 272
Costis Aivalis
  • 13,680
  • 3
  • 46
  • 47
  • Thankzz for that wonderful tutorial....but still i have some doubts...like am trying to setup this on a live server which linux based....and the tutorial here is for windows xp ....so can this be followed too for a linux server... – Scrappy Cocco Mar 24 '11 at 05:38
  • @Scrappy Cocco: Great that you liked it! You will find that things are fortunately surprisingly identical between windows and linux. You have to substitute ".dll" with ".so", the path separation character "\" with "/", and the directories are located in different places, but easy to follow. After all windows have copied lots of the conventions used in Unix. – Costis Aivalis Mar 24 '11 at 10:38
  • @CostisAivalis - Do you know a work around for the `require_java()` error noted above? – Kit Feb 21 '12 at 13:08
  • @Kit: Does Step 10 give you a "Hello World" output? – Costis Aivalis Feb 21 '12 at 13:50
  • @CostisAivalis: No. I get an error `Warning: java_require() not supported anymore. Please use` – Kit Feb 21 '12 at 14:32
  • 2. Save it as phpinfo.php into C:\Program Files\Apache Group\Apache2\htdocs\test. 3. Open http://localhost/test/phpinfo.php in your web browser. Do you get Java Support Enabled? – Costis Aivalis Feb 21 '12 at 14:44
  • No I don't. There are only a few java environment vars in the phpinfo. However `$s = new Java("java.lang.String", "hello");` works OK. – Kit Feb 21 '12 at 15:15
  • Any chance we could continue this in a chat room? http://chat.stackoverflow.com/rooms/8022/chat-between-costis-aivalis-kit – Kit Feb 21 '12 at 15:18
  • It could be that you do not have a JDK installed and only a Java run time engine. Try the commands "javac -version" and "java -version" and make sure the output matches your environment variable values. – Costis Aivalis Feb 21 '12 at 15:24
  • As the installation process looks very outdated, you can also refer to http://docs.soluble.io/soluble-japha/install_server/ for an updated guide – Sébastien Vanvelthem Mar 08 '17 at 12:17
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";}
?>
antyrat
  • 27,479
  • 9
  • 75
  • 76
dfy7
  • 21
  • 1
2

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

See credits on the git readme for more information.

Kieran Andrews
  • 5,845
  • 2
  • 33
  • 57
0

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.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
0

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.

sumanchalki
  • 1,457
  • 17
  • 21
0

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.

cquezel
  • 3,859
  • 1
  • 30
  • 32