0

我们将 cometD 与 Tomcat 7.0.42 一起使用(这是必须的)。我们现在尝试让 Oort(cometD 的聚类机制)工作。如果我像这样在 web.xml 中启用 Oort,则每次另一个节点尝试连接时都会发生以下异常。

我很清楚,cometD 目前无法将 Websockets 与 Tomcat 一起使用,这就是为什么我认为 cometD 会简单地退回到长轮询......

这是我的配置:

  <web-app 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"
     version="3.0">
<display-name>messenger</display-name>

<servlet>
    <servlet-name>cometd</servlet-name>
    <servlet-class>org.cometd.server.CometdServlet</servlet-class>
    <init-param>
        <param-name>allowedTransports</param-name>
        <param-value>LongPollingTransport</param-value>
    </init-param>
    <init-param>
        <param-name>timeout</param-name>
        <param-value>20000</param-value>
    </init-param>


    <init-param>
        <param-name>jsonContext</param-name>
        <param-value>org.cometd.server.JacksonJSONContextServer</param-value>
    </init-param>
    <init-param>
        <param-name>maxInterval</param-name>
        <param-value>10000</param-value>
    </init-param>

    <init-param>
        <param-name>long-polling.multiSessionInterval</param-name>
        <param-value>2000</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
</servlet>

<servlet-mapping>
    <servlet-name>cometd</servlet-name>
    <url-pattern>/cometd/*</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>Oort</servlet-name>
    <servlet-class>org.cometd.oort.OortStaticConfigServlet</servlet-class>
    <init-param>
        <param-name>oort.url</param-name>
        <param-value>http://192.168.178.37:8080/messenger/cometd</param-value>
    </init-param>
    <init-param>
        <param-name>oort.channels</param-name>
        <param-value>/messenger/**,/internal/**</param-value>
    </init-param>
    <init-param>
        <param-name>oort.cloud</param-name>
        <param-value>http://192.168.178.22:8080/messenger/cometd</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
    <async-supported>true</async-supported>
</servlet>

<servlet>
    <servlet-name>Seti</servlet-name>
    <servlet-class>org.cometd.oort.SetiServlet</servlet-class>
    <load-on-startup>3</load-on-startup>
    <async-supported>true</async-supported>
</servlet>

这是一个例外:

org.cometd.common.TransportException: {httpCode=400, websocketCode=1002}
at org.cometd.websocket.client.WebSocketTransport.connect(WebSocketTransport.java:287) ~[cometd-websocket-jetty-2.7.0.jar:na]
at org.cometd.websocket.client.WebSocketTransport.send(WebSocketTransport.java:194) ~[cometd-websocket-jetty-2.7.0.jar:na]
at org.cometd.client.BayeuxClient$BayeuxClientState.send(BayeuxClient.java:1390) ~[cometd-java-client-2.7.0.jar:na]
at org.cometd.client.BayeuxClient.sendHandshake(BayeuxClient.java:374) ~[cometd-java-client-2.7.0.jar:na]
at org.cometd.client.BayeuxClient$HandshakingState.execute(BayeuxClient.java:1496) ~[cometd-java-client-2.7.0.jar:na]
at org.cometd.client.BayeuxClient.updateBayeuxClientState(BayeuxClient.java:1062) ~[cometd-java-client-2.7.0.jar:na]
at org.cometd.client.BayeuxClient.handshake(BayeuxClient.java:315) ~[cometd-java-client-2.7.0.jar:na]
at org.cometd.oort.Oort.connectComet(Oort.java:411) ~[cometd-java-oort-2.7.0.jar:na]
at org.cometd.oort.Oort.observeComet(Oort.java:358) ~[cometd-java-oort-2.7.0.jar:na]
at org.cometd.oort.Oort.observeComet(Oort.java:306) ~[cometd-java-oort-2.7.0.jar:na]
at org.cometd.oort.OortMulticastConfigurer.receive(OortMulticastConfigurer.java:125) ~[cometd-java-oort-2.7.0.jar:na]
at org.cometd.oort.OortMulticastConfigurer$MulticastReceiver.run(OortMulticastConfigurer.java:154) ~[cometd-java-oort-2.7.0.jar:na]
at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]

Caused by: java.net.ProtocolException: Bad response status 400 Bad Request
at org.eclipse.jetty.websocket.WebSocketClientFactory$HandshakeConnection.onClose(WebSocketClientFactory.java:546) ~[jetty-websocket-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.websocket.WebSocketClientFactory$WebSocketClientSelector.endPointClosed(WebSocketClientFactory.java:326) ~[jetty-websocket-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.destroyEndPoint(SelectorManager.java:848) ~[jetty-io-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.doUpdateKey(SelectChannelEndPoint.java:601) ~[jetty-io-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.doSelect(SelectorManager.java:463) ~[jetty-io-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.io.nio.SelectorManager$1.run(SelectorManager.java:285) ~[jetty-io-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603) ~[jetty-util-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538) ~[jetty-util-8.1.5.v20120716.jar:8.1.5.v20120716]
... 1 common frames omitted
4

2 回答 2

0

The error you see reports webSocketCode=1002, and the code that does that disables the WebSocket transport, so fallback to long polling should work flawlessly.

The CometD test suite has a test for exactly this scenario.

于 2013-10-25T15:51:12.833 回答
-1

So this is only a debug message and not necessarly a "real" Exception shown?

于 2013-10-30T10:27:53.160 回答