ServerPush add-on

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"?>

I am sorry for your troubles but I am unable to reproduce your issue. The ISE “Not supported” only occurs when either a servlet or servlet filter accessed as part of a request that calls startAsync() on the HTTP request is not marked as
true
. All standard Tomcat valves support async so the issue would not be there. I suggest you look at your tomcat config and make sure there is not something in your request path not supporting async. As an example, when I first wrote this add-on it worked perfectly on my machine but when I integrated it into my company’s build and pushed it to the test system it did not work with the exact error you have specified. I about pulled my teeth out trying to understand why. It turned out that a third-party library we were using in the app, Java Melody, had included a web-fragment.xml in the JAR’s META-INF/ directory which declared a non-aysnc servlet filter with the mapping of /*. We were already including this filter in our web.xml so it was completely redundant; however, we never noticed it until moving to tomcat 7 and using servlet 3.0. Review your JAR files in WEB-INF/lib and make sure there is nothing like this:


for JAR in WEB-INF/lib/*.jar; do
    if [ `unzip -l $JAR | grep -c web-fragment.xml` -gt 0 ]
; then
        echo "web-fragment.xml found in $JAR"
    fi
done

Also review the context.xml and server.xml in Tomcat’s conf dir.

First, thank you very much for writing this add-on. It is highly needed in several dynamic web applications and should be IMO part of the official vaadin release.
Well, it has already been proposed for vaadin 7 as I see on http://dev.vaadin.com/wiki/Vaadin7/Proposals/ServerPush

However, I have some stability problem with this add-on.

My web application consists of a button and a normal (lazy) table. When I press the button my program starts filling the table in the background. Since I want to present the results as fast as possible I decided to use ServerPush in order to update the table in the browser incrementally. Thereto I use the ServerPush servlet (org.vaadin.addons.serverpush.ServerPushApplicationServlet) so that I do not have to manually call push().
For adding rows to the table I use the normal addItem(content, id) method.

But almost always when I add more than 100 rows to the table the table (or the client-server communication or whatever) crashes. In this case the table does not react anymore on certain user actions. I cannot sort the rows by column anymore and the table does not load new rows anymore when I scroll down via mouse wheel.

Thus, the question is whether the table, the normal GWT communication or the atmosphere communication crashes? But how to find the cause for this problem?

BTW, when I reload the page the table works again normally.

Hello,

I am trying to use the ServerPush add on. I follow the steps in
this post
.
On the third step, I have to create a custom widgetset inheriting the org.vaadin.addons.serverpush.ServerPushWidgetset widgetset, but there is no matching class.The only one avalaible is org.vaadin.addons.serverpush.ServerPush.

How should I do ?

I am using ServerPush 1.06 and Vaadin 6.7.1. on RBD8

Thanks.