DontPushOzoneLayer - WebApplicationContext class cast issue


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(
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.writeAjaxPage(
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.eclipse.jetty.servlet.ServletHolder.handle(
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(
at org.springframework.web.filter.OncePerRequestFilter.doFilter(
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(

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)) {

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?

David E.