How to create simple Web Server for Map/Java Application? - java

I want to create web server for (localhost) which:
1-provides HTML code (https://leafletjs.com/)
2-receives requests (Ajax requests) from the client that calls corresponding methods in the backend and their send the result back to the client.

Install an "Apache Tomcat" application server and write a "Servet Application" or use "Java Server Faces". Google for those keywords.
I wrote a german tutorial about this: http://stefanfrings.de/jsf_tutorial/index.html there is a translation link in the upper right corner.
If you do not want to install an application server, then you may prefer to use Jetty, which is basically the same as Tomcat but embedded in your own executable program.

Related

Replace applet with alternatives

Our app heavily makes use of applets to check-in (upload) and check out (download) files from users machine. Can someone please confirm what are the alternatives for applet (as it is going to be deprecated by Oracle in 2018)?
We had the same problem. We were using applets in our web application for printing, scanning etc. on local machines. We solved the problem with a simple Java Web Start client application that has a simple web server embedded (Jetty). Now when user starts the web application the client application is downloaded, if necessary, and started on the local machine. It sits there in a tray and listens for requests from the server side application. Handlers are implemented for different types of requests. When client side receives a request, it hands it over to a responsible handler, which executes its task and creates a response, that is sent back to the server side.
For now, this solution works perfect and we could reuse most of the applet code.

How to run a Java console application that uses Sockets in the cloud?

I can't seem to find a simple way to get my Java console app in the cloud. I thought it would be as simple as uploading it. I'm willing to pay money of course. My console app just takes data from the client, computes some stuff, and sends it back to the client. Is there any way to put my Java console app in the cloud? If not, what's the easiest alternative?
In order to run a java application on a server you will need to setup a server for java applications to run on.
Personally I do this with Tomcat and then when I want to access my application I go to the url of my server and then add the port to the end of it,
http://www.example.com:8080
If you go Here
You can follow along with a nice tutorial walking you through this on a RHEL server.

View running application output in the browser, how?

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&parameter2=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.

How to create voice chat in web browser with java

I want to create a voice chat which runs on the web browser.
The basic idea is that when I run the server.jar file, it will listen to a socket for connection, and when I type the ip and port on another computer on web browser(ex. 1.1.1.1:8082), the server will accept the connection and display an voice chat applet. Server.jar should contain all voice handlers. For example, if we have three computers, one with the server running while other two has web browser applet running and connected to the server, user1 talking will transmit over to the server, which then transmit over to user2.
So far, I have the applet and the server, but I am having trouble using the web browser to open the applet. It seems I need to use servlet and apache tomcat for the server side to make this work.
Can anyone confirm that I need to use servlet and apache tomcat to achieve this? Or can anyone suggest a better way to approach this project?
if it's peer-to-peer, everything can be written inside the applet.
Oh and as far as i know, there is no java voip libraries so you're going to have to port one from a C/C++ library or write it yourself.

Hardware support from a web application

I have a web application running with support for some specific pieces of hardware. This is achieved in the following steps:
User runs a small installer that places java files (and a couple
others) on the client machine. The main piece is a jar called "hardwareManager"
User visits web app. The web app runs a java applet which, due to
a .java.policy file placed during the install, has permission to
interact with the client machine outside the browser sandbox.
The applet checks to make sure the hardwareManager is running,
and if not runs a command to start it.
User interacts with the web app which sends commands to the applet via
javascript. The applet then writes commands to a text file
on the client machine. The text file is constantly monitored by the
hardwareManager which runs any commands it reads in.
This works, but seems clunky. I have a couple ideas on how to improve it, but I don't know which, if any, are even worth trying.
Would it be better to set up the hardwareManager as a socketServer and have the applet connect directly to it, rather than going through text files? Is that even possible?
Is there a way to eliminate the applet altogether and have the javascript talk directly to the hardwareManager? Maybe by writing the hardwareManager to be a local http server? What port should it run on? Do javascript xss limitations fit in here somewhere?
It would be less clunky to start the Java application using Java Web Start. This would remove the need to daemonize or install the Java hardware manager.
Another alternative is to use a built-in browser inside Java. I supose this is not an option, since you depend heavily on Javascript (I suppose to provide a rich client experience).
If you already have to install something on the client machine, why did you make the choice to go with a web application?
Talking from experience: We had a Java EE application which needed to print to PoS printers at the client site. We installed a small "synchronizer" application that connects through SSH and synchronizes all clients files. Afterwards, it loads the JAR and executes the program. This program connects through RMI with the server and subscribes to a JMS queue to receive the print assignments.
Applied to your case: Why not let your Java application connect to the server directly? You can use HTTP, SOAP or even JMS over RMI. You can then launch the hardware command from the server (instead of from the limited JavaScript webbrowser environment). This way, you get tons of features: authentication, buffering of commands, and you can even share hardware between multiple clients.
Schematic:
<----AJAX------> Web browser
ApplicationServer
<---HTTP/SOAP--> Java hardware manager application
You can launch the Java application using Java Web Start, which allows you to update the application automatically (instead of needing to pass every client a new installer).

Categories