0

I didn't find any promising answer to Multiple Endpoints may not be deployed to the same path though scouring through several stackoverflows and google groups cometd related topics.

Cometd Version: 3.0.5 Tomcat Version: 7.0.55

BayeuxServer instance is created as follows for Spring integration.

@Bean(initMethod = "start", destroyMethod = "stop")
    @Singleton
    public BayeuxServer  bayeuxServer() {
        BayeuxServerImpl bayeuxServer = new BayeuxServerImpl();
        ***bayeuxServer.setTransports(new WebSocketTransport(bayeuxServer), new JSONTransport(bayeuxServer));***
        bayeuxServer.setOption(ServletContext.class.getName(), servletContext);
        bayeuxServer.setOption("ws.cometdURLMapping", "/cometd/*");
        bayeuxServer.addExtension(new org.cometd.server.ext.TimesyncExtension());
        servletContext.setAttribute(BayeuxServer.ATTRIBUTE, bayeuxServer);
        return bayeuxServer;
    }

Example: https://github.com/cometd/cometd/blob/master/cometd-java/cometd-java-oort/src/test/java/org/cometd/oort/spring/OortConfigurator.java

During this setup cometd and tomcat both tried to add end point on the same path as seen in error log.

Caused by: java.lang.RuntimeException: javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/cometd] at org.cometd.websocket.server.WebSocketTransport.init(WebSocketTransport.java:93)

Jul 30, 2015 4:35:02 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Allocate exception for servlet cometd javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/cometd] at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:207)

I understand the cometd doesn't play well with tomcat. Can the tomcat be prevented from adding the end point same as created by cometd? I have a requirement to deploy the application in tomcat.

user2263197
  • 97
  • 1
  • 12
  • Upgrade to *at least* Tomcat 7.0.63 to get some better error message details out of Tomcat for this. (it will report what the 2 endpoints sources are in the exception message) – Joakim Erdfelt Jul 30 '15 at 21:07
  • Upgrading to tomcat 7.0.63 problem is not resolved. The two points will be the same path [/cometd] as registered. The endpoint should be registered only once. – user2263197 Jul 31 '15 at 03:08

1 Answers1

2

I believe the problem is in your application / setup, and not in CometD or Tomcat.

This worked for me with CometD 3.0.5 and Tomcat 7.0.63:

$ mvn archetype:generate -DarchetypeCatalog=http://cometd.org
...
Choose archetype: 
1: http://cometd.org -> org.cometd.archetypes:cometd-archetype-dojo-jetty9 (3.0.5 - CometD archetype for creating a server-side event-driven web application)
2: http://cometd.org -> org.cometd.archetypes:cometd-archetype-spring-dojo-jetty9 (3.0.5 - CometD archetype for creating a server-side event-driven web application)
3: http://cometd.org -> org.cometd.archetypes:cometd-archetype-jquery-jetty9 (3.0.5 - CometD archetype for creating a server-side event-driven web application)
4: http://cometd.org -> org.cometd.archetypes:cometd-archetype-spring-jquery-jetty9 (3.0.5 - CometD archetype for creating a server-side event-driven web application)
...
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 4

After choosing option 4, which will produce a configuration bean very similar to the snippet you posted in your question, you are prompted with other configuration questions:

Define value for property 'groupId': : org.cometd.test
Define value for property 'artifactId': : cometd-tomcat
Define value for property 'version':  1.0-SNAPSHOT: : 1.0.0 
...

At this point you can build the war:

$ cd cometd-tomcat
$ mvn clean install

The war file will be located in cometd-tomcat/target/cometd-tomcat-1.0.0.war. Copy this file to Tomcat's webapps directory, start Tomcat, and browse http://localhost:8080/cometd-tomcat-1.0.0.

These steps are a quick summary of what is described in the CometD documentation primer.

Worked like a charm for me.

I suggest that you start from here, and modify this setup adding the features you need for your application.

sbordet
  • 16,856
  • 1
  • 50
  • 45