Pass a string from a JAVA application to a php variable - java

Assuming that we have a JAVA application that connects and exchanges some XML's with an EPP server.
That application writes the data that it receives from the server into files.
It creates a file for each response it gets, according to System.currentTimeMillis().
The name of the file is currentMillis.
Now, since I'm going to need a php script to locate those files, can I simply make the
JAVA application return a value (that of the currentMillis) and somehow from the php script parse that into a PHP variable?

You will need to do the Java and PHP communication over HTTP. So convert the java code that returns the time into a Servlet.
Then invoke the servlet from your PHP code and capture the data returned into a PHP variable.

Related

How can I received parameters from a Java program in a PHP function

I am trying to make my java program and PHP program interoperable. Major part of the processing is carried in PHP, I need a java program to call a PHP function and send some parameters.
Can anyone help me here ?
You can implement a wannabe web service on your back-end:
Have some php script, that will be processing POST requests coming to specific URL
//in your php script you can access and process your POST data
$somekey = $_POST['somekey'];
process($somekey);
From your java program you need to create and send POST request to that URL

PHP, Java Applet communication

Here's what I would like to do.
I have a PHP file in my server where I would like to call java applet. The applet function will send a get request to read a page from third party server. Now I want page read from applet function to be sent to PHP script. To simply put ,i want the return value of the applet request function in a PHP variable. Is it possible to do?
I want to do this way because I already have the code to parse the page information in PHP, so I don't want to rewrite that in java again.
I wanted the Java applet because the request has to be sent using the client information like IP. So I don't want to use proxies.
Note: I am not trying to hack anyone's server. I am not a advanced programmer of either Java or PHP. Please reply me in a descriptive manner possibly with pseudo code.
I already have the code to parse the page information in PHP, so I don't want to rewrite that in java again.
PHP should be able to get that page more easily than can a Java applet. The applet would need to be trusted or in communication with a site that uses the 'cross-domain resources' file that explicitly allows hot-linking.
Searches on 'php proxie' seemed to spill out around 7.32 million hits. I'd start there.

Writing response from Java Http Server to jQuery

I wrote some Java program working on iSeries server. It can handle all Http requests to this server.
I also wrote Html page which is opened on local computer and I use some jQuery (Ajax) requests to iSeries server and I want to get some data from program which is running on it.
My server program sees that it gets some requests (POST and GET) with all parameters etc. and responses to it.
Unfortunately jQuery can't read answer data while simple Java program written and run on my local computer connects to iSeries server can read all responses from this server.
How can I write response in Java which will be avaiable to be read by jQuery?
It's very easy to process data in JSON format in the client side with jQuery. Try to program your server-side to return your data in JSON format.

Using java to communicate with a PHP script on my server

I need to be able to access my database, which in it's own isn't hard as java can directly access it. I want to, however, use a php script to access it, as I need to insert stuff into the database as well, and I don't want to have the username and password of a read-write accoutn for my database in my java code. If someone decompiles it, he can just access my database and do stuff with it...
So basicly, I want to use a PHP script and send $_POST request info from my java code to my php script
(yes, java, not javascript ;-) )
You can do this, no problem. Use a URLConnection with setDoOutput(true), and get its output stream for the POST.
Of course, your PHP script should make sure that all data which is sent is sane, as anyone could send such a request to your PHP script. (Or you would need some way for the Java application to authenticate itself to the PHP script, which simply shifts the problem of hiding these credentials instead of the database ones.)
You should store DB credentials in configuration file to avoid embedding them directly into the code.

Open PDF file on client's browser directly from Java Servlet Class

Hey Folks, So this is the rundown:
Essentially, what I want: PL/SQL Procedure call(using UTL_HTTP) --> Java Web Application, Servlet --> opens up a browser window and renders a PDF.
We use the package UTL_HTTP within our PL/SQL Procedure for this, as it has an option to send requests to external urls via the POST method. The only reason we use this package is to ensure our data is passed as POST parameters (apparently, there is no other way to open up external sites directly from PL/SQL procedures while passing parameters through the POST method). There are other means to provide urls directly and pass get parameters as part of the request url string, but this would expose sensitive parameters like username, password, serial id etc.
This http request from the PL/SQL procedure is intercepted by a servlet in our Java Web Application. Our Java Web Application is a Document Management Application and handles all the document management logic.
We managed to reach the servlet and also get a hold of the PDF and put it in the response.
Here's the catch: Since the originating application was a PL/SQL Procedure that sends the HTTP request directly to our Web Application, at no point is a browser window opened. So in our Java servlet class, we get hold of the PDF and write it onto the response. But we need to spawn a browser window to render the pdf. I found this neat site that provides Java Code to open up a browser window directly from a java class. But the problem is that the browser window opens up at the server directly and not on the client.This browser window ought to open up in our client machine from where the http request was issued not at the server.
Any suggestions?
Cheers
If you are using an PL/SQL Web aplication (using APEX or webToolkit) you can send to the browser the blob that you get from the UTL_HTTP call to the servlet

Categories