@Test public void testDecode_header_body_null() throws Exception { Frame expectedFrame = new Frame(); expectedFrame.setCommand(Frame.COMMAND_SEND); assertEquals(expectedFrame, decode("SEND\n\n\0")); }
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) throws Exception { if (buffer.readableBytes() > 0 && buffer.bytesBefore((byte) '\n') == 0) { buffer.readByte(); return new HeartBeatFrame(); } Frame currentFrame = null; String command = readString(buffer, Frame.EOL_COMMAND); if (isValidCommand(command)) { currentFrame = new Frame(command, new Header(), null); } else { LOGGER.trace("Invalid command : {}", command); return null; } String headerLine = null; while ((headerLine = readString(buffer, Frame.EOL_HEADER)) != null) { String[] headerParts = headerLine.split(":"); if (headerParts.length == 2) { currentFrame.setHeaderValue(unescapeHeader(headerParts[0]), unescapeHeader(headerParts[1])); } } buffer.readByte(); if (isExpectedBody(currentFrame.getCommand())) { String body = null; String contentLengthString = currentFrame.getHeaderValue(Header.HEADER_CONTENT_LENGTH); if (contentLengthString != null && Long.parseLong(contentLengthString) > 0) { int contentLength = Integer.parseInt(contentLengthString); body = readString(buffer, contentLength); buffer.readByte(); } else { body = readString(buffer, Frame.EOL_FRAME); } if (body != null && !body.isEmpty()) { currentFrame.setBody(body); } } else { buffer.readByte(); } return currentFrame; }
StompFrameDecoder extends ReplayingDecoder<VoidEnum> { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) throws Exception { if (buffer.readableBytes() > 0 && buffer.bytesBefore((byte) '\n') == 0) { buffer.readByte(); return new HeartBeatFrame(); } Frame currentFrame = null; String command = readString(buffer, Frame.EOL_COMMAND); if (isValidCommand(command)) { currentFrame = new Frame(command, new Header(), null); } else { LOGGER.trace("Invalid command : {}", command); return null; } String headerLine = null; while ((headerLine = readString(buffer, Frame.EOL_HEADER)) != null) { String[] headerParts = headerLine.split(":"); if (headerParts.length == 2) { currentFrame.setHeaderValue(unescapeHeader(headerParts[0]), unescapeHeader(headerParts[1])); } } buffer.readByte(); if (isExpectedBody(currentFrame.getCommand())) { String body = null; String contentLengthString = currentFrame.getHeaderValue(Header.HEADER_CONTENT_LENGTH); if (contentLengthString != null && Long.parseLong(contentLengthString) > 0) { int contentLength = Integer.parseInt(contentLengthString); body = readString(buffer, contentLength); buffer.readByte(); } else { body = readString(buffer, Frame.EOL_FRAME); } if (body != null && !body.isEmpty()) { currentFrame.setBody(body); } } else { buffer.readByte(); } return currentFrame; } }
StompFrameDecoder extends ReplayingDecoder<VoidEnum> { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) throws Exception { if (buffer.readableBytes() > 0 && buffer.bytesBefore((byte) '\n') == 0) { buffer.readByte(); return new HeartBeatFrame(); } Frame currentFrame = null; String command = readString(buffer, Frame.EOL_COMMAND); if (isValidCommand(command)) { currentFrame = new Frame(command, new Header(), null); } else { LOGGER.trace("Invalid command : {}", command); return null; } String headerLine = null; while ((headerLine = readString(buffer, Frame.EOL_HEADER)) != null) { String[] headerParts = headerLine.split(":"); if (headerParts.length == 2) { currentFrame.setHeaderValue(unescapeHeader(headerParts[0]), unescapeHeader(headerParts[1])); } } buffer.readByte(); if (isExpectedBody(currentFrame.getCommand())) { String body = null; String contentLengthString = currentFrame.getHeaderValue(Header.HEADER_CONTENT_LENGTH); if (contentLengthString != null && Long.parseLong(contentLengthString) > 0) { int contentLength = Integer.parseInt(contentLengthString); body = readString(buffer, contentLength); buffer.readByte(); } else { body = readString(buffer, Frame.EOL_FRAME); } if (body != null && !body.isEmpty()) { currentFrame.setBody(body); } } else { buffer.readByte(); } return currentFrame; } StompFrameDecoder(); }
StompFrameDecoder extends ReplayingDecoder<VoidEnum> { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) throws Exception { if (buffer.readableBytes() > 0 && buffer.bytesBefore((byte) '\n') == 0) { buffer.readByte(); return new HeartBeatFrame(); } Frame currentFrame = null; String command = readString(buffer, Frame.EOL_COMMAND); if (isValidCommand(command)) { currentFrame = new Frame(command, new Header(), null); } else { LOGGER.trace("Invalid command : {}", command); return null; } String headerLine = null; while ((headerLine = readString(buffer, Frame.EOL_HEADER)) != null) { String[] headerParts = headerLine.split(":"); if (headerParts.length == 2) { currentFrame.setHeaderValue(unescapeHeader(headerParts[0]), unescapeHeader(headerParts[1])); } } buffer.readByte(); if (isExpectedBody(currentFrame.getCommand())) { String body = null; String contentLengthString = currentFrame.getHeaderValue(Header.HEADER_CONTENT_LENGTH); if (contentLengthString != null && Long.parseLong(contentLengthString) > 0) { int contentLength = Integer.parseInt(contentLengthString); body = readString(buffer, contentLength); buffer.readByte(); } else { body = readString(buffer, Frame.EOL_FRAME); } if (body != null && !body.isEmpty()) { currentFrame.setBody(body); } } else { buffer.readByte(); } return currentFrame; } StompFrameDecoder(); static String unescapeHeader(String string); }
StompFrameDecoder extends ReplayingDecoder<VoidEnum> { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) throws Exception { if (buffer.readableBytes() > 0 && buffer.bytesBefore((byte) '\n') == 0) { buffer.readByte(); return new HeartBeatFrame(); } Frame currentFrame = null; String command = readString(buffer, Frame.EOL_COMMAND); if (isValidCommand(command)) { currentFrame = new Frame(command, new Header(), null); } else { LOGGER.trace("Invalid command : {}", command); return null; } String headerLine = null; while ((headerLine = readString(buffer, Frame.EOL_HEADER)) != null) { String[] headerParts = headerLine.split(":"); if (headerParts.length == 2) { currentFrame.setHeaderValue(unescapeHeader(headerParts[0]), unescapeHeader(headerParts[1])); } } buffer.readByte(); if (isExpectedBody(currentFrame.getCommand())) { String body = null; String contentLengthString = currentFrame.getHeaderValue(Header.HEADER_CONTENT_LENGTH); if (contentLengthString != null && Long.parseLong(contentLengthString) > 0) { int contentLength = Integer.parseInt(contentLengthString); body = readString(buffer, contentLength); buffer.readByte(); } else { body = readString(buffer, Frame.EOL_FRAME); } if (body != null && !body.isEmpty()) { currentFrame.setBody(body); } } else { buffer.readByte(); } return currentFrame; } StompFrameDecoder(); static String unescapeHeader(String string);  }