Vaadin and session scoped Spring beans

Hi,

I integrated Spring framework into a Vaadin application using Option 3 from http://vaadin.com/wiki/-/wiki/Main/Creating%20JEE6%20Vaadin%20Applications document (Application and other components are created as session scoped Spring beans).

I have a problem with ?restartApplication URL command (probably AbstractApplicationServlet.closeApplication method respectively) and Application.close() method as these methods are not invalidating sessions but only unregistering Vaadin Application from it. This works for Applications instances, but it keeps Spring session scoped beans in chaos - because HttpSession is left intact, Spring beans are not recreated but reused.

How can we solve this? I don’t know if there is a simple way how to invalidate all session scoped Spring beans in an application context, maybe just invalidating HttpSession would be simplier?

I tried calling:

((WebApplicationContext)getContext()).getHttpSession().invalidate();

in Application.close() method as mentioned in this forum post: http://vaadin.com/forum/-/message_boards/message/50778?_19_redirect=/forum/-/message_boards/search%3F_19_redirect%3D%252Fforum%26_19_breadcrumbsCategoryId%3D0%26_19_searchCategoryIds%3D0%26_19_keywords%3Dclear%2Bsession, but it throws an Exception:

java.lang.IllegalStateException: invalidate: Session already invalidated

Thanks,
Regards,
Pavel Arnost

Any luck with this issue?

Instead of ?restartApplication in URL, I have used logout() method as mentioned in second referenced post, it works well.

The logout() method is doable but it would be nice to be able to use the ?restartApplication and/or ?closeApplication.

There should be a hook to support closing a session (or not if desired) on close/restart. I tried to invalidate the session on Application.close() and on AbstractApplicationServlet.getNewApplicationand both result in internal vaadin failures similar to what is described above because it expects the session to be valid.

From Vaadin 6.7.6


    private void closeApplication(Application application, HttpSession session) {
        if (application == null) {
            return;
        }

        application.close();   <- invalidating session here cause problems ahead
        if (session != null) {
            WebApplicationContext context = getApplicationContext(session);
            context.removeApplication(application);
        }
    }

Here’s what happens when invaliding session on AbstractApplicationServlet.getNewApplicationand


11:50:58,072 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web]
.[default-host]
.
[/textura.test].[com.textura.web.p
qm.PqmApplication$Servlet]] (http--127.0.0.1-8080-3) Servlet.service() for servlet com.textura.web.pqm.PqmApplication$Se
rvlet threw exception: java.lang.NullPointerException
        at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.getExistingApplication(AbstractApplicationServlet.j
ava:2220) [vaadin-6.7.6.jar:6.7.6]

        at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.findApplicationInstance(AbstractApplicationServlet.
java:769) [vaadin-6.7.6.jar:6.7.6]

        at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:456) [vaadi
n-6.7.6.jar:6.7.6]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.