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.

4

1 回答 1

2

我相信问题出在您的应用程序/设置中,而不是在 CometD 或 Tomcat 中。

这适用于 CometD 3.0.5 和 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

选择 option 后4,将生成一个与您在问题中发布的代码段非常相似的配置 bean,系统会提示您其他配置问题:

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 
...

此时您可以构建war

$ cd cometd-tomcat
$ mvn clean install

war文件将位于cometd-tomcat/target/cometd-tomcat-1.0.0.war. 将此文件复制到 Tomcat 的webapps目录,启动 Tomcat,然后浏览http://localhost:8080/cometd-tomcat-1.0.0

这些步骤是对CometD 文档入门中描述的内容的快速总结。

对我来说就像一个魅力。

我建议您从这里开始,并修改此设置,添加您的应用程序所需的功能。

于 2015-07-31T09:09:02.757 回答