I know I don't have any code to show you guys, I am stuck at some point and I dont know where to start. I hope someone will help me.
I am developing a Spring MVC application, and I need to send a message to all active session users to execute a script which is available to all the clients as it is defined in a js file and included for every user.
I have looked around and found some frameworks which offers these type of functionalities like Atmosphere but I don't think it should be used in my situation as it is a big framework and the functionality required is very little. I have also gone thorough WebSockets but I cant find anything which would help me in invoking the script on client side for all the clients.
If someone can help me go to a right path or direct me to a similar example. I will be grateful
****Update****
I can also use polling if there is way that: if the controller gets a request the session should be considered idle during that, for instance, there is controller which is called every 5 minutes and in the session out time is 30 minutes. The session won't expire in this time if the controller used for polling is called every 5 minutes, I need to exclude the particular controller from calculating the idle time
No Polling Solution:
From what I gather, you need a Remote Procedure Call mechanism.
I would go with https://github.com/eriksank/rpc-websocket.
The general idea:
Your clients register themselves to your server process as "consumers".
When a message is ready, your server then goes through every registered "consumer" and sends the message which rpc-websocket can handle .
Polling Solution:
Here is a general idea, works if you have registered, logged on users.
Have a database table that stores messages, lets call it "messages".
Have a database table that keeps track of messages and users, lets call it "message_tracker". if a user has seen a message, there will be a row in this table for the messageId and UserID.
Have a javascript script poll a server url for new messages. What is a new message can be decided based on the database tables above.
If a new message is found, process it and then call another server url which inserts into the message_tracker database table
Related
Currently I'm working on a single page application with java/jersey running as my back-end. But at the moment I have some requests that take a while (over 10 seconds). I was wondering if its possible to send updates back to the client with jersey?
I wanna use like a status bar but I have no clue how far the request is without updates from the back-end.
I couldn't find anything about this topic searching on google/stackoverflow. Maybe I'm using the wrong search terms.
If you don't want to use websockets there are a few approaches you can take.
Provide API to client that takes clientId and optionally processId and gives status of the process running on server.
Then client can have Javascript to asynchronously call this API and update progress bar.
In addition you can have server side Jersey resource start long running process asynchronously and immediately return response with estimated time and processId.
I currently have the following situation:
I have build a client Java application, which used to communicate with the MySQL database directly. When I was inserting a lot of data, I used to do this with AutoCommit turned off. This was easy to do, because I had direct access to the Connection. I had chosen to do this, because it enabled me to rollback the changes when something went wrong during the synchronization.
Now, the application is evolving and I thought I would be better to build a server API which communicates with the MySQL database. So, at the moment, I am inserting data by doing Http requests. Each request opens and closes a new Connection.
Now, I would like to be able to rollback the changes when one of the requests goes wrong. I assume I can not work with AutoCommit, because this is based on a Connection, and that one is different for each request.
Can anyone tell me how this is done usually?
I have thought of the following:
First call an URL which sets the AutoCommit to false, and then do all the requests and check if one fails. But this would go wrong if another client is also inserting data at the same time.
Sending the data to the server with one request, but this would force me to alter my design drastically.
Note: I know some code is usually required when asking a question, but I can not see how this would improve my question. However, if it is needed, feel free to request it.
Every web request should run in it's own transaction.
Send all the data that belongs to a logical transaction in one request and call commit at the end of the request processing.
Spaning transactions accros multiple web requests is a bad idea. Think about crashing clients which never commit. This will leave you with open transactions that never close.
I am working on web based applications.
Server : Tomcat
Technology : Simple Jsp/Servlet/JQuery
I need to restart my server as an when new updates are there. And these changes are frequent almost every 1 or 2 day. I think to create some mechanism like I can say to every logged in user to save their changes and server will start in few minutes. (Timer will be there). Popup should be open though user is ideal.
Is there any direct way to do this so? Or I need to implement ajax call on every few seconds to server on every jsp page to check if any message is there on server???
Any idea will be appreciated.
Thanks in advance.
For the approach you are taking, I would suggest you to use Async Serlvets(Req. min Servlet API 3.0) or Apache Tomcat's comet technology(Kind of Async Servlet).
You will make ajax call on every page when it(page) loads(ajax onload() for eg.) to Async Servlet and will idle until response from server comes. This Async servlet should send Server Restart notification to all connected clients- whenever you trigger notification manually. Once ajax client gets notification, it will display the Warning(or user friendly message).
This will remove the need to make unnecessary polling to server after fixed internal - A big plus resource wise.
Personally I wont suggest this way, better get agreed on specific timeframe for deployment everyday(every two days) with clients and perform deployments in this time.
If you are from India- You must be aware about IRCTC website- Which is not available for train reservation every night for 1 hour.
I have a Spring MVC web application that is generating a report on the server, once the report is generated, I need to enable a button that allows the user to download it. I am not sure how to go about doing this.
I figured that I will have to spawn off a thread that will just keep checking for the existence of the file and use javascript (jQuery or prototype most likely) to handle the UI elements, but I'm just not sure how to tie these all together.
There are no threads in Javascript. Instead you'll set a timeout to do the polling. The polling would take the form of a URL that will respond with some sort of "ready" indicator when the file is ready. If the file is not ready, then the AJAX success handler will start another timeout. When the server says it's ready, your Javascript handler will make the button visible and no further polling will be necessary.
Check this example here http://forum.springsource.org/showthread.php?t=70489 and let know if it works
You could use some type of messaging on the server that tells the client when the file is ready e.g. we us a table for all report requests and the server writes the status into the table and the client is then asking for the status of the report job with an AJAX call every few seconds.
I need to implement SSO between a windows domain and a J2EE web appliction.
I've been thinking what the impact of this would be on the web application's session timeout. We have a 2 hour time out.
If we implement a seemless SSO, then I think it might become confusing for the user.
The SSO will make it appear that the web application is immediately available.
I'm worried that they will start filling in forms then go for lunch (or something) and come back after their session has timed out. However, it might not be immediately apparent that this has happened, since the SSO will just sign them on again (but now with a new session).
Has anyone any experience with anything like this and how to handle it? Do we just need to implement some form of extra messaging to tell the user that their previous session has timed out and their work has been lost?
I think you definitely need to pop-up an Alert box of some kind if the user's session is reset. Get them to click OK on the message and redirect them to the home page.
Also, I think a 2 hour timeout sounds like a bad idea if you're doing it how I think you are. Do you mean the user has 2 hours from when log in to work before their session times out? Wouldn't it make more sense to have something like 10 minute timeout but with the timer getting reset whenever the user sends a new request within that session.
The timeout is not a static fixed time measured from login but rather a dynamic measure of inactivity.
On sites we hav buit with this functionality after 10 minutes or so the web page goes back to the login page (JS used) and the user can start again if they want.
If they are busy with a long process where they are reviewing results or something then check the mouse move or some sublte key like that indicating they are still busy.
Old question, but in case anyone runs across it:
Try really hard to store no state in the server session. Client, fine; back-end server persistence (like a database), fine. Just nothing in between that would get lost. When the user is seamlessly re-authenticated, they don't notice the switch. Duration of timeout becomes irrelevant.
This answer is actually more feasible now, six years later, as there are several front-end frameworks that will store your data for you. You can still use Spring Security (say) on the server, as the authentication is still there with the new session; it should regenerate your security info (SecurityContext, UserDetails, etc.) on the fly. Whatever request gets or sends data should then "just work."