REST service notify a JSF WebApp - java

I'm searching a notifications system where my webservice REST can notify my JSF WebApp and reload some data and display them dynamicaly.
For more precisions,
I have a entity SANDWICH_SHOP, and user can add a COMMAND for a SANDWICH_SHOP with his mobile (on an native application)
If the sandwich shop is connected on the WebApp, he can see all commands of his SandwichShop, and i would like that datatable where all command are display automaticaly reload and display the news datas.
I tried a system with a servlet in my webapp, when the POST is done on the webservice, a request is made to my servlet, and i found the bean with the session and reload data. But it doesnt work cause HttpSession wasnt the same so i couldnt get my bean in my servlet (my bean was SessionScoped)
What's the best system i can use for this problem ? JMS ? WebSocket ? Thanks

If you're looking for (near) realtime updates to any (or all) connected clients, then WebSockets would be a good solution to this (assuming the clients are web based). You can push a notification from the server out to any connected web browser client.

Related

Two instances of tomcat running same application create same sessionId for different users(?) [duplicate]

One of our Spring MVC web application is deployed on multiple web servers with tomcat 7 and LB is at front to balance and distribute the requests to appropriate tomcat server.
Problem with this web farming is each tomcat server is able to store and retrieve its own HTTP session, but LB can send requests to any one of web server. So if a user is served for login page through tomcatServer1 then it's HTTP session will be created on it's respected server and it may happen that for second request of dashboard page LB sends it to tomcatServer2 where HTTP session is not available, resulting user is again redirected to login page.
To overcome this,
we are using "Sticky Session" property on LB, so that if a user (HTTP session + user's public IP) is first time served from tomcatServer1 then it will get bound to that server. Setting "Sticky Session" is not helpful as it's not utilizing all servers equally.
Another way is, develop our own session state server and deploy on a server then all server should communicate to that server for storing and retrieving session object/data.
Providing custom SessionManager to Servlet Container.
About #2, If in case we able to develop state server then also I have to modify the code to related to HttpSession.setAttribute() and HttpSession.getAttribute(). So question is, is it possible to override implementation of HttpSession for methods setAttribute & getAttribute? Also About #3, I don't know whether this solution will provide distributed state session server?
I developed session state server for tomcat using python.
Due to this I don't need to change the code already written for creating/accessing and destroying session. Also as there is separate server/service which is handling and storing session so not master cluster is needed.

Distributed HTTP session state server for tomcat

One of our Spring MVC web application is deployed on multiple web servers with tomcat 7 and LB is at front to balance and distribute the requests to appropriate tomcat server.
Problem with this web farming is each tomcat server is able to store and retrieve its own HTTP session, but LB can send requests to any one of web server. So if a user is served for login page through tomcatServer1 then it's HTTP session will be created on it's respected server and it may happen that for second request of dashboard page LB sends it to tomcatServer2 where HTTP session is not available, resulting user is again redirected to login page.
To overcome this,
we are using "Sticky Session" property on LB, so that if a user (HTTP session + user's public IP) is first time served from tomcatServer1 then it will get bound to that server. Setting "Sticky Session" is not helpful as it's not utilizing all servers equally.
Another way is, develop our own session state server and deploy on a server then all server should communicate to that server for storing and retrieving session object/data.
Providing custom SessionManager to Servlet Container.
About #2, If in case we able to develop state server then also I have to modify the code to related to HttpSession.setAttribute() and HttpSession.getAttribute(). So question is, is it possible to override implementation of HttpSession for methods setAttribute & getAttribute? Also About #3, I don't know whether this solution will provide distributed state session server?
I developed session state server for tomcat using python.
Due to this I don't need to change the code already written for creating/accessing and destroying session. Also as there is separate server/service which is handling and storing session so not master cluster is needed.

JSF to send request on local machine on live application

We are doing university project in JSF 2.2 with primeface framework. We want to develop the application which is hosted on live server but the request needs to be sent on local machine from which user is accessing application. This might be stupid question but I would like to know if there is any possibility where we can do such implementation.
For example: We will host application 'www.somesite.com' on server, in this application we will have multiple forms, but we want this forms to be submitted to user local machine where we will deploy required component/service which will take the input from user and also send required response to user. It means, the view will be render from host server but data will be bind from local machine.
One way to do this is, when user submit form, we will send the request to host server and from server we will send data to user local machine where we will deploy required component/service which will be listening to server request/response, but we want to eliminate this layer and want to send direct request to user local machine as soon as user submit form
I would appreciate if you can help us....
If I understood well your request you need to change the action of the form to be able to send the request to a localhost.
I think the only way to do so is to use a pure html form and not a h:form. With an html form you can set the action attribute to a localhost.
JSF form with URL action?
But in this case you can have problem to use the jsf component, you will have a jsf warning (with javax.faces.PROJECT_STAGE set to Development)
The form component needs to have a UIForm in its ancestry. Suggestion:
enclose the necessary components within
see here for BalusC explanation

How does Java web-app with #SessionScoped Bean know if browser is re-started?

This is a pretty basic question. I'm learning from a textbook about JSF web apps, and using a #SessionScoped Bean to manage the session. The book mentioned that if you close the browser, the session ends, and this was easy to verify with testing. But I am not sure how the web app is informed that the browser has been closed and re-opened. I couldn't find any cookies stores locally. So how does the web app get this info?
Thanks!
It's a Session Cookie that does the magic.
In fact when you arrive to any web page of your application, you start an http session. Then your browser stores a sessionId used as identifier for following requests.
So when the browser is closed, there is no way that your application knows about that.
The only way to finish the session from the server side is by setting up a timeout in the web.xml.
When there is no request form the browser before the timeout is triggered, then all the methods in the managed beans of this session annotated with #PreDestroy will be called and then everything will be cleanup in the server side.

Flex Inheriting Logged in User

I am trying to secure my Flex application within my Java web application. Currently my Java web application, handles logging and managing user accounts and the like. I was wondering if there is a way to essentially share that user credentials with the Flash movie in a secure mechanism? For instance, if you log in, we want you to be able to save items in the Flex application for that user, only if that user is logged in of course. Any ideas? Any help is greatly appreciated.
Update:
I apologize for the vagueness. I'm running Tomcat 5.5, Java 6 doing portlet development inside a Vignette Portal. All data communication is via Blaze DS. In our environment, we have data services and the portal handles logins, user management and the like. Currently we are simply passing down the username to the flash movie, which I don't feel is very secure.
You can pass data to a flash movie using flashVars which can be generated in a JSP. The data can be a one-time key generated on the server and associated with a user id. The Flex application can then take the key and use it to log in via a webservice call. The server will then validate the key and allow access to the user's account.
It is a very general question and it's hard to provide a good answer without knowing what is your current architecture. The Flex application is using the same web server as your web application? What are you using in order to discuss with the backend (web services, sockets, rtmp sockets)? If you are sharing the same web server you can access the same HTTP session and you can check if the user is logged in or not.
If you need to be aware in your Flex application that the user has just logged off from the HTML application or the session has expired you have several options, again depending on your architecture. Assuming that the HTML application was already was notified you can call through ExternalInterface a method from the Flex application. If not (session expired while you are using the Flex application) you will know when trying to save your data.

Categories

Resources