Java Spring: Real-time status update to the client over REST API - java

I am developing a web application in Java Spring where I want the user to be able to upload a CSV file from the front-end and then see the real-time progress of the importing process and after importing he should be able to search individual entries from the imported data.
The importing process would consist of actually uploading the file (sending it via REST API POST request) and then reading it and saving its contents to a database so the user would be able to search from this data.
How could I show the real-time progress of this process? I found a tutorial for jQuery, which shows the progress of amount of data uploaded/transferred, but as the most the work is done while processing the uploaded file, I thought I would like a solution where before the line processing I find out the amount of lines in the file and then the user could see a live message like:
Lines processed: 1 out of 10000
It could update/change incrementally, but as one line is processed pretty quickly, showing each number of lines processed is not that important.
Either way, the question is, what's the easiest way to send these messages from Spring REST API to the client?

I found a solution myself and used Web Sockets for that.
I used this approach from the Spring documentation:
https://spring.io/guides/gs/messaging-stomp-websocket/
It could help on sending the messages for each processed line to the front end listener (after the web socket topic/connection is started) but I used a different approach for the data import, I used batch insert so that was unavailable for me, but web sockets are capable of doing that.

Related

What is the technique behind live streaming from security camera to web pages when using Java?

I have done researches on Google, many posts and answers gave me ready-to-use packages or the example is not in Java. I am not looking for solutions to this question.
I want to understand how live streaming from security camera on the web pages can be implemented and in Java.
First of all, there is no video file recorded beforehand because it is about live streaming from security camera. But one should be able to watch the video later on as well.
My questions are:
Do I always need to record the video first and use that video on the web page so that video can be live-streamed and can be watched later on? Or live streaming and video recording/saving in a file can be in two separate processes?
Is WebSocket Server the only solution to push video data to the web browser continuously?
In case of WebSocket Server pusing video data to the web browser, what kind of data should be pushed to the web browser?
On the web page, must I use the <img> tag to show the live-streaming video?
Solution 1: From the post below, the Java WebSocket Server pushes the ByteBuffer object containing byte data to the web browser. But this solution first takes video data from the web browser (client), sends the data to the WebSocket Server and then just receives the converted version of data back. It is like a round trip.
https://javawebsocketsvideo.blogspot.com/
Solution 2: And this code sample shows that Java Server sends DatagramPacket object containing byte data to its client. But this solution works with existing video file (not live-streaming) and its client is not a web page.
https://github.com/ramanbuttar/video-streaming/blob/master/Server.java
That's why these solutions did not clear my questions.

Logging REST traffic in Java EE (or HTTP in general)

I had a look around for a Java solution to logging REST or HTTP calls in general in a Java EE environment to a database for later analysis but I haven't been successful so far.
My requirements are logging the request and response of course, including some meta data like the ip of the requesting side (client/server), the currently authenticated user and the status code. This should happen in way that you could search for this meta data in a efficient way so that there is not much stress on the database and you could build a log browser on top of it which can present you with results without being unresponsive even if there were several million log entries.
A nice to have would be that the log viewer is already there and does not have to be built.
Do I have to implement this myself or is there any solution that I could throw in?

How to return from a process to a frontend backend process?

I need load 10.000 rows in my database google cloud sql using AppEngine with Java. For this case, i use a proccess using backend, but i want advertise to user, how rows was wrong load? But, i don't know as send a message from my backend proccess to my front to show a message to screen.
Regards.
Maybe you don't need to send callback (from backend to front-end). Maybe you should make the front-end poll to see when these results are ready at the back-end side. Maybe through some JS/Ajax code which keeps polling on the background and once the results are ready, pulls them and displays them in the designated area of the page. I assume your front-end is a web page.

Periodically call of a Servlet from jsp page (Java)

I have a problem and i don't know how to resolve it...
I have 2 .dbf files with ~10000 records (geospatial informations) that i want to read from a jsp page, every time i read 200 records i have to send them to a servlet in some format (i haven't decided yet).
The Servlet must save every record as a Document object in Google Appengine (the limit of 200 records is specified by Appengine api's).
I can't upload the file to server and read server-side cause of some AWT classes not supported by Appengine, then i tried to read the files client-side and send to server the parsed records but i don't know how i can do this.
Someone have a solution to this problem?
jsp, once complied, is nothing but a servlet. That being said, you say:
I can't upload the file to server and read server-side cause of some AWT classes not supported by Appengine
Once you finish reading 200 records, why not insert it into the appengine from the jsp itself. The jsp will run on the server either way.

Post information to server and receive XML

On my web server I will be creating a custom XML file for a client app to access. This means I must authenticate the client and then give the client the XML file.
I believe the client application will need to post data (login, password) to the server and once a connection is established, it will receive the XML file from the server (most likely PHP).
If you have any advice, it would be most welcomed: particular classes to look at and any potential dangers.
I found something relevant in C#, however I am limited to Java as the app will be for Android.
Android lets you pull in external jar's, so I would use HttpClient for performing your POST operation with login info.((EDIT: Per Samuh in the comments, this is already a part of the android SDK, no need to include the external version))
Once you have the XML data in your application, you can parse it however you see fit. I would create a SQLite database for your application to store the data parsed in from the XML file. Then, when you run your app, (or the user clicks refresh), pull the XML file down, populate the SQLite DB with the data from it, and hook the UI controls to the database as done in the Notepad tutorial
The advantages of this setup are that you can always have a local copy to show the user if they are offline, and the user can quit, pause, or leave the app open or closed and not lose the information. You should implement both a refresh on demand and a regular refresh with Alarm's setInexactRepeating() so the application will update automatically in the background in a battery life maintaining way.
That should be enough to get you started.

Categories

Resources