Converting JavaScript functions to Java remote method interfaces

Experience:

A while back, I was involved in developing a Java Server-Client application for building automation purposes. Initially, we used Java RMI to connect the server and client but soon realized that utilizing JavaScript for the client side would be more advantageous for various reasons.

Since RMI didn't work between JavaScript and Java, we opted for WebSockets for establishing a near real-time connection. This was approximately 3 years ago when WebSockets were still in beta stage with minimal documentation and incomplete functionalities. To bridge this gap, I devised my own JSON-based RMI protocol where incoming JSON objects from the client were deserialized and processed by my server application using java.lang.reflection to execute the desired methods.

Fortunately, the system worked efficiently as I designed it to be quite flexible, allowing dynamic insertion of subclasses at runtime without compromising functionality.

Inquiry:

I have always pondered whether there exists a standardized approach to integrate Java with JavaScript similar to RMI (maybe extending an interface and accessing these methods via JavaScript). Surely, I can't be the only one grappling with this challenge.

About Me: As an electrical engineer by profession, my knowledge of Java, JavaScript, and web technologies is mainly self-taught. While I am well-versed in Java concepts, JavaScript is relatively new territory for me.

Answer №1

To facilitate asynchronous communication between client and server, various frameworks are at your disposal such as Atmosphere, Spring Reactor, DWF, and Spring Websockets.

These frameworks typically include a client-side JavaScript file that acts as an intermediary for server-side methods. By preventing the request-response cycle from closing in the browser, they continuously send empty messages to maintain an open connection and keep data synchronized.

Additionally, there are proprietary APIs like Pusher available in the market for achieving similar results.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Eliminate PHP method for removing JSON object name based on index

I put in a lot of effort to ensure that my title makes sense haha. Here is the JSON that I have: [{ "0": { "id": 130427, "created_at": 1512521776301, "updated_at": 1512549188911, "category": 0, "platform": 6, ...

When a div is modified through an ajax function, I aim to activate a JavaScript function

Is there a way to automatically execute a javascript function once the status updates to "Upload successful"? I am uncertain about how to accomplish this task. Following a multi file upload, the status will switch based on whether it was successful or en ...

What is the best way to customize the appearance of an XML snippet using Greasemonkey?

I am attempting to customize an XML fragment retrieved from a server response using a Greasemonkey script. Take a look at this sample XML fragment from w3schools.com: <note> <to> Tove</to> <from>Jani</from> <heading ...

What is the best way to use jq to reverse a map and generate lists for repeated values?

Suppose I have a JSON map structured like this: { "a": "1", "b": "3", "c": "2", "d": "1" } Is there a way to reverse it and generate lists for duplicate values? This w ...

Issue with CSS: 200vw not scaling correctly for mobile devices

I'm attempting to create a horizontal slide effect between two div elements, so here is the HTML code: <div id="container"> <div class="viewport-1"> <div class="inner-div"> <h1>Viewport background 1</h1></ ...

Sveltejs template not displaying on M1 MacBook Air after running - stuck on blank screen

Currently, I am in the process of learning Sveltejs and have been utilizing for the tutorial, which has been quite effective. However, I decided to work on developing and testing Sveltejs applications locally on my MacBook Air M1. I downloaded the provid ...

Mobile Devices Experiencing Issues with Proper Resizing of Three.JS Panorama

I'm currently working on a project using Three.Js and its device orientation library to create a panorama that users can navigate by moving their phones. Initially, everything looks great as intended: Proper Panorama However, upon refreshing the pag ...

The error message thrown is: "Unable to assign headers after they have already been sent to the client."

I've been attempting to make a GET request, but it keeps failing at the app.js res.json line. app.js app.use(function(err, req, res, next) { res.locals.message = err.message; res.locals.error = req.app.get("env") === "development" ? err : {}; ...

Populating a Dual ListBox with JSON data

I'm currently using a dual listbox control from and am attempting to populate it with information retrieved from a JSON request. Initially, I populated the Duallistbox using a VB sub like this: Public Shared Sub GenerateDropDownListAndValues(dt As ...

Prevent a link from loading twice in jQuery's load() function if the parent page already

I am currently working on a page where data will be loaded into a lightbox using jquery. //index.php <script type="text/javascript" src="/jquery-1.11.0.min.js"></script> <a href='login.php'></a> //this will load ...

Is it okay to incorporate this code into the existing plugin?

My plugin, known as "pluggable," has the ability to take any element with the class .plugin and inject the following markup into it: <span class="colorable">color me</span> Below is the original markup containing elements with the class "plug ...

Error encountered in ES6 destructuring syntax

Could you please assist me in figuring out what is causing the issue here: var foo = { bar: 1, baz: 2 }; var { bar, baz } = foo; I encountered an error SyntaxError: Unexpected token {. I am using node v5.4.1 and I am unsure if the problem lies wit ...

Utilizing socket communication to convey data between devices in an Android application developed in Eclipse by transmitting

I have a unique idea for an app that involves sending messages directly to a specific mobile phone that has the same application installed, using the IP address of the recipient. I already know the IP address of the receiver, so there's no need to sea ...

Examine the state of each element within a div separately

I have a div containing elements with the class 'container'. Each of these container elements has multiple child divs with the class 'children'. I am looking to perform an action on the child divs when they become visible in the viewpor ...

Customize Jackson ObjectMapper configuration for specific POJO classes

One of the challenges I am facing is with my object mapper's initialization: this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); However, there are certain POJOs where I need their null value fields to be included. I have att ...

What is the process for incorporating a script function into a React application?

Recently, I've been attempting to integrate the external application Chameleon into my React application. To achieve this, I need to incorporate the javascript function within my application. I prefer it to be invoked only in specific scenarios, so I ...

Design a logo to serve as the main button on the navigation bar of the

I've been experimenting with adding a logo instead of the 'Home' text in my navigation bar, but I'm not sure where to implement it. Should I add it within #nav or separately? Also, I want the nav bar to stay fixed without overlapping on ...

Calling Ajax inside each iteration loop

I have encountered numerous posts discussing this topic, but the solutions I came across do not quite suit my needs. Some experts suggest changing the code structure, however, I am unsure of how to go about doing that. What I desire: 1) Retrieve a list ...

What could be causing the return statement to malfunction in this recursive function?

Given a pre-sorted array of ascending integers: int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9 }; The goal is to create a program that recursively searches for a specific integer in the array - let's call it "gesucht" - and returns its position. The ...

Completing the pledge using ionic/ui-routing

I've encountered an issue with my promise not resolving as expected while using Ionic/ui-routing. This is the structure of my service: return { all: function () { $localForage.getItem('foo').then(function (bar) { re ...