How to execute java functions/script in PHP - java

I have a system which is implemented using PHP(Joomla). Now the client wants to integrate a SMS gateway. Unfortunately SMS gateway does not supoort PHP. It's written in Java and All the examples are written in JAVA.
I'm supposed to include webservices‐rt.jar to my program and run a example script as below.
lk.mobitel.esms.User user = new lk.mobitel.esms.User (); user.setUsername(“TestUser”);
user.setPassword(“Password”);
lk.mobitel.esms.test.ServiceTest st = new lk.mobitel.esms.test.ServiceTest ();
System.out.println(st.testService(u));
According to my knowledge I can run a .jar as below using PHP
<?php exec("java -jar filename.jar arguments",$output); ?>
How can I run a JAVA script like above in PHP? Is it possible? Is there a way to bridge PHP and JAVA? What I want is to run JAVA in PHP else I would say communicate between these two.

I never did this, but PHP Manual gave a link for PHP-Java Bridge for PHP5 as PHP/Java Bridge. If it is what you are looking for ?

It's not possible to combine PHP and Java in the same script and have them executed in one run.
Your exec approach is the way to go, if you are approaching from PHP. But you should rather use passthru as exec does not return anything. With passthru you can get the shell response of your java command and act accordingly.

Is there a way to bridge PHP and JAVA? What I want is to run JAVA in PHP else I would say communicate between these two.
Simple answer:
Bridge using data-exchange layer. :)
Hint (in super simple language): My favorite webservice uses PERL to process their scripts and I fetch them using XML.
Groupon is made on RoR but, I happily get tweets, thanks to their API which outputs a JSON.
Simple? :)

Related

Execute Python script from Android app in Java?

I am trying to find a way to execute a Python script from my Java code in Android. I did a research on this matter but the only thing I found is, how I can convert python scripts in APK for android (Kivy e.t.c.).
More specifically I have a script which contains a lot of functions.What i want to do is to create an object based on this python script inside my java code and via this object to call my functions.
I can't convert my Python code into Java, because I use various libraries that exists only in python.
Any advice would be helpful and deeply appreciated.
The following a snippet of my Python script. I use the library charm for cryptography.
from charm.core.math.integer import integer,serialize,deserialize
class serializeClass:
def __init__(self)
...
def serialize(self, charm_object):
assert type(charm_object) == integer, "required type is integer, not: ", type(charm_object)
return serialize(charm_object)
def deserialize(self, object):
assert type(object) == bytes, "required type is bytes, not: ", type(object)
return deserialize(object)
One option would be to create a Web Service API to allow your python results be served up over HTTP. Then it's just a matter of Android communicating with an HTTP web service which is simple.
You might find some python to java bridge out there but in my experience these things always have limitations in practice and seem great in theory but don't end up working correctly.
You can use SL4A project which would allow you run your Python code on Android.
Github: https://github.com/damonkohler/sl4a
Tutorials: https://github.com/damonkohler/sl4a/blob/wiki/Tutorials.md
Check out Qpython, could be an easy solution. You can run your python script against the Qpython android python core, or deploy yours.
Checkout this repository: https://github.com/qpython-android/app-call-qpython-api

How PHP script can be called using Java Applet

I want to access user's scanner using PHP script. I know this can be done by using PHP script on Linux based machine.
I want to put this script on the server and wanted to run it via Java Applet I don't know Java much also I am not sure if this task can be done by this way.
Please suggest if this is correct way and How to proceed on it.
Thanks for your time!
Can the scanner PHP code be operated purely via parameters in the URL? If so, then a Java applet could connect to those URLs passing parameters as necessary, and if the PHP script returns information in the HTML output stream (as if it were returning a web page), then the applet can parse the page it 'downloads' from that URL to get the information out. Not elegant, but do-able.

Android: Call Python Script (via SL4A) from Java code

Is it possible to call/run a python script file from Java code on the Android platform using SL4A? Basically I have a full blown Java Android app and I have several Python scripts that scrape some information from various web pages. I would like to be able to call these python scripts with the web page and get the results back. Is this possible? If so, can anyone point me in the direction of an example or two?
Thank you,
Harry
run an SL4A script from my application?
http://code.google.com/p/android-scripting/wiki/FAQ#Can_I_run_an_SL4A_script_from_my_application?
Here you go, a solution on how to make Android applications using SL4A and Python. I have developed a functional Python application following this tutorial so I can vouch for it. I assume you can add the Python code and do your data exchange with JSON.
I personally have never tried to mix these two together, though I will probably try after seeing your post.
Also, if you have any problems/questions, related to starting that example, post them here, I might help.

PHP get data or interact with a running Java process. (I think different than PHP/Java bridge)

I have an apache2 webserver with php installed and working. I am wondering if there is any way I can get a PHP script to access a Java program that is constantly running, mostly to just get information that the process keeps track of. The Java program is not a webapp or running within the apache server. It is a separate program.
Ive been looking into PHP/Java Bridge systems, and all they seem to do is let you run Java programs from PHP and vice-a-versa, which is not what I need. I can think of a way to do this via a web service and SOAP running on localhost, but if there is a way to avoid this and I can gain direct access to the Java program, I could get my webapp to run much faster.
The Java app that I am trying to "talk to" is a program that I wrote so I have access to the source code to make the necessary changes if something within the Java program needs to be set up.
Thanks in advance, I've been looking all over for something like this.
You'll need to communicate with the Java process in one way or another. As a web service is too heavy, you could simply communicate over a socket with a custom text or binary protocol.
Or you could also perhaps make the Java program write to a database every n seconds, and read from the database in your PHP script.
EDIT :
Look at http://www.php.net/manual/en/sockets.examples.php for a socket client example in PHP.
Look at http://download.oracle.com/javase/tutorial/networking/sockets/clientServer.html for a server socket example in Java.
PHP/Java Bridges let you call a running Java program from PHP.
Read: http://en.wikipedia.org/wiki/PHP/Java_Bridge
Read: http://php-java-bridge.sourceforge.net/pjb/desktop-apps.php
The bridges actually use local socket communication, from the faq:
<?php
include_once("Java.inc");
$i1 = new Java("your.class", "1");
$i2 = new Java("your.class", "2");
$i3 = $i1->add($i2);
echo $i3->toString() . "\n";
?>
See Java.inc.
And edit your java code to contain the following line:
static final php.java.bridge.JavaBridgeRunner runner = php.java.bridge.JavaBridgeRunner.getInstance("9267");
Hey, so basically you need to run java application from php and get response from java application?
If its that so - I can't see any problem fro php/java-bridge. For example I've successfully run java encryption method for custom encryption in php.
You might look into Quercus/Resin. PHP runs inside Java on a Java web server. You can call Java code as if it was PHP functions/commands. All PHP commands are not supported, both most are. For example, you can run WordPress under Quercus.
http://www.caucho.com/resin-3.0/quercus/

How to connect to RMAN in Java?

I don't know how to connect to RMAN in Java. Simple request don't work when I use command non-SQL, like RMAN etc... I'm gonna to make program like "ORACLE Secure BackUP", but how they connected to RMAN??
I don't believe that there is a published API for interacting with RMAN other than the command line. So if you wanted to create a program like Oracle Secure Backup that used RMAN, you'd probably have to invoke the RMAN executable from Java. Which means that you'd probably also have to parse the output of the various RMAN commands in order to provide feedback to the user.
If you want to go down this path, you'd want to use the Runtime class in Java. Here is an example of calling an external program from Java.

Categories

Resources