There will be NoSuchElementException when StompMessage.from() method parses STOMP frame which contains SPACE character in the name or value part in header line.
The main code which caused this issue:
The regex means, ':' and all whitespace characters(space, \t, \n, \r, etc) are not allowed in header lines' name or value part. As a result, reader.hasNext will return false when handle a header line contains SPACE character in name or value part, then reader.skip("\n\n") throws NoSuchElementException.
ERROR
receipt-id:message-12345
content-type:text/plain
content-length:170
message:malformed frame received
Solution
According to the STOMP Protocol Specification 1.2 - Augmented BNF,only CR or LF or ":" is not allowed in header's name or value part, so the PATTERN_HEADER constant should be changed to:
private static final Pattern PATTERN_HEADER = Pattern.compile("([^:\\n\\r]+)\\s*:\\s*([^:\\n\\r]+)");
Problem
There will be NoSuchElementException when StompMessage.from() method parses STOMP frame which contains SPACE character in the name or value part in header line. The main code which caused this issue:
The regex means, ':' and all whitespace characters(space, \t, \n, \r, etc) are not allowed in header lines' name or value part. As a result,
reader.hasNext
will return false when handle a header line contains SPACE character in name or value part, thenreader.skip("\n\n")
throws NoSuchElementException.In fact, it's reasonable to contain SPACE characters in header's value part, as mentioned in the STOMP Protocol Specification 1.2 - ERROR Frame :
Solution
According to the STOMP Protocol Specification 1.2 - Augmented BNF,only CR or LF or ":" is not allowed in header's name or value part, so the PATTERN_HEADER constant should be changed to:
private static final Pattern PATTERN_HEADER = Pattern.compile("([^:\\n\\r]+)\\s*:\\s*([^:\\n\\r]+)");