ServerPush add-on

Added 1.0.3. See directory for change log.

What atmosphere artifacts are required?

I find it hugely frustrating that the Vaadin directory provides a pom download, but that pom doesn’t include what dependencies are actually required for the add-on to function.

Hi, Thomas. Thanks so much for this terrific add-on! I have a chat “sub-application” that appears to be working correctly when the context path is “/*” but I’m afraid I missing something when it comes to associating an alternative context path with the chat app so as to have multiple contexts handled by multiple applications. I would like to have the contexts like so:

main app at /main/*
chat app at /chat/*

I’m not using auto-push, so /main is a Navigator7 servlet, and /chat is a standard Vaadin servlet with listener-based “manual” push()es. I’ve tried what seems like every combination of context settings in atmosphere.xml, context.xml and web.xml. I’d be very grateful for any guidance from you or the group!

Best regards,
Elliott Wade

If an add-on jar uploaded to Directory contains a Maven pom file, Directory will use that. For more information, see
this
.

Hi Elliot,

Can you tell me more about your app? Are you using multiple web contexts or are
/main/*
and
/chat/*
in the same context? and if so, what is that context? i’ll be happy to provide you the correct config if you can supply me this information. Here is an example assuming you are using manual push and the context path of your app is /foo.

  1. You can copy the atmosphere.xml and web.xml from the zip file as templates. This will make the URL for push
    /foo/server-push
  2. Now use the constructor of ServerPush that accepts a String value, which is set as the context path. Since the context path of the web application is
    /foo
    , call
    new ServerPush(“/foo”)
  3. Everything should work fine now

The important thing is to match the context path constructor param to the AtmosphereServlet’s servlet mapping url pattern (minus
/server-push
). Please note that this path is
independent
of the Vaadin application path; thus, you can have
/chat/*
point to the Vaadin app and
/push/server-push
configured for the atmosphere servlet. Using this path the servlet mapping url pattern in web.xml for the AtmosphereServlet would be
/push/server-push
, the
context-root
attribute in atmosphere.xml would be the same, and you would instantiate the ServerPush widget using
new ServerPush(“/push”)
.

Being able to specify the context path in the ServerPush constructor is powerful as you do not have to actually specify the exact context path. Here’s another example (assume context path is /web:
In
WEB-INF/web.xml
:


....
<servlet-mapping>
    <servlet-name>AtmosphereServlet</servlet-name>
    <url-pattern>/foo/bar/baz/somethinghere/longURL/server-push</url-pattern>
</servlet-mapping>
....

In
META-INF/atmosphere.xml
:


....
<atmosphere-handlers>
    <atmosphere-handler context-root="/foo/bar/baz/somethinghere/longURL/server-push" class-name="org.vaadin.addons.serverpush.VaadinServerPushHandler">
         <property name="heartbeat" value="5000"/>
     </atmosphere-handler>
</atmosphere-handlers>
....

In your app:


....
ServerPush push = new ServerPush("/web/foo/bar/baz/somethinghere/longURL");
....
application.getMainWindow().addComponent(push);
....
// something happens
push.push();
....

So the URL mapping is really irrelevant as long as the config files match and you are using manual push. This cannot currently be done with automatic push as it always uses
/server-push
as the path; however, if there is enough interest i can add that in.

Hope this helps you Elliot. Send me any questions you may have.

Henri, is there any way to view what is currently in the Vaadin Maven repo? Does Vaadin copy the dependencies into its own Maven repo or does it just copy the dependencies section of the pom.xml so the dependencies are retrieved from Maven central or any other configured repo?

Why would the content of the Vaadin repository matter ? If Vaadin and atmosphere are in the Maven Central repository (which they are), your POM should not include any repository directives (same goes for the usual common-* libraries and suchlike that your code directly depends on).

Also, your POM should likely mark Vaadin as optional – whoever includes your add-on should be responsible for deciding which version they want

This stems from my ignorance of Maven, which I do not use. I’m an Apache Ivy guy ;0) As this add-on stands right now, the user is free to pull-in whichever version of Vaadin they want as well as other libraries. I like that better as it is more flexible for developers. For those Ivy users, you can find this add-on in the
Ivy RoundUp
repository.

Hi,
I am using this add on. It works fine on Tomcat 6.0.33 but gives the following error on Tomcat 7.0.22

WARNING: failed using comet support: org.atmosphere.container.TomcatCometSupport, error: Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.
If that’s not the case, you can also remove META-INF/context.xml and WEB-INF/lib/atmosphere-compat-tomcat.jar
O

What extra do I need to do to make it working on Tomcat 7

I am using this with Tomcat 7.0.21 using Servlet 3.0 with no special config. Make sure your context.xml has the child element

. It that does not solve your problem please send me your config and I can guide you.

I am using context.xml with this loader element in META-INF

One difference is that I am not using Servlet 3.0. Does it have to be servlet 3.0? If that is the case what do I need to do to covert to servlet 3.0?

I would recommend Servlet 3.0. To enable it you need to have your web.xml web-app definition set to 3.0 like so:


<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

Additionally, any servlet filters that sit in front of the Atmosphere servlet must have the
true
element. If you just want to use Tomcat’s Comet support then add


<init-param>
    <param-name>org.atmosphere.useNative</param-name>
    <param-value>true</param-value>
</init-param>

to the Atmosphere servlet’s definition.

Please find the attached application. This war file also contains the source file as well and all configuration files I used.

In tomcat 6.0.33 it works fine and detects it as comet application.

The same application does not work in tomcat 7.0.22 and gives following error

WARNING: failed using comet support: org.atmosphere.container.TomcatCometSupport, error: Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.
If that’s not the case, you can also remove META-INF/context.xml and WEB-INF/lib/atmosphere-compat-tomcat.jar
Oct 5, 2011 3:08:39 PM org.atmosphere.cpr.AtmosphereServlet doCometSupport
WARNING: Using BlockingIOCometSupport.

Please see this also for more related issues
https://vaadin.com/forum/-/message_boards/view_message/795678
11956.war (11.6 MB)

I tried servlet 3.0 but got same result.

I dont have any filter for Atmosphere servlet so I use only useNative property to be true but makes no difference.

Hi Mark,
Did you get chance to look at it? I am kind of stuck because of this issue.

thanks
dheeraj

Yes, I looked at it. You have one, potentially two, problems. The first is that the context path in ServerPushApplication is incorrect. there is no /root context in tomcat by default. Your context.xml has the context path as “” which means the root context; however, since you are deploying as a WAR file that context path is overwritten by Tomcat. Since the name of the WAR is ServerPush.war the correct path is /SeverPush/foo/bar.

I’d highly recommend using the ServerPushApplicationServlet; it will eliminate these discrepancies. See https://github.com/markathomas/ServerPush/tree/master/samples for sample projects.

Also, I tested your WAR (after fixing the path) on both tomcat 7.0.22 and 7.0.21. Both worked fine.

Hi Mark,
I am still not able to run it successfully. One difference I see is following

I see the message
INFO: Atmosphere is using comet support: org.atmosphere.container.TomcatCometSupport running under container: Apache Tomcat/7.0.22

Instead of
INFO: Atmosphere is using comet support: org.atmosphere.container.Servlet30Support running under container: Apache Tomcat/7.0.22 using javax.servlet/3.0

Even though I have my web.xml schema pointing to 3.0 as following

And I have following property set in both Vaadin servlet and Atmosphere servlet
true

I dont have any servlet jar in WEB-INF/lib as well

Does it have to use Servlet30Support in order for me to fix this issue? And why is it not using Servlet30Support?

Comment out


<init-param>
        <param-name>org.atmosphere.useNative</param-name>
        <param-value>true</param-value>
</init-param>

as that init-param forces the use of the container’s Comet implementation.

Hmm it has become a nightmare for me. When I comment this property I get this error in Tomcat 7.0.22. Yes I do have web.xml using Sevlet 3.0 header

SEVERE: AtmosphereServlet exception
java.lang.IllegalStateException: Not supported.
at org.apache.catalina.connector.Request.startAsync(Request.java:1642)
at org.apache.catalina.connector.Request.startAsync(Request.java:1635)
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1024)
at org.atmosphere.container.Servlet30Support.suspend(Servlet30Support.java:137)
at org.atmosphere.container.Servlet30Support.service(Servlet30Support.java:91)
at org.atmosphere.cpr.AtmosphereServlet.doCometSupport(AtmosphereServlet.java:1156)
at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:1138)
at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:1124)

In web.xml…

<?xml version="1.0" encoding="UTF-8"?>