@Override protected void sendMessageBinary(ByteBuffer msg, boolean last) throws WsIOException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(applicationClassLoader); super.sendMessageBinary(msg, last); } finally { Thread.currentThread().setContextClassLoader(cl); } }
@Override protected void sendMessageText(boolean last) throws WsIOException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(applicationClassLoader); super.sendMessageText(last); } finally { Thread.currentThread().setContextClassLoader(cl); } }
private void newFrame() { if (readPos == writePos) { readPos = 0; writePos = 0; } maskIndex = 0; payloadWritten = 0; state = State.NEW_FRAME; // These get reset in processInitialHeader() // fin, rsv, opCode, payloadLength, mask checkRoomHeaders(); }
private boolean swallowInput() { long toSkip = Math.min(payloadLength - payloadWritten, writePos - readPos); readPos += toSkip; payloadWritten += toSkip; if (payloadWritten == payloadLength) { if (continuationExpected) { newFrame(); } else { newMessage(); } return true; } else { return false; } }
private boolean processData() throws IOException { boolean result; if (Util.isControl(opCode)) { result = processDataControl(); } else if (textMessage) { if (textMsgHandler == null) { result = swallowInput(); } else { result = processDataText(); } } else { if (binaryMsgHandler == null) { result = swallowInput(); } else { result = processDataBinary(); } } checkRoomPayload(); return result; }
private boolean processDataBinary() throws IOException { while (!appendPayloadToMessage(messageBufferBinary)) { } else { if (!usePartial()) { CloseReason cr = new CloseReason(CloseCodes.TOO_BIG, sm.getString("wsFrame.bufferTooSmall", copy.put(messageBufferBinary); copy.flip(); sendMessageBinary(copy, false); messageBufferBinary.clear(); if (usePartial() || !continuationExpected) { messageBufferBinary.flip(); ByteBuffer copy = copy.put(messageBufferBinary); copy.flip(); sendMessageBinary(copy, !continuationExpected); messageBufferBinary.clear(); newFrame(); } else { newMessage();
private boolean processDataText() throws IOException { while (!appendPayloadToMessage(messageBufferBinary)) { } else if (cr.isOverflow()) { if (usePartial()) { messageBufferText.flip(); sendMessageText(false); messageBufferText.clear(); } else { if (usePartial()) { messageBufferText.flip(); sendMessageText(false); messageBufferText.clear(); } else { if (usePartial()) { messageBufferText.flip(); sendMessageText(false); messageBufferText.clear(); newFrame(); sendMessageText(true); newMessage(); return true;
if (isMasked()) { headerLength = 4; } else { payloadLength = byteArrayToLong(inputBuffer.array(), inputBuffer.arrayOffset() + inputBuffer.position(), 2); inputBuffer.position(inputBuffer.position() + 2); } else if (payloadLength == 127) { payloadLength = byteArrayToLong(inputBuffer.array(), inputBuffer.arrayOffset() + inputBuffer.position(), 8); inputBuffer.position(inputBuffer.position() + 8); if (isMasked()) { inputBuffer.get(mask, 0, 4);
mhPong.onMessage(new WsPongMessage(controlBufferBinary)); } catch (Throwable t) { handleThrowableOnSend(t); } finally { controlBufferBinary.clear(); newFrame(); return true;
private void checkRoomHeaders() { // Is the start of the current frame too near the end of the input // buffer? if (inputBuffer.length - readPos < 131) { // Limit based on a control frame with a full payload makeRoom(); } }
if ((b & 0x80) == 0 && isMasked()) { throw new WsIOException(new CloseReason( CloseCodes.PROTOCOL_ERROR, if (getLog().isDebugEnabled()) { getLog().debug(sm.getString("wsFrame.partialHeaderComplete", Boolean.toString(fin), Integer.toString(rsv), Integer.toString(opCode), Long.toString(payloadLength)));
private boolean appendPayloadToMessage(ByteBuffer dest) { if (isMasked()) { while (payloadWritten < payloadLength && readPos < writePos && dest.hasRemaining()) { byte b = (byte) ((inputBuffer[readPos] ^ mask[maskIndex]) & 0xFF); maskIndex++; if (maskIndex == 4) { maskIndex = 0; } readPos++; payloadWritten++; dest.put(b); } return (payloadWritten == payloadLength); } else { long toWrite = Math.min( payloadLength - payloadWritten, writePos - readPos); toWrite = Math.min(toWrite, dest.remaining()); dest.put(inputBuffer, readPos, (int) toWrite); readPos += toWrite; payloadWritten += toWrite; return (payloadWritten == payloadLength); } }
private void newMessage() { messageBufferBinary.clear(); messageBufferText.clear(); utf8DecoderMessage.reset(); continuationExpected = false; newFrame(); }
@Override protected Transformation getTransformation() { // Overridden to make it visible to other classes in this package return super.getTransformation(); } }
private boolean processDataControl() throws IOException { if (!appendPayloadToMessage(controlBufferBinary)) { return false; newFrame(); return true;
private boolean processData() throws IOException { boolean result; if (Util.isControl(opCode)) { result = processDataControl(); } else if (textMessage) { if (textMsgHandler == null) { result = swallowInput(); } else { result = processDataText(); } } else { if (binaryMsgHandler == null) { result = swallowInput(); } else { result = processDataBinary(); } } checkRoomPayload(); return result; }
if (!usePartial()) { CloseReason cr = new CloseReason(CloseCodes.TOO_BIG, sm.getString("wsFrame.bufferTooSmall", copy.put(messageBufferBinary); copy.flip(); sendMessageBinary(copy, false); messageBufferBinary.clear(); if (usePartial() || !continuationExpected) { messageBufferBinary.flip(); ByteBuffer copy = ByteBuffer.allocate(messageBufferBinary.limit()); copy.put(messageBufferBinary); copy.flip(); sendMessageBinary(copy, !continuationExpected); messageBufferBinary.clear(); newFrame(); } else { newMessage();
} else if (cr.isOverflow()) { if (usePartial()) { messageBufferText.flip(); sendMessageText(false); messageBufferText.clear(); } else { } else if (cr.isOverflow()) { if (usePartial()) { messageBufferText.flip(); sendMessageText(false); messageBufferText.clear(); } else { if (usePartial()) { messageBufferText.flip(); sendMessageText(false); messageBufferText.clear(); newFrame(); sendMessageText(true); newMessage(); return true;
private boolean swallowInput() { long toSkip = Math.min(payloadLength - payloadWritten, writePos - readPos); readPos += toSkip; payloadWritten += toSkip; if (payloadWritten == payloadLength) { if (continuationExpected) { newFrame(); } else { newMessage(); } return true; } else { return false; } }
if (isMasked()) { headerLength = 4; } else { payloadLength = byteArrayToLong(inputBuffer.array(), inputBuffer.arrayOffset() + inputBuffer.position(), 2); inputBuffer.position(inputBuffer.position() + 2); } else if (payloadLength == 127) { payloadLength = byteArrayToLong(inputBuffer.array(), inputBuffer.arrayOffset() + inputBuffer.position(), 8); inputBuffer.position(inputBuffer.position() + 8); if (isMasked()) { inputBuffer.get(mask, 0, 4);