PHP to Java

 Hello,

  We have a credit card interface written in PHP and our cc processor written in Java. What I want is to read the data from the PHP interface, pass it onto the Java processor and then readthe result back.

  The first solution I thought of is to use HTTP. Convert the java application into a Servlet and have the PHP redirect the flow to the Servlet. This is a possible solution but I am wondering how I could read the result back from the servlet (mind you I haven't got a clue about PHP syntax in order to read the input stream).

  The second solution is to use the Java extensions that come with PHP4. The problem here is that the live server is not configured with the Java extensions and I do not know how feasible it would be to take it down, recompile PHP with Java support and then run it.

  Also I am not sure how stable this Java extension is.

  Also, I found out that in order to do redirection to another page I have to use the header("Location: URL"); code. Does anyone knwo how I can pass variables along with it as well? Something similar to the following in Java

<jsp:forward page="myPage.jsp" >
   <jsp:param name="param1"
      value="value1" />
</jsp:forward>

  Any more thoughts on the above two solutions? 500 points and an A answer for good opinions/information.
LVL 37
girionisAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lozlozCommented:
hi,

you can use header("Location: page.jsp?variable1=value1&variable2=value2"); but i suppose you'd want it to be a bit more secure. if you wanted to use the post method then you could use this function: http://www.faqts.com/knowledge_base/view.phtml/aid/12039/fid/51. this could be used to essentially forward the form's values directly to java so it would be like posting the form to a java page after you've performed your php functions on the data. regarding java extensions, from the manual:

Warning
This extension is EXPERIMENTAL. The behaviour of this extension -- including the names of its functions and anything else documented about this extension -- may change without notice in a future release of PHP. Use this extension at your own risk.
 
having said that it might be feasible to take down php, add the option to include the extension and restart it. that's all i can think of for now

loz
0
aolXFTCommented:
The java extension is experimental. You could however add java functionality to PHP, using the Extension Mechanism.

That means you compile the java extension as an external module, and add it in using the extensions area of the php.ini file.

If you are using the apache module, on Linux, taking the server down and putting it back up with Java Support(after you've compiled the extension, and added it to php.ini), is simply a case of running 'apachectl restart'.
0
aolXFTCommented:
Sorry, didn't read the question properly, You couldn't get the java extension installed. TBH, if you can't get the extension installed, you aren't very likely to get PHP installed with the java extension either.

One method you could use would be to store the information locally(either in files, or a database), that you put them into through PHP, and take them out through Java/JDBC.
0
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

girionisAuthor Commented:
 Thank you both for your replies.

  aolXFT:

> You couldn't get the java extension installed.

  Why I couldn't get the java extension installed? I haven't tried it yet, I am just asking for opinions :)

  As for the DB/local file suggestion, I do not think it's a right idea. I am not familiar with PHP and its syntax in general. Also I will need to notify PHP somehow for the result (i.e. if the cc is accepted or rejected) that's why I thought about the Java extension.

  I will leave this question open for now for any more suggestions :)
0
lozlozCommented:
when sending the result of the cc transaction, you can simply use variables in the url query string as i said - phppage.php?jspvariable=ccaccepted. this would be access in php as the variable $_GET["jspvariable"] (e.g. if($_GET["jspvariable"] == "ccaccepted") { print "transaction successful!"; } else { print "transaction failed."; }

as i said, if you want to keep all the variables integrated within the system rather than exporting them externally then bringing them back in, the function i provided above may be the one to use. using a database/flat file system would be feasible in my opinion as long as you could use a database which was easy to access from both php and java

loz
0
girionisAuthor Commented:
 Yes but I need to send the request from PHP to a Servlet/JSP page and not another PHP. The problem is not how to send the request (I can simply redirect the flow) but how I can read the result back from the JSP page? The only thing I can think of is to read the request's input stream.

  For example, lets say that I have a PHP file with the following:

header("Location: page.jsp?variable1=hello");

  Then when I run the above and the flow is redirected to the page.jsp in the page.jsp I have smth like:

<%
os = response.getOutputStream();
if (request.getParameter(variable1).equals("hello"))
{
   os.println("hello to you too");
}
else
{
    os.println("another hello");
}
%>

  Now how should I read the string "hello to you too" that comes from the JSP page for example? Once the request is forwarded is there any way I can get back to it?
0
arjendvCommented:
You should use the curl library, it anables you to post data to your jsp script, and get the results back in php.
There are a lot of examples in the user comments on http://nl.php.net/manual/nl/ref.curl.php  .
Using curl, you will also be able to post data via https to make it more secure.
Im sorry that i dont have the time to post a whole solution, but im sure this will point you in the right direction.
Using redirects will never be secure,and may cause potetial problems if users press the back and forward buttons in their  browser.

Arjen

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
girionisAuthor Commented:
 Thank you for your answers. I am currently evaluating all of the suggestions, mainly the Java extension and the curl option. I will get back to you when I have some more info :)

  Meanwhile any more suggestions/info/ideas are more than welcome.
0
girionisAuthor Commented:
 Thank you, I finally used cURL and I found it easier to install and also use.

  Also thanks to the other two guys/gals who have helped me. I will post two separate questions for you so you can also get some points for your help and suggestions :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.