我正在尝试向在 Jetty 9 下运行的 CometD 服务器发送一条大消息(>130k)。当服务器收到这条大消息时,它会生成以下异常:
org.eclipse.jetty.websocket.api.MessageTooLargeException: Text message size [130353] exceeds maximum size [65536]
at org.eclipse.jetty.websocket.api.WebSocketPolicy.assertValidTextMessageSize(WebSocketPolicy.java:140)
at org.eclipse.jetty.websocket.common.Parser.assertSanePayloadLength(Parser.java:127)
at org.eclipse.jetty.websocket.common.Parser.parseFrame(Parser.java:482)
at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:254)
at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.readParse(AbstractWebSocketConnection.java:632)
at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:480)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)
[qtp83954662-20] INFO org.cometd.websocket.server.WebSocketTransport$WebSocketScheduler$1 - WebSocket Error, Address: null
...
(the rest removed for brevity)
我了解问题所在,并查看了 CometD 文档。根据文档,您可以使用初始化参数更改缓冲区大小和最大消息大小:ws.bufferSize 和 ws.maxMessageSize。我在 web.xml 文件中设置了这些参数并重新启动了 Jetty,但参数设置似乎没有效果。我仍然得到完全相同的异常,因为缓冲区大小保持不变。
下面提供了 web.xml 文件的设置:
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometDServlet</servlet-class>
<init-param>
<param-name>ws.bufferSize</param-name>
<param-value>400000</param-value>
</init-param>
<init-param>
<param-name>ws.maxMessageSize</param-name>
<param-value>400000</param-value>
</init-param>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
我错过了什么吗?如何在 CometD 服务器中设置最大消息大小并让服务器实际使用该消息大小?