Re: WebSocket Filter to open a Hibernate Session
Hi Martin, That's something I figured out as well, the bypassing of the Filters by WebSocket requests. I did as you said and implemented a custom IRquestCycleListener to respond on the onBeginRequest & onEndRequest in case there is a WebSocketRequest. This is working correctly now! Thanks for the pointer. One other question though, since this seems awfully similar to how OSIV works. If I do not filter on WebSocketRequest and allow the Session opening for each incoming request, in theory I should not need to apply the "OpenSessionInViewFilter" anymore correct? But then another thing I noticed... I set a debug point inside the onBeginRequest & onEndRequest to see what's is passing through those functions. Apparently for a single page request the onBeginRequest & onEndRequest are called multiple times while I have no Lazy Loading components on that page. My guess would be that those multiple requests are for the resources that needed to be loaded, e.g. images/js/css/whatever. In that respect, it would absolutely not be wise to use that to open & close hibernate sessions ;-) Upon a WebSocket event, the onBeginRequest & onEndRequest are called only once, so that's correct. Again thanks. Best Regards, Marco Springer On Tuesday 15 September 2015 18:06:51 Martin Grigorov wrote: > Hi, > > Servlet Filters are not used when sending messages in web socket > connection. This is how Servlets work at the moment. > > You can use Wicket's IRequestCycleListener's onBeginRequest/onEndRequest. > > Martin Grigorov > Wicket Training and Consulting > https://twitter.com/mtgrigorov > > On Tue, Sep 15, 2015 at 4:32 PM, Marco Springer wrote: > > Hi, > > > > Using normal requests and long-polling ajax timers to update an interface > > works fine with hibernate sessions. > > Now I'm trying to implement WebSockets to update small parts of a web > > application that come from server side events. I want to get rid of the > > long > > polling. > > > > For now I'm only using a @Scheduled annotation to broadcast an event to > > all attached clients. As a simple scenario. > > > > The web application should, in response, update with loading new data > > from a database using Hibernate. > > > > This is where it fails, giving the message: > > /Caused by: org.hibernate.HibernateException: No Hibernate Session > > bound to thread, and configuration does not allow creation of non- > > transactional one here/ > > > > I know this fails due to the fact that WebSocket events don't go through > > the normal filters, e.g. OpenSessionInViewFilter that I'm using. > > > > > > *My question:* > > Where can I create a hook where I can start the Hibernate Session the > > same way the OpenSessionInViewFilter does? > > > > If I'm totally off with my thoughts, I'd like to hear that too :) > > > > Used libraries: > > wicket 6.19.0 > > wicket-sprint 6.19.0 > > wicket-native-websocket-jetty9 6.19.0 > > hibernate 3.6.10-Final > > springframework 3.2.13-RELEASE > > (Why the old Hibernate/Spring versions: haven't had time to migrate yet, > > too much to do!) > > > > Thank you very much in advance. > > > > Best regards, > > Marco Springer
Re: WebSocket Filter to open a Hibernate Session
Hi, Servlet Filters are not used when sending messages in web socket connection. This is how Servlets work at the moment. You can use Wicket's IRequestCycleListener's onBeginRequest/onEndRequest. Martin Grigorov Wicket Training and Consulting https://twitter.com/mtgrigorov On Tue, Sep 15, 2015 at 4:32 PM, Marco Springer wrote: > Hi, > > Using normal requests and long-polling ajax timers to update an interface > works fine with hibernate sessions. > Now I'm trying to implement WebSockets to update small parts of a web > application that come from server side events. I want to get rid of the > long > polling. > > For now I'm only using a @Scheduled annotation to broadcast an event to > all attached clients. As a simple scenario. > > The web application should, in response, update with loading new data > from a database using Hibernate. > > This is where it fails, giving the message: > /Caused by: org.hibernate.HibernateException: No Hibernate Session > bound to thread, and configuration does not allow creation of non- > transactional one here/ > > I know this fails due to the fact that WebSocket events don't go through > the normal filters, e.g. OpenSessionInViewFilter that I'm using. > > > *My question:* > Where can I create a hook where I can start the Hibernate Session the > same way the OpenSessionInViewFilter does? > > If I'm totally off with my thoughts, I'd like to hear that too :) > > Used libraries: > wicket 6.19.0 > wicket-sprint 6.19.0 > wicket-native-websocket-jetty9 6.19.0 > hibernate 3.6.10-Final > springframework 3.2.13-RELEASE > (Why the old Hibernate/Spring versions: haven't had time to migrate yet, > too much to do!) > > Thank you very much in advance. > > Best regards, > Marco Springer > > >
WebSocket Filter to open a Hibernate Session
Hi, Using normal requests and long-polling ajax timers to update an interface works fine with hibernate sessions. Now I'm trying to implement WebSockets to update small parts of a web application that come from server side events. I want to get rid of the long polling. For now I'm only using a @Scheduled annotation to broadcast an event to all attached clients. As a simple scenario. The web application should, in response, update with loading new data from a database using Hibernate. This is where it fails, giving the message: /Caused by: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non- transactional one here/ I know this fails due to the fact that WebSocket events don't go through the normal filters, e.g. OpenSessionInViewFilter that I'm using. *My question:* Where can I create a hook where I can start the Hibernate Session the same way the OpenSessionInViewFilter does? If I'm totally off with my thoughts, I'd like to hear that too :) Used libraries: wicket 6.19.0 wicket-sprint 6.19.0 wicket-native-websocket-jetty9 6.19.0 hibernate 3.6.10-Final springframework 3.2.13-RELEASE (Why the old Hibernate/Spring versions: haven't had time to migrate yet, too much to do!) Thank you very much in advance. Best regards, Marco Springer