On 21/11/2013 14:33, Johan Compagner wrote: >> >> >> Patches welcome. >> > > > something like this? (only for text changes only in WsFrameBase)
Hard to read the patch in this format. The best way to provide a patch is to open a bugzilla issue (this one would be an enhancement request) and add the patch in diff -u format, ideally against trunk (8.0.x). Mark > > in the constructor of WsFrameBase > > // take the minimum from what is set by the user or the default. > messageBufferText = > > CharBuffer.allocate(Math.min(Constants.DEFAULT_BUFFER_SIZE,wsSession.getMaxTextMessageBufferSize() > )); > > so always init on the smallest set buffer size. > > > and then for example in processDataText() remove all the userPartial() > tests and the throw TooBig exceptions > so only do always just (i think on 3 places) > > messageBufferText.flip(); > sendMessageText(false); > messageBufferText.clear(); > > in sendMessageText could become: > > private volatile StringBuilder messageBuffer; > private void sendMessageText(boolean last) throws WsIOException { > String message = null; > if (!last) > { > // if this is not the last part, append it to the StringBuilder > buffer. > if (messageBuilder == null) messageBuilder = new > StringBuilder(messageBufferText.length()*2); > if ( (messageBuilder.length() + messageBufferText.length()) <= > wsSession.getMaxTextMessageBufferSize()) { > messageBuilder.append(messageBufferText.toString()); > messageBufferText.clear(); > return; > } > else if (usePartial()) { > // if the stringbuilder buffer added with the current > buffered text is greater then the max buffer size > // then send this if partial is supported. > message = messageBuilder.toString(); > // reset the current buffered string builder. > messageBuilder = null; > // call resend so that the current BufferedText is added. > sendMessageText(last); > } else { > // if partial is not supported throw the to big exception. > throw new WsIOException(new CloseReason( > CloseCodes.TOO_BIG, > sm.getString("wsFrame.textMessageTooBig"))); > } > } > else { > // it was the last, > if (messageBuilder == null) { > // it was not part of a bigger one, just take the current > message > message = messageBufferText.toString(); > } > else { > // it is the last of a bigger one, check the buffered size > if ( (messageBuilder.length() + messageBufferText.length()) > > wsSession.getMaxTextMessageBufferSize()) { > throw new WsIOException(new CloseReason( > CloseCodes.TOO_BIG, > sm.getString("wsFrame.textMessageTooBig"))); > } > // size is correct append the last part and extract the > complete message > messageBuilder.append(messageBufferText.toString()); > message = messageBuilder.toString(); > messageBuilder = null; > } > } > > if (textMsgHandler != null) { > if (textMsgHandler instanceof WrappedMessageHandler) { > long maxMessageSize = > ((WrappedMessageHandler) > textMsgHandler).getMaxMessageSize(); > if (maxMessageSize > -1 && > message.length() > maxMessageSize) { > throw new WsIOException(new > CloseReason(CloseCodes.TOO_BIG, > sm.getString("wsFrame.messageTooBig", > > Long.valueOf(messageBufferText.remaining()), > Long.valueOf(maxMessageSize)))); > } > } > > try { > if (textMsgHandler instanceof MessageHandler.Partial<?>) { > ((MessageHandler.Partial<String>) > textMsgHandler).onMessage( > message, last); > } else { > // Caller ensures last == true if this branch is used > ((MessageHandler.Whole<String>) > textMsgHandler).onMessage( > message); > } > } catch (Throwable t) { > ExceptionUtils.handleThrowable(t); > wsSession.getLocal().onError(wsSession, t); > } > } > } > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org