title: Comet message sent twice
body: <p>I want to use Cometd in my project and tried the Jetty 8 version of it on a Tomcat 7 server. It works but the message is being sent twice.</p>
  
  <p>To check if it had something to do with the rest of the project I set up a stand-alone project with only this functionality and I still get the message twice.</p>
  
  <p>I can not find out why that might be.</p>
  
  <p>There are 5 files in the project:</p>
  
  <ul>
  <li>pom.xml</li>
  <li>web.xml</li>
  <li>index.html</li>
  <li>BayeuxInitializer.java</li>
  <li>FormDataService.java</li>
  </ul>
  
  <p>Here is the code for each of the files:</p>
  
  <ul>
  <li><p>web.xml</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
            xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
            id="WebApp_ID" version="2.5"&gt;
      &lt;display-name&gt;Sertal Vision&lt;/display-name&gt;
  
      &lt;servlet&gt;
         &lt;servlet-name&gt;cometd&lt;/servlet-name&gt;
         &lt;servlet-class&gt;org.cometd.server.CometdServlet&lt;/servlet-class&gt;
         &lt;init-param&gt;
            &lt;param-name&gt;timeout&lt;/param-name&gt;
            &lt;param-value&gt;60000&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;init-param&gt;
            &lt;param-name&gt;logLevel&lt;/param-name&gt;
            &lt;param-value&gt;3&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet&gt;
         &lt;servlet-name&gt;bayeux-init&lt;/servlet-name&gt;
         &lt;servlet-class&gt;ch.sertal.server.BayeuxInitializer&lt;/servlet-class&gt;
         &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
         &lt;servlet-name&gt;cometd&lt;/servlet-name&gt;
         &lt;url-pattern&gt;/cometd/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;servlet-mapping&gt;
         &lt;servlet-name&gt;bayeux-init&lt;/servlet-name&gt;
         &lt;url-pattern&gt;/bayeux/servlet/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;filter&gt;
         &lt;filter-name&gt;continuation&lt;/filter-name&gt;
         &lt;filter-class&gt;org.eclipse.jetty.continuation.ContinuationFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
         &lt;filter-name&gt;continuation&lt;/filter-name&gt;
         &lt;url-pattern&gt;/cometd/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;welcome-file-list&gt;
         &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
   &lt;/web-app&gt;
  </code></pre></li>
  <li><p>index.html</p>
  
  <pre><code> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
   &lt;html&gt;
   &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8"/&gt;
      &lt;script type="text/javascript" src="js/dojo/dojo/dojo.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
         var subscription = undefined;
  
         dojo.addOnLoad( function () {
            dojo.require( "dojox.cometd" );
            dojo.require("dojox.timing");
            // Disconnect when the page unloads
            dojo.addOnUnload( function () {
               dojox.cometd.disconnect( true );
            } );
  
            var cometURL = "cometd";
            dojox.cometd.init( cometURL );
  
            var subscription = dojox.cometd.subscribe( "/sertal/formData", function ( message ) {
               dojo.create( "li", {
                  innerHTML:message.data.count
               }, dojo.byId( "message-list" ) );
            } );
  
            i = 1;
            var t = new dojox.timing.Timer();
            t.setInterval( 1000 );
            t.onTick = function() {
               dojox.cometd.publish( '/sertal/formData', { count: i++ } );
            };
            t.start();
  
         } );
      &lt;/script&gt;
   &lt;/head&gt;
   &lt;body&gt;
  
   &lt;div&gt;
      &lt;ul id="message-list"/&gt;
   &lt;/div&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre></li>
  <li><p>BayeuxInitializer.java</p>
  
  <pre><code> package ch.sertal.server;
  
   import org.cometd.bayeux.server.BayeuxServer;
  
   import javax.servlet.GenericServlet;
   import javax.servlet.ServletException;
   import javax.servlet.ServletRequest;
   import javax.servlet.ServletResponse;
   import java.io.IOException;
  
   public class BayeuxInitializer extends GenericServlet {
      private static final long serialVersionUID = -9089442901563633963L;
  
      @Override
      public void init() throws ServletException {
         BayeuxServer bayeux = ( BayeuxServer ) getServletContext().getAttribute( BayeuxServer.ATTRIBUTE );
  
   //      new HelloService( bayeux );
         new FormDataService( bayeux, getServletContext() );
  
      }
  
      @Override
      public void service( ServletRequest servletRequest, ServletResponse servletResponse ) throws ServletException, IOException {
         throw new ServletException( "sorry :-)" );
      }
   }
  </code></pre></li>
  <li><p>FormDataService.java</p>
  
  <pre><code> package ch.sertal.server;
  
   import org.cometd.bayeux.Message;
   import org.cometd.bayeux.server.BayeuxServer;
   import org.cometd.bayeux.server.ServerSession;
   import org.cometd.server.AbstractService;
  
   import javax.servlet.ServletContext;
   import java.util.Map;
  
   /**
    * Created by IntelliJ IDEA.
    * User: micha.roon
    * Date: 1/16/12
    * Time: 12:25 PM
    * To change this template use File | Settings | File Templates.
    */
   public class FormDataService extends AbstractService {
      private ServletContext context = null;
  
      public FormDataService( BayeuxServer bayeux, ServletContext context ) {
         super( bayeux, "hello" );
         this.context = context;
         addService( "/sertal/formData", "processFormData" );
         System.out.println( "New FormDataService" );
      }
  
      public void processFormData( final ServerSession remote, Message message ) {
         Map&lt;String, Object&gt; input = message.getDataAsMap();
  
         remote.deliver( getServerSession(), "/sertal/formData", input, null );
      }
   }
  </code></pre></li>
  <li><p>pom.xml</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;BayeuxTest&lt;/groupId&gt;
      &lt;artifactId&gt;BayeuxTest&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
  
      &lt;build&gt;
         &lt;plugins&gt;
            &lt;!--compiler plugin--&gt;
            &lt;plugin&gt;
               &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
               &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
               &lt;configuration&gt;
                  &lt;source&gt;1.6&lt;/source&gt;
                  &lt;target&gt;1.6&lt;/target&gt;
               &lt;/configuration&gt;
            &lt;/plugin&gt;
  
            &lt;plugin&gt;
               &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
               &lt;artifactId&gt;tomcat-maven-plugin&lt;/artifactId&gt;
               &lt;version&gt;1.1&lt;/version&gt;
               &lt;configuration&gt;
                  &lt;username&gt;${tomcat.username}&lt;/username&gt;
                  &lt;password&gt;${tomcat.password}&lt;/password&gt;
                  &lt;url&gt;${tomcat.manager}&lt;/url&gt;
                  &lt;path&gt;${tomcat.context}&lt;/path&gt;
               &lt;/configuration&gt;
            &lt;/plugin&gt;
  
         &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencies&gt;
         &lt;dependency&gt;
            &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
            &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
            &lt;version&gt;3.0.1&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
         &lt;/dependency&gt;
  
         &lt;!--for cometd support--&gt;
         &lt;dependency&gt;
            &lt;groupId&gt;org.cometd.java&lt;/groupId&gt;
            &lt;artifactId&gt;bayeux-api&lt;/artifactId&gt;
            &lt;version&gt;2.3.1&lt;/version&gt;
         &lt;/dependency&gt;
         &lt;dependency&gt;
            &lt;groupId&gt;org.cometd.javascript&lt;/groupId&gt;
            &lt;artifactId&gt;cometd-javascript-jquery&lt;/artifactId&gt;
            &lt;version&gt;2.3.1&lt;/version&gt;
            &lt;type&gt;war&lt;/type&gt;
         &lt;/dependency&gt;
         &lt;dependency&gt;
            &lt;groupId&gt;org.cometd.java&lt;/groupId&gt;
            &lt;artifactId&gt;cometd-java-server&lt;/artifactId&gt;
            &lt;version&gt;2.3.1&lt;/version&gt;
         &lt;/dependency&gt;
  
         &lt;dependency&gt;
            &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
            &lt;artifactId&gt;jetty-servlets&lt;/artifactId&gt;
            &lt;version&gt;8.0.4.v20111024&lt;/version&gt;
            &lt;exclusions&gt;
               &lt;exclusion&gt;
                  &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
                  &lt;artifactId&gt;jetty-client&lt;/artifactId&gt;
               &lt;/exclusion&gt;
            &lt;/exclusions&gt;
         &lt;/dependency&gt;
         &lt;dependency&gt;
            &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
            &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
            &lt;version&gt;2.5&lt;/version&gt;
         &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
   &lt;/project&gt;
  </code></pre></li>
  </ul>