0

I am trying to send a large message (>130k) to a CometD server that is running under Jetty 9. When the server receives this large message, it generates the following exception:

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)  

I understand what the problem is, and have looked at the CometD documentation. According to the documentation, you can change the buffer size and the maximum message size using the initialization parameters: ws.bufferSize and ws.maxMessageSize. I set those parameters in my web.xml file and restarted Jetty, but the parameter settings seem to have no effect. I am still getting the exact same exception, because the buffer size remains unchanged.

The settings for the web.xml file are provided below:

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

Am I missing something? How can I set the maximum message size in a CometD server and have the server actually use that message size?

Factor Three
  • 2,094
  • 5
  • 35
  • 51

1 Answers1

1

Your web.xml is correct, and that is the right way to address the problem.

There are tests in the CometD test suite that verify that the ws.maxMessageSize parameter works correctly.

I just tried myself to modify the CometD demo, adding ws.maxMessageSize and then sending a large message from a test client, and it just worked perfectly.

Perhaps you have a typo in the parameter name, or something else that resets the parameter to its default value ?

sbordet
  • 16,856
  • 1
  • 50
  • 45
  • Actually, there is no typo (see the web.xml file provided with the question), If something is causing the parameter to be reset, then it has to be somewhere in the startup code. Where would I look for something like that? If the web.xml file is correct, then what would have caused the reset? – Factor Three Nov 17 '16 at 00:52
  • Are you using Spring to create the `BayeuxServer` instance or some other mechanism ? That would explain why the settings defined in `web.xml` would not have effect. – sbordet Nov 17 '16 at 09:28