HttpSessionListener interface implementation by Tapestry5 component
Hi everyone, When a user logs out I want to remove it from my online_table. This can happen in two ways: 1. The user clicks LOGOUT link and I remove him from the online_table and invalidate his session. 2. The users simply closes the browser, in which case I am unaware that he left and the session will be invalidated by the container after a certain interval. In case 2 however, when the container disposes of the session I want to capture it and based on it's attribute, remove the user from the online_table. I'm using Tomcat so I do this by implementing the HttpSessionListener interface in one of my components. This component is a Layout component that I use to wrap around my pages. When the container kills the session it correctly invokes my method: @Inject private OnlineUsersControler onlineUsersControler; @Override public void sessionDestroyed(HttpSessionEvent arg0) { onlineUsersControler.removeUser(//get user credentials here); - it throws NULL POINTER because the onlineUserControler has not been instantiates by the @Inject annotation } As you can see the OnlineUserControler is a Tap5 service. It looks like when Tomcat invokes my sessionDestroy method, Tap5 does not also fulfill the @Inject contract. I guess it happens because the page get's called by Tomcat and not Tap. Is there a way for me to force Tap to inject my service? Any other work around idea is welcomed. I have even went so far as to putting a finalize method in the User object to be removed and calling System.gc() on sessionDestroy ( i know ridiculous ). Thank you, Bogdan. -- View this message in context: http://tapestry.1045711.n5.nabble.com/HttpSessionListener-interface-implementation-by-Tapestry5-component-tp5572413p5572413.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: HttpSessionListener interface implementation by Tapestry5 component
On Fri, Mar 16, 2012 at 1:28 PM, bogdan_cm bogdan.iva...@rbccm.com wrote: When a user logs out I want to remove it from my online_table. This can happen in two ways: Is there a way for me to force Tap to inject my service? Any other work around idea is welcomed. I have even went so far as to putting a finalize method in the User object to be removed and calling System.gc() on sessionDestroy ( i know ridiculous ). Which security package are you using? The latest, not-yet-released tynamo.org's tapestry-security publishes an Authenticator service that allows you to register listeners for authentication events (onSuccess, onFailure, onLogout). Kalle - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: HttpSessionListener interface implementation by Tapestry5 component
Are you sure you're using the instance that Tapestry created? If you registered your HttpSessionListener via your web.xml then Tomcat is creating the instance. In this case you want to grab the instance of Registry stored in the ServletContext. http://tapestry.1045711.n5.nabble.com/Hello-Can-anyone-tell-how-to-use-servlet-session-Listener-with-tapestry-IoC-services-tc3396643.html#a3399525 @Override public void sessionDestroyed(HttpSessionEvent se) { //Get Tapestry IoC Registry Registry registry = (Registry)se.getSession().getServletContext().getAttribute(TapestryFilter.REGISTRY_CONTEXT_NAME); OnlineUsersControler onlineUsersControler = registry.getService(OnlineUsersControler.class); onlineUsersControler.removeUser() } On Fri, Mar 16, 2012 at 1:28 PM, bogdan_cm bogdan.iva...@rbccm.com wrote: Hi everyone, When a user logs out I want to remove it from my online_table. This can happen in two ways: 1. The user clicks LOGOUT link and I remove him from the online_table and invalidate his session. 2. The users simply closes the browser, in which case I am unaware that he left and the session will be invalidated by the container after a certain interval. In case 2 however, when the container disposes of the session I want to capture it and based on it's attribute, remove the user from the online_table. I'm using Tomcat so I do this by implementing the HttpSessionListener interface in one of my components. This component is a Layout component that I use to wrap around my pages. When the container kills the session it correctly invokes my method: @Inject private OnlineUsersControler onlineUsersControler; @Override public void sessionDestroyed(HttpSessionEvent arg0) { onlineUsersControler.removeUser(//get user credentials here); - it throws NULL POINTER because the onlineUserControler has not been instantiates by the @Inject annotation } As you can see the OnlineUserControler is a Tap5 service. It looks like when Tomcat invokes my sessionDestroy method, Tap5 does not also fulfill the @Inject contract. I guess it happens because the page get's called by Tomcat and not Tap. Is there a way for me to force Tap to inject my service? Any other work around idea is welcomed. I have even went so far as to putting a finalize method in the User object to be removed and calling System.gc() on sessionDestroy ( i know ridiculous ). Thank you, Bogdan. -- View this message in context: http://tapestry.1045711.n5.nabble.com/HttpSessionListener-interface-implementation-by-Tapestry5-component-tp5572413p5572413.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: HttpSessionListener interface implementation by Tapestry5 component
Thank you both very much for replying. It solved my problem. Bogdan. -- View this message in context: http://tapestry.1045711.n5.nabble.com/HttpSessionListener-interface-implementation-by-Tapestry5-component-tp5572413p5572656.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org