Transferring information straight from the web browser to a Java desktop program

I'm developing a web application using TypeScript for client-side scripting. I am utilizing technologies such as Spring Boot, PostgreSQL, and Angular. My goal is to allow my existing Java desktop application, completely independent from the web app itself, to receive data sent from the website when a user clicks a button. The desktop app will then prompt the user to import this data.

I am seeking advice on how to achieve this. Are there any examples or sample code available?

Is it possible to set up a listener server in my desktop application that can accept data payloads from clients (browsers) in a way that is platform-independent?

It's important to note that this process is distinct from downloading data from an internet source as the user should trigger the action from the browser interface, not the desktop application itself.

Although I've explored registering my Java desktop app with a custom URI scheme, this solution only works for Windows and simply launches the app with specified parameters rather than meeting my requirements.

Answer №1

Here's how I see your setup:

Your browser communicates with a SpringBoot application over HTTP/HTTPS through the internet.

You need to make a local desktop application interact with a webpage that is displayed in the browser.

To achieve this, you can create an HTTP connection between the webpage and the desktop application using the following steps:

  • Your desktop application should have an embedded servlet container like Undertow, which binds a server socket to 127.0.0.1:yourPort.
  • The embedded servlet container needs a CORS Filter because the origin of the webpage is different from 127.0.0.1.
  • The webpage can establish a connection using XMLHttpRequest, for example:
    
    var req = new XMLHTTPRequest();
    req.open("POST", "<a href="http://127.0.0.1:yourPort" rel="nofollow noreferrer">http://127.0.0.1:yourPort</a>");
    req.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    req.send("payload="+ myPayload);
    

If the browser establishes a HTTPS connection with the SpringBoot server, you may encounter a "Mixed Content Warning" since a secure web context (your webpage) is accessing a resource via HTTP.

Modern browsers like Chrome, Firefox, Edge, and Safari now follow the W3C Secure Contexts working draft, which allows access to 127.0.0.1 without triggering a Mixed Content warning.

However, keep in mind that once you deploy this setup, your desktop application becomes susceptible to XSS attacks.

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

Can someone guide me on incorporating static methods into a Mongoose model using TypeScript for Mongoose version 5.11?

When using Mongoose 5.10, I implemented static methods in my Mongoose models with the following pattern: import { Schema, Document, Model, Connection } from "mongoose"; import { v4 } from "uuid"; export interface IFoo extends Document ...

Updating a subscribed observable does not occur when pushing or nexting a value from an observable subject

Help needed! I've created a simple example that should be working, but unfortunately it's not :( My onClick() function doesn't seem to trigger the console.log as expected. Can someone help me figure out what I'm doing wrong? @Component ...

Exploring the world of mouse events in Typescript using JQuery, all the while maintaining strict typing regulations

I'm currently working on a project that involves using JQuery in Typescript. One challenge I'm facing is passing a mouse event from a JQuery element to a wrapper class. Here's an example of what I'm trying to achieve: import * as $ fro ...

What is the best way to retrieve the current value of a variable from outside the setOnItemSelectedListener method?

What is my goal here? I am attempting to retrieve the value of the data member totalPrice outside of the OnItemSelectedListener where it gets updated inside the OnItemSelectedListener through the function populate(). Here is the code: MainActivity publ ...

The latest version of Reinforced.Typings, 1.4.0, is causing build crashes when upgrading from the previous version 1

Recently, I updated my C# 4.5.1 .NET library named "ViewModels" to the newest 1.4.0 version of the Reinforced.Typings library/tool using NuGet. This tool allows me to convert my C# code to .ts files. During the upgrade process, I chose not to overwrite th ...

Calculate the total number of tabs within the Tabhost container

Is there a way to determine the total number of tabs in tabhost so that I can use it in a loop? Also, how can I compare the tabId with the selected currenttab? I am facing difficulty in setting the visibility of an image view in the on tab change listene ...

Discrepancies between Angular components and services in Visual Studio

I'm currently enrolled in an Angular course for the second time, but this time I'm using Visual Studio instead of VS Code because I need to add a C# backend. Despite my efforts, I am still struggling with some unknown issues that I can't ev ...

When the date and 'variable' class are combined, it leads to a JsonGenerationException: BsonSerializer is specifically designed for use with BsonGenerator

Upon updating to Jongo 1.3.0, we encountered a new error when attempting to read documents from MongoDB: com.fasterxml.jackson.core.JsonGenerationException: BsonSerializer can only be used with BsonGenerator Further investigation revealed that the issue ...

Leverage the TypeScript Compiler API to verify whether an interface property signature permits the value of undefined (for example, prop1?:

Currently, I am utilizing the TypeScript Compiler API to extract Interface information in order to generate database tables. The process is functioning effectively, however, I am seeking a method to determine if certain fields are nullable, or as it is phr ...

Guide on retrieving the interface property name or key name as a string in Typescript

Currently, I am utilizing the API of Slack and encountering situations where I send JSON requests containing strings that return as property names later on. I want to create an interface where I can send one of its property names as a string and receive t ...

Updating my application to enable the passing of JobParameters to my Setup in Springbatch

My current setup involves a Spring Batch application structured like this: @SpringBootApplication @EnableBatchProcessing public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } ...

Changing the time in Angular while converting a string to a date object has proven to be

Can anyone help me with a problem I'm having trying to convert a String into a Date object without it being affected by timezone changes? Specifically, when I receive 2020-07-14T15:27:39Z from an http get request, I need to convert this into a Date o ...

Error: No routes found in Angular 5

I have developed an Angular 5 app and set up the following routing configuration in app-routing.module.ts file: import { ControlPanelComponent } from './dashboard/control-panel/control-panel.component'; import { MainComponent } from './dash ...

Error: The type '{ children: Element[]; className: string; }' cannot be assigned to the type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'

My current setup involves using Next.js and TypeScript While working in Visual Studio Code, I encountered an error message stating Type error: Type '{ children: Element[]; className: string; }' is not assignable to type 'DetailedHTMLProps&l ...

The type CustomModel[] lacks the property 'XYZ' in it

Using TypeScript v2.7.2 Check out the code snippet below: import { Component, OnInit } from '@angular/core'; import { Ingredient } from "../shared/ingredient.model"; @Component({ selector: 'app-shopping-list', templateUrl: ' ...

Look up the attribute in the parent node and retrieve the value of the child node's attribute

Simplified Version: Find attribute in parent node and retrieve attribute values from child nodes. Detailed Version: Within an XML file, I have the following snippet: <include template="directory/file.xml"> <param name="permission" va ...

Integrating Angular 2 with Java functionalities and JSP

Starting my journey with the Angular 2 framework, I recently dove into working with it. As I delved deeper, many questions began to surface. My initial step was creating an Angular project using the Angular CLI, which went smoothly. However, when I attem ...

Failure in Testing: ReferenceError indicating that SpeechSynthesisUtterance has not been defined

In a recent project, I decided to add text-to-speech functionality and opted for a plain JavaScript solution. (https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance) Currently, I am using [email protected] and [email protecte ...

When working with two dynamic lists in RichFaces, the a4j:ajax functionality may not be activated as expected

Here is the code containing an error: <h:form> <rich:select defaultLabel="Select region" value="#{StaticInfo.regionElegida}"> <f:selectItems value="#{StaticInfo.regiones.entrySet()}" var="region" itemValue="#{region.key}" itemLa ...

Is there a way to verify if the database has been successfully saved and the API call has been

I am currently in the process of developing a function that calls two other functions. Function 1 is responsible for saving an object to a database, while function 2 performs an API call. async createMSCalendarEntry(start: Date, end: Date, name: string ...