Can we make communication between Jnlp and Browser? - java

I am invoking applet through JNLP from my application (which is hosted on tomcat server) and it is working fine. Now from applet I need to send the response back to the application or browser.
In my search, I found that we can do this using web socket. But not sure from where to start.
Can you please let me know any idea on this.

I think you need some kind of push notifications. One way of doing this as you already mentioned is with websockets and there are bunch of tutorials on the web as well as a question here on stackoverflow How to implement push to client using Java EE 7 WebSockets?
The second way is with server polling (frequently sending requests and checking for new events/states/subscribers etc.)

Related

How to send targeted push notifications to a specific client?

I just got started with Java Web Application Development and I've been developing a Web Application with Java Servelts using Apache Tomcat where customers can book appointments with hair stylists. Now I want to add a feature where stylists are notified by a push notification in real time once a client makes an appointment. I did my research and I found out the following ways:
Long Polling
Server Sent Events/ Event Source
Web Sockets
Since the necessary communication is asynchronous from the server, I feel that the Server Sent Events would be the right choice.
I came up with an idea where the book event generates a notification which is stored in a separate table. A thread monitors the data source for any new notifications and notifies the targeted receiver once a new nofication is found.
The issue I am facing here is how to identify the necessary active client out of several clients and target the data to it.
I've been looking everywhere in the internet and I couldn't find any Java Servlet and Tomcat implementations for reference.
Is it possible to implement my idea using just Servlets in a Tomcat container?
If there is a better approach to this problem, please let me know.

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.

Sending and receiving data from an Android application to a web hosted Java application

I've been looking around all morning, and can't seem to figure this one out. I know it's not as complicated as I think it is, and all I need is just some pointers to the right direction.
I have an Android application that takes some user input, sends it to a Java application over the web, and then receives some output based on the input.
My Android and Java applications are ready, but how do I go about sending and receiving the data over the web? I understand that I'll be sending and receiving HTTP requests, but my problem is where I'll be sending them and receiving them from. Do I host my Java application on a Servlet like Tomcat, or do I use something like OpenShift to host my application for me?
I have no trouble with sending some HTTP request from my Android application to the web and receiving some output back, but my problem is that my web service needs to use a Java library to process the input and generate the output. I'm just not sure how I'm supposed to get this data to and from this Java library that needs to be hosted on the web.
I hope my question makes any sense.
EDIT: Perhaps I wasn't clear with what exactly I need help with. I do realize that the architecture I use doesn't really make any difference, but the problem I have is with how I'm supposed to use this architecture.
Let's say I have a registered domain name that I can easily send to and receive data from using my Android application - no trouble with that. But how am I supposed to integrate my Java library with this server? Do I just create an applet and put it on my server? Does my web host even allow Java applets to run?
I guess my question is how I'm supposed to get through the "barrier" between my HTTP request / transport layer protocol and my Java application.
Server architecture usually does not matter. You can use Java, NodeJs, Rails, Python, .NET, etc. You just need an endpoint that accepts a HTTP POST/PUT/GET/DELETE/PATCH verb.
This is more a question of "how do I set up a server to accept input" and its a very large topic in itself. I would advise you look at PAAS solutions like:
Parse.com
Kinvey.com
You can use their tools to build a solution fairly quickly. If you need something custom you'll need to build your backend in the language of choice and host it online via AWS, Google Cloud, Heroku, a VPS or something similar.

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.

Async data fetching from Java WebService

I'm implementing a client-server GPS application. Client side is a J2ME midlet that sends GPS location via HTTP/XML to a Java Webservice (Tomcat servlet). The servlet stores positions in SQL database. The other client app is a web browser that can login and see the actual position of midlet using Google Maps. This client is written using GWT. All is deployed on the same Tomcat container. Now I'm wondering how to dynamically update current position in webrowser Google Maps of the mobile so that the client can see how the mobile moves. How to do it in GWT - should I create a timer object in GWT client and asynchronously send HTTP request to server for getting the actual positions? Or is there any mechanism in AJAX/GWT to notify client (web browser) about the data update?
Thanks
Dominik
Regardless of all the talk about "push", the standard HTTP model is still one where the client has to ask the server for updates.
In a GWT app, you should use the well-supported Ajax functionality to request small-granular updates (polling, I guess) from the server at regular intervals (5 seconds, maybe?) and use the newly obtained information to update your map info.
There is a detailed article on the GWT incubator web site about Server Push and how to achieve it with GWT. From the article:
Explains Server Push, sometimes known as 'comet', and how you can achieve this with GWT.
Then, if you take a look at the comments, you can find interested related information and open implementations as gwt-comet, GWTEventService ...
I agree with rok.
If your deployment is going to be small enough to be able to support one permanent connection per web browser client go with Server Push/ Hanging RPC/ Long Polling or whatever you want to call it.

Categories