[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 727
  • Last Modified:

PHP and JAVA

Hi,
I have a linux server running PHP and APACHE. I enabled JAVA support for PHP. So when I run this code,
// get instance of Java class java.lang.System in PHP
$system = new Java('java.lang.System');

// demonstrate property access
echo 'Java version=' . $system->getProperty('java.version') . '<br />';
echo 'Java vendor=' . $system->getProperty('java.vendor') . '<br />';
echo 'OS=' . $system->getProperty('os.name') . ' ' .
             $system->getProperty('os.version') . ' on ' .
             $system->getProperty('os.arch') . ' <br />';

// java.util.Date example
$formatter = new Java('java.text.SimpleDateFormat',"EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");

echo $formatter->format(new Java('java.util.Date'));

I got this result

Java version=1.5.0_06
Java vendor=Sun Microsystems Inc.
OS=Linux 2.4.21-40.EL on i386
Monday, May 22, 2006 at 11:21:48 AM Greenwich Mean Time

so I assume it show it works without any problem.

Now let me explain what I am trying to do. I have a JAR file which is a Java SDK file for Barclays Authantication service.
Apperantley this SDK provides some functions which I can use for this purpose.

Anyway, how can I use this SDK within my PHP script? the name of the jar file is XFMS_Java_API.jar
0
bilgehanyildirim
Asked:
bilgehanyildirim
  • 14
  • 12
1 Solution
 
bilgehanyildirimAuthor Commented:
I am ready to send this SDK for you to examine.
0
 
siliconbritCommented:
Is this the SDK delivered with the Barclays ePDQ?
0
 
bilgehanyildirimAuthor Commented:
yes! Oh my god, I found someone who knows ePDQ :)))
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bilgehanyildirimAuthor Commented:
That SDK is only for authantication(Chip and PIN) not authorization (AVS)
0
 
siliconbritCommented:
The reason I ask is that the Barclays knowledgebase provides example code covering all valid methods for using the API.

You have to use an approved method to use the java class, and I am not sure that this is allowed.  Talk to the Barclays technical support team first, their number is in your ePDQ account.  If they say that it's allowed, and cant provide an example, post back here and I'll help you to complete the work.

Note that I haven't done this before, but I'm happy to work with you on it.
0
 
bilgehanyildirimAuthor Commented:
I have contacted to Barclays like 10 times. They said they could only provide the SDK, no technical help. They said Java SDK would work with any kind of implementation. it is very hard to find documentation.
I have couple of PDFs and the Java SDK. but unfortunately it is nearly impossible to find an example about PHP (there are examples about JAVA using JAVA SDK)

I know nearly nothing about Java, but I have knowledge of OO programming. So I don't think I will have any problem once I have a grip to this Java SDK :)

If it is ok for you, I can send you the Java SDK and the documentation I have.

Regards,
Bill
0
 
bilgehanyildirimAuthor Commented:
no news?
0
 
siliconbritCommented:

The problem you have is that there is quite a lot of java code you need to write as part of your integration.  Unless you are confident with java, you will find it difficult to use the PHP/Java framework.

I dont accept emails from EE posters, but if you make some headway, you can use this question to post specific queries on specifiic problems you are facing.

If I were in your position, I would start by getting the java ePDQ framework running using the examples in the documentation, making sure you are using test transactions.  Just work through the examples, and when you have that done, we can start to look at how to replicate the same behaviour, using PHP as the controlling agent.

If you cant do this, then you need to consider using a skilled developer who has ePDQ experience.  I have this, but I can't accept projects through EE.  Barclays have a number of partners, published on the site that can help you with this.

0
 
bilgehanyildirimAuthor Commented:
I don't understand why I need to write Java code. As far as I know, JAVA SDK is providing some classes (of course methods as well)
I thought PHP code should be something like this

<?
       $foo = new Java ('XFMS_Java_API');
       
       $foo->setCredentials('username','password');
     
       if ($foo->checkCard('41111111111111111'))
       {
           echo ("<iframe src=$foo->popUpAddress></iframe>");
       }
       else
      {
          echo ("no authantication needed");
      }
?>

am I so naive :)

I thought all java codes is in the SDK, kind of DLL file for windows.

I contacted all of the companies barclays recommended, none of them is cabaple of doing this. I know this is weird but they all said they do MPI implementation, which we already use.

0
 
siliconbritCommented:

Have you tried that PHP code?
0
 
bilgehanyildirimAuthor Commented:
it says
Warning: java.lang.ClassNotFoundException: XFMS_Java_API in /home/httpd/vhosts/******.com/httpdocs/Examples/PHP_JAVA_Example_1.php on line 23

and line 23 is
$foo = new Java ('XFMS_Java_API');

:))

all the files are in the correct directories as described in readme.txt.

I know you don't accept email from EE but if you want i can upload it to my personal server and you can download from there.
0
 
bilgehanyildirimAuthor Commented:
please don't disappear :(
0
 
siliconbritCommented:

The ClassNotFound exception tells you that you are trying to instantiate a class that is not visible on the CLASSPATH.

This is usually a result of one of two things:

  1) You have mis-spelt the class name or its parameter list

  2) The jar or war file does not exist or is not set on the CLASSPATH.

Do you know how to set your classpath?
0
 
siliconbritCommented:

Something to add into your code from the original question:

   echo 'Java classpath=' . $system->getProperty('java.class.path') . '<br />';
0
 
bilgehanyildirimAuthor Commented:
Thank you!!

I don't know how to set but I have full control over my server. so if you tell me, I can do it step by step.
At the moment values in the php.ini is

[Java]
java.class.path = "/usr/local/jdk/jdk/php_java.jar:/usr/local/jdk/jdk/XFMS_Java_API.jar
java.library.path =  /usr/local/jdk/jdk/jre/lib/i386/
java.home = /usr/local/jdk/jdk/bin
java.library = /usr/local/jdk/jdk/jre/lib/i386/server/libjvm.so
0
 
siliconbritCommented:

Did you reboot the webserver (or php-cgi if your using it), after you added the XFMS_Java_API.jar to the php.ini file?


The path to XFMS_Java_API has "jdk" in it twice.  Is this the correct path to the jar file?

  ( ls /usr/local/jdk/jdk/XFMS_Java_API.jar )


0
 
siliconbritCommented:
...and the same with:

  ls /usr/local/jdk/jdk/php_java.jar

0
 
bilgehanyildirimAuthor Commented:
ok let me check. can i just restart the apache from plesk or do i need to reboot?
0
 
siliconbritCommented:

Restart Apache from your Plesk console
0
 
siliconbritCommented:


There is also no closing quote on your java.class.path line:

  [Java]
  java.class.path = "/usr/local/jdk/jdk/php_java.jar:/usr/local/jdk/jdk/XFMS_Java_API.jar         <- where's the quote?
  java.library.path =  /usr/local/jdk/jdk/jre/lib/i386/
0
 
bilgehanyildirimAuthor Commented:
Ok, I restarted but it didn't work. this is what I did

I found where that api is
[root@server /]# locate XFMS_Java_API.jar
/usr/java/j2sdk1.4.2/jre/lib/ext/XFMS_Java_API.jar
/usr/java/j2sdk1.4.2/lib/XFMS_Java_API.jar
/opt/arcot/xfort/sdk/j_api/XFMS_Java_API.jar

and I added it to php.ini
java.class.path = /usr/local/jdk/jdk/php_java.jar:/opt/arcot/xfort/sdk/j_api/XFMS_Java_API.jar

I got the same error message..
0
 
siliconbritCommented:

It looks like the file exists in three locations, two of which are within the standard java lib directory.

Does the user under which PHP runs (the 'apache' user?), have read access to the jar file?

Are you certain that this is the correct jar file? After all you originally specified "/usr/local/jdk/jdk/XFMS_Java_API.jar" and that location does not appear when you use 'locate'.

Did you correct the quotes on the java.class.path as I mentioned in my last post?

0
 
bilgehanyildirimAuthor Commented:
after restart it says
Fatal error: java.lang.NoClassDefFoundError: net/php/reflect in /home/httpd/vhosts/*****.com/httpdocs/Examples/PHP_JAVA_Example_1.php on line 4

and line 4 is $system = new Java('java.lang.System');

grrrrrrr. I hate JAVA!
0
 
bilgehanyildirimAuthor Commented:
I gave all XFMS_Java_API.jar and php_java.jar CHMOD 777. is it enough?
0
 
siliconbritCommented:

The class reflect() is part of the PHP/Java package (not XFMS...), so your classpath is not correct.

1) Check the quotes as I've already said twice.

2) Check that the path to the php_java.jar is correct.

I am going to stop monitoring this thread shortly.  I can help you if you follow my advice, or if you have rudimentary java/php experience, but it's going to be a struggle if you cant sort out your own classpath.

Go back to my post of 23/05 when I said:

"If I were in your position, I would start by getting the java ePDQ framework running using the examples in the documentation, making sure you are using test transactions.  Just work through the examples, and when you have that done, we can start to look at how to replicate the same behaviour, using PHP as the controlling agent."

In other words, dont use PHP to begin with, use Java only so that you understand what you need to do.

Then work on learning how to use Java within PHP,

Then, and only then, start to think about integrating your ePDQ requirements in PHP.

0
 
bilgehanyildirimAuthor Commented:
Ok, thank you very much for your time.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 14
  • 12
Tackle projects and never again get stuck behind a technical roadblock.
Join Now