com.vaadin.server.communication
Class JSR356WebsocketInitializer

java.lang.Object
  extended by com.vaadin.server.communication.JSR356WebsocketInitializer
All Implemented Interfaces:
java.util.EventListener, javax.servlet.ServletContextListener

@WebListener
public class JSR356WebsocketInitializer
extends java.lang.Object
implements javax.servlet.ServletContextListener

Initializer class for JSR 356 websockets.

Websocket specification says that initialization of websocket end points should be done in the servlet context initialization phase. Some servers implement this strictly so that end points cannot be registered after the context initialization phase.

Note that WebListener is Servlet 3.0 API so this will not be run for older servers (unless added to web.xml), but these servers do not support JSR 356 websockets either.

Since:
7.5.0
Author:
Vaadin Ltd

Nested Class Summary
static class JSR356WebsocketInitializer.FakeServletConfig
          "ServletConfig" which only provides information from a ServletRegistration and its ServletContext
 
Constructor Summary
JSR356WebsocketInitializer()
           
 
Method Summary
 void contextDestroyed(javax.servlet.ServletContextEvent sce)
           
 void contextInitialized(javax.servlet.ServletContextEvent sce)
           
static java.lang.String getAttributeName(java.lang.String servletName)
          Returns the name of the attribute in the servlet context where the pre-initialized Atmosphere object is stored
static void initAtmosphereForVaadinServlet(javax.servlet.ServletRegistration servletRegistration, javax.servlet.ServletContext servletContext)
          Initializes Atmosphere for use with the given Vaadin servlet
protected  boolean isVaadinServlet(javax.servlet.ServletRegistration servletRegistration)
          Tries to determine if the given servlet registration refers to a Vaadin servlet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSR356WebsocketInitializer

public JSR356WebsocketInitializer()
Method Detail

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent sce)
Specified by:
contextInitialized in interface javax.servlet.ServletContextListener

initAtmosphereForVaadinServlet

public static void initAtmosphereForVaadinServlet(javax.servlet.ServletRegistration servletRegistration,
                                                  javax.servlet.ServletContext servletContext)
Initializes Atmosphere for use with the given Vaadin servlet

For JSR 356 websockets to work properly, the initialization must be done in the servlet context initialization phase.

Parameters:
servletRegistration - The servlet registration info for the servlet
servletContext -

getAttributeName

public static java.lang.String getAttributeName(java.lang.String servletName)
Returns the name of the attribute in the servlet context where the pre-initialized Atmosphere object is stored

Parameters:
servletName - The name of the servlet
Returns:
The attribute name which contains the initialized Atmosphere object

isVaadinServlet

protected boolean isVaadinServlet(javax.servlet.ServletRegistration servletRegistration)
Tries to determine if the given servlet registration refers to a Vaadin servlet.

Parameters:
servletRegistration - The servlet registration info for the servlet
Returns:
false if the servlet is definitely not a Vaadin servlet, true otherwise

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent sce)
Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.