DontPushOzoneLayer - WebApplicationContext class cast issue

Hi,

I’m currently developing an application where the primary navigation is via the Spring MVC framework but when some more complex data operations are required it then jumps off into a couple of different Vaadin app’s, one of which is a DontPushOzoneLayer app. However, I have a problem that occurs when a user first starts a standard Vaadin app and at some later point in the session then navigates to the DontPushOzoneLayer app for the first time. When this sequence occurs we get the following exception being thrown (snippet only);

java.lang.ClassCastException: com.vaadin.terminal.gwt.server.WebApplicationContext cannot be cast to org.vaadin.dontpush.server.DontPushOzoneWebApplicationContext
at org.vaadin.dontpush.server.DontPushOzoneServlet.writeAjaxPageHtmlVaadinScripts(DontPushOzoneServlet.java:83)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.writeAjaxPage(AbstractApplicationServlet.java:1781)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:540)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:648)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1336)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)

This basically occurs because the standard Vaadin app creates its default WebApplicationContext instance and stashes it within the Users session object and when the DontPushOzoneLayer apps tries to start at a later point, it gets a copy of this vanilla WebApplicationContext object instead of creating its own specific DontPushOzoneWebApplicationContext object.

As a hack, I’ve solved this for my current needs with the following code placed within the relevant Spring Controller class just before the DontPushOzoneLayer app is launched for the user;

            // This is required in case another Vaadin application has been started which is not a DontPushOzone application.
            WebApplicationContext ctx = (WebApplicationContext) request.getSession().getAttribute(WebApplicationContext.class.getName());
            if (ctx != null && !(ctx instanceof DontPushOzoneWebApplicationContext)) {
                request.getSession().removeAttribute(WebApplicationContext.class.getName());
            }

This is working ok for now but what I would like to know however is whether there is a better and more elegant way of solving this (possibly via configuration, class extension, method overloading or some other way) that I may not have considered that might also be a better long term solution than the hack I’ve used above?

Regards,
David E.