On 22/09/2013 21:49, Igor Urisman wrote: > However, the server implementation is free to pick the maximum size of a > payload > that it is willing to receive as a whole. Tomcat designers chose that size > to be 125 > bytes. Reasonable number given the particulars of the wire level protocol, > but not > one defined in the standard.
That statement not correct. The default incoming buffer size for text and binary messages is 8k bytes. This applies to both the client and the server. There is a specification (RFC6455) mandated limit on control message payloads of 125 bytes. > It appears that there's also a talk of exposing the inbound message via a > Reader > <http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html>but > that's not in Java EE 7. Another incorrect statement. MessageHandler.Whole<Reader> is supported in JSR-356. Note that Readers only work with whole messages, not partial ones. > So, just as a specific example, my implementation looks like the following: > > public class FermiMessageHandler implements MessageHandler.Partial<String> { > > private Session session; > private int maxMessageSize = 20000; > private StringBuilder messageBuffer = new StringBuilder(maxMessageSize); > > FermiMessageHandler(Session session) { > this.session = session; > } > > @Override > public void onMessage(String msgPart, boolean last) { > if( messageBuffer.length() + msgPart.length() > maxMessageSize) { > session.close(new > CloseReason(CloseReason.CloseCodes.CLOSED_ABNORMALLY, "Message is too > long"); > } > else { > messageBuffer.append(msgPart); > if (last) { > String message = messageBuffer.toString(); > // We have a complete message. Do something with it. > messageBuffer.setLength(0); > } > } > } > } Just think about what you have done for a minute. The whole point of partial messages is so that you don't have to buffer the entire message in memory before processing it. Your code defeats the point of that entirely. You'd be better off increasing the maximum message size supported by the implementation and using MessageHandler.Whole<String>. Better still would be to re-write your handler so it actually processed partial messages. Mark --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org