Server push on Jetty 9.2

Hi everybody,

I’m trying to implement server push using Vaadin 7.2.4 on my embedded Jetty server (9.2.1.v20140609). However, I keep getting exceptions during startup. These are the steps I have already executed:

  1. Instructed Maven to load the Vaadin server push stuff:


  2. Applied a server push annotation to my Vaadin UI:

    public class MyUI extends UI

  3. Enabled server push on my embedded Jetty server:

    ServletHolder servletHolder = new ServletHolder(servlet);
    servletHolder.setInitParameter(“pushmode”, “automatic”);
    webAppContext.addServlet(servletHolder, “/*”);

  4. In Jetty 9.1 the WebSocketPolicy.setMaxMessageSize method has been removed, which is called by Atmosphere. To avoid the NoSuchMethodException I also added following temporary workaround (see

    servletHolder.setInitParameter(“org.atmosphere.cpr.asyncSupport”, “org.atmosphere.container.JSR356AsyncSupport”);

  5. In the previous step we told Atmosphere to use Jetty’s to use it’s JSR356 standard Java websocket API, instead of it’s native websocket API (see
    ). Therefore I added following
    for Maven:



  6. At this point I get following exception
    com.vaadin.server.ServiceException: Atmosphere init failed

    at com.vaadin.server.communication.PushRequestHandler.(
    at com.vaadin.server.VaadinServletService.createRequestHandlers(VaadinServletService.
    at com.vaadin.server.VaadinService.init(
    at com.vaadin.server.VaadinServlet.createServletService(
    at com.vaadin.server.VaadinServlet.[u]


    at org.eclipse.jetty.servlet.ServletHolder.initServlet(
    at org.eclipse.jetty.servlet.ServletHolder.initialize(
    at org.eclipse.jetty.servlet.ServletHandler.initialize(
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(
    at org.eclipse.jetty.webapp.WebAppContext.startContext(
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(
    at org.eclipse.jetty.webapp.WebAppContext.doStart(
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(
    at org.eclipse.jetty.server.Server.start(
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.jav
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(
    at org.eclipse.jetty.server.Server.doStart(
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start( starting up my embedded Jetty:

    Caused by: java.lang.IllegalStateException:

    ServerContainer is null

    at org.atmosphere.container.JSR356AsyncSupport.(

The only information I can find about this exception, is a similar
with Tomcat: "
The attribute is always null when calling ServletContext during the Servlet.init() operation"
. It looks like this is the case in my call stack above. Does anybody know what I’m doing wrong, or how I could workaround this problem?

Thanks a lot!!
Bart Butenaers

Hi Bart,

It seems that according to the spec, the implementation should set the ServerContainer attribute when initializing the servlet context, so it
be available at servlet init time. It seems Jetty does so
, but I can’t readily tell why it’s nevertheless not found by Atmosphere. Should probably debug by putting a breakpoint in the Jetty code to see when it’s executed if at all.

Hello Johannes,

Thanks for your very usefull reply! Indeed, it seems that the WebSocketServerContainerInitializer is never configured. From another
it became obvious that I had to configure it explicitly (i.e. creating a websocket container) before starting the embedded Jetty server:

ServletHolder servletHolder = …;
ServletContextHandler context = new ServletContextHandler();
context.setContextPath( “/” );
context.addServlet( servletHolder, “/*” );
server.setHandler( context );

ServerContainer container =

WebSocketServerContainerInitializer.configureContext( context );


Now the exception is gone and I get following in my log: "
Atmosphere Framework 2.1.2.vaadin2 started

However, the startup method of that initializer class is never called. In the same blog they mention "
Because we haven’t added any endpoints yet, the container basically sits here and does nothing
". Do you have any idea which endpoint I have to add to the container for Vaadin, to get the server push up and running?

Thanks again!
Bart Butenaers

In case anybody would be using the same steps as I described above: the server push seems to be working correctly this way, even


specifying an endpoint! The PushRequestHandler sends all the requests to the PushHandler. So the problem described above is solved for me …