I have a simple java program that take some parameters to create an image. I want to set up a website in which the user can choose the parameters and, from his ok pressed, the server runs the program. When the program has finished, an image is on the server so the web user can see the result. How can I do that? Which technology I need? Something like JSP or only java installed on the server? Normally, hosting services have this possibility by default or I have to choose some advanced options? Just to have an idea... Thanks!
You can do it with java, but also with php if you need it (php is generally more available and in my opinion quicker to setup).
You have your form send data as GET / POST request;
at the other end you have a web/application server receive the data (some kind of REST service or just a plain script), execute your image generating routine/program and then take this image and return it through http.
Related
I have a native (installable) Java program that constantly generates certain data (only numbers and text). I want to send that data to the browser. I am looking for something similar to node.js with socket.io
I want to send data (text and numbers only) from java stand alone application running on the client's PC to the client's browser and display this data as a standard website (HTML CSS and JS).
Take a look at this image. How would you approach this problem?
Take a look at this image as well.
So
1 - Everything work on the PC
2 - principal concept: if you choose to use a browser, the control comes from the user + browser (which can choose to retrieve data, push buttons, etc.). Nothing outside can decide to send data to a browser if it didnt ask it. Function of a browser is to browse.
one solution:
you production app build the data and put it in some file, it can format it in HTML : format option 1 (or raw data : format option 2)
the data produces can be put on a local file (store option 1), or to be used by a web server (store option 2), even with the same file.
store option 1: just use your brower to browse your directories:
something like that: file:///C:/truc.html
store option 2: you need a local web server:
instal some (heavy for each PC): tomcat, or glassfish
it can deliver static page for format option 1 (same result as store option 1)
or it can proces with a java/jsp program which retrieve raw data and show it as html (format option 2)
You dont need sockets, or network functions.
In your schema: the background process:
can work with the webserver (or event read or change some datas in the database).
dont have to talk with the browser. The browser needs only to talk with the server, which works with your background process.
your background process can be hosted in the server. It can be scheduled by quartz on glassfish (tomcat, or other web servers). In this design, you finally only need a browser and a client.
I have a simple cloud IDE,I want to make it able to build and run applications remotely, the target application's source files will be in a remote server in isolated virtual machine (e.g Windows 8.1,or Ubuntu 14.04). It's not difficult to build that application but how to run it and view its output to users ?
What if it's a desktop application (suppose it's written in C# or Java or Python)?
Note: users access there applications only using browsers (e.g Firefox,Chrome,...)
Edit: desktop application may contains GUI stuff not only console ;)
You need a web application.Now this web application when loads send request to backend code that backend code will do SSH to remote machine and read the file from specific location.Now that read stream will be send back in response and displayed on web based UI. In these type of application few thinks matters.
1) Like if you whole file at once then it will take time to display that content to user.Better idea will be read around 100 lines at once and when user scroll down then again send request to web server to read next 100 lines in this way you can decrease response time and better user experience.
Each of the languages you mentioned offers a Web Services framework of some kind. Pick one, and implement something that a) starts your app, b) shows the output. Depending on the processing time (how long it takes to complete) you might even get away with just one.
You can go for a self-contained, standalone service:
C#: Is it possible to create a standalone, C# web service deployed as an EXE or Windows service?
Python:
Best way to create a simple python web service
Java:
https://technology.amis.nl/2009/06/05/publish-a-webservice-from-a-poja-plain-old-java-application-that-is-out-of-the-container-using-endpoint-class/
Alternatively, you might use a container (server) for your app, like Apache with mod_mono or IIS for C#, Tomcat, Jetty, Jboss for Java, Apache with mod_wsgi for Python (just examples).
The web service would probably sit on the remote machine, so it could use system calls ('command line') to run your core app, and then it would send the results over http. Since you mention GUI, there could be more layers to the solution:
The GUI - static HTML, desktop app, sending requests to the 2nd layer, say displaying dropdowns for parameter1 and -2
The Web Service - takes the params from the request, say http://remote.machine.land/start/app?parameter1=X¶meter2=Y, runs a local command like /home/users/myapp.sh -parameter1=X -parameter2=Y
The application itself - not necessarily aware of any internet out there.
This way you stay free to change/enhance any part at a time, call the 2. layer programmatically, introduce load-balancing, etc.
3.
From my understanding the Java Client is what is rendered onto the browser such as the javascript, "the client side" for example what the user see's (tables, html, the sorting etc) things in the jsp. The server side is the servlet that makes the connection and call the specific class's based upon the request. I feel as though I am completely wrong as when I do research I am getting different answers. CAn I get some clarification on this please.
Java running on the client side means the end user needs Java installed and is running a Java program on their computer. This could be a standalone Java executable program (a traditional application), or it could be through a browser running a Java applet. Either way the end user's computer is actually running the Java code locally.
Java on the server side means that all the Java processing happens on a server somewhere, and the person accessing the site or service doesn't need Java installed. Servlets and JSPs fall into this category. The server does all the processing and then returns HTML/Javascript/CSS, etc to the end user. The user's web browser receives and processes those files to display the web site.
It sounds like you are getting confused because web browsers use Javascript to display dynamic sites, but Javascript is a totally separate language that has nothing to do with Java. In other words, a web site could be powered by Java servlets on the back end and could also use Javascript on the front-end, but they aren't directly related or dependent on each other. All the HTML, Javascript, CSS, etc that make up the web site are processed by the user's browser and the user doesn't have to know or care how all that stuff is generated on the back end.
I have a java application that will take the image as an input and output another image. I have a website with a popular host (PHP+MYSQL Hosting). I want to create a page on the website with PHP with a form where a user can upload an image which will then pass the image onto the Java application.
What I am planning on doing is when then user uploads the image, it gets stored in a folder on the web server. I will then call the java app on the server passing the url of the image as an argument and then the java app will output another image, let’s say, to a result folder. The PHP page after the execution will then display the result image on the browser.
Now my questions are:
Is it possible to execute java apps on popular webhosts (for example mine is WebHostingBuzz.com)?
The java app is fairly heavy as it does a lot of image processing. Should I offload the java app to another web server? If yes, are there any services that will run my java app?
(Optional) It’s a demo of my java app and I don’t want to store the images people upload. Is there a way where I can directly pass the uploaded image to the java app and output the image generated directly instead of storing it on the web server? I would prefer this because, if the image is big, I can make PHP stop the execution after a timeout.
How do I communicate with the java app from PHP for info on its execution, for example When PHP calls the java app, the page has to wait till the app finishes processing? I want the java app to send a response to the PHP page saying that the processing is completed and the page is redirected or refreshed accordingly.
I hope you get the idea, please suggest the technologies that I can use to implement this and also if you have a better idea, post it!
Thanks!
Now my questions are: Is it possible to execute java apps on popular webhosts (for example mine is WebHostingBuzz.com)?
It's technically possible. But the hosting has to install JRE at the host and give the PHP user sufficient OS-level and filesystem-level permissions. So you're really dependent on the hosting whether they provide this opportunity. Best is to just contact their support team and ask it.
If it is supported, you could just use shell_exec().
$result = shell_exec("java -jar /path/to/imageprocessor.jar " + $imagepath);
if ($result) {
// Shell execution succeed.
} else {
// Shell execution failed.
}
For asynchronous communication / background processing, the client has to fire an ajaxical request.
If it is not supported, consider porting Java to PHP. The GD image library has pretty a lot of functions which may be of use.
Google App Engine allows to host Java (and Python) web applications. The SDK and the basic account is free of charges. With the SDK, you could develop and test the application locally and then simply deploy to App Engine (NetBeans and Eclipse plugins are available).
Then the PHP app could send the data in a HTTP POST to the Google App Engine application and get the result in the response data.
Or the data is stored first in a database blob and a processing job is put in a task queue (a 'message queue'). This has the advantage that the PHP client request will return immediately after the data has been POSTed. Then, the PHP application could poll for the result data while Google App Engine processes the image. The PHP side would be more responsive this way.
Wouldn't it be easier to make your java app a web app, that PHP could call via an url in wich he would put the url of the image so java can download it?
like http://yourjavaserver/imageprocessing?imgurl=IMAGE_URL
and the java servlet would reply with the image file itlsef.
You can look for "java hosting" on google, to find a host for this, but it's more expensive than PHP hosting. Maybe the best choice would be to get a dedicated server which could host both PHP and java applications...
I think your best bet here is with your java app running as cron(or a deamon) that can load the file details from the database. This will require a (one or more) page-refresh on the users part after the generation is complete, at which point your script can recall the image from the database/filesystem.
I do not think you will be able to do this in real-time due to timeout restrictions on the PHP webpage. However, you could write a java applet that can take the file and process it before sending it to the server (or depending on how you intend to use it, perhaps you do not need to upload it after the transformation?).
We have a php setup for our web pages that is secure with HTTPS. The web app talks to a DB but we also want it to talk to a java server we have.
The java server is a standalone java application (not web). We simply want a callback action after the PHP page finished writing to the DB done in the java server. What is a good way for this php page to talk to the java program to get something done?
I usually recommend against quick and dirty but here :
You can dump data in a file if it can be asynchronous. Then a cron job from java, checking for that kind of file at a regular interval, do the specified command.
For example, you can dump the word ExecuteCmd1 in a file. The java thread reads it, interprets it and choose that he must execute the method or class with the same name.
You can do the same thing over to go back to php.
Probably via a TCP/IP connection. If your Java application runs a server, then the PHP script can connect and send a message informing the Java app that the DB has been written to.
Do a quick and dirty JSON RPC from PHP to Java. You could probably get it up and running in one cup of coffee.
Use CURL on php (http://php.net/curl) and json_encode() to POST a json string to your Java server. (scroll down and find the curl wrapper class that someone wrote in the comments. It's easy.)
Use JSON (http://www.json.org/java/) in Java to decode it and use it immediately. Send your response back in JSON too.
I had a similar XML RPC system running in production for years. PHP -> IP -> Java works great.
Google Protocol Buffers Not so much dirty, but works, and works well, regardless of which launguage you use.
You can try the PHP/Java bridge. I used it a while ago to use Java logic inside Typo3, a PHP CMS.
My advice, whether you use the bridge or not: make sure you know where the errors come from if something doesn't work. Check both PHP and Java logs. Be verbose if an exception occurs.
How much data do you need to transfer?
How many requests per second?
Does the Java application have to handle the request immediately, or is it enough to handle the request in a few minutes?
Does the Java application need to return data to the user's browser?
If the answers to questions 3 and 4 are no and no, you could just create a database table for the jobs, have the PHP app insert a new job, and have the Java app poll the job table every minute or so.