Browse Source

Merge pull request #1185 from dreis2211/stomp-encoder-improvement

Improve performance of StompEncoder

Issue: SPR-14747
pull/1186/head
Juergen Hoeller 9 years ago committed by GitHub
parent
commit
94753b5e87
  1. 12
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java

12
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java

@ -81,7 +81,10 @@ public final class StompEncoder { @@ -81,7 +81,10 @@ public final class StompEncoder {
}
else {
StompCommand command = StompHeaderAccessor.getCommand(headers);
Assert.notNull(command, "Missing STOMP command: " + headers);
if (command == null) {
throw new IllegalStateException("Missing STOMP command: " + headers);
}
output.write(command.toString().getBytes(StandardCharsets.UTF_8));
output.write(LF);
writeHeaders(command, headers, payload, output);
@ -115,22 +118,25 @@ public final class StompEncoder { @@ -115,22 +118,25 @@ public final class StompEncoder {
boolean shouldEscape = (command != StompCommand.CONNECT && command != StompCommand.CONNECTED);
for (Entry<String, List<String>> entry : nativeHeaders.entrySet()) {
byte[] key = encodeHeaderString(entry.getKey(), shouldEscape);
if (command.requiresContentLength() && "content-length".equals(entry.getKey())) {
continue;
}
List<String> values = entry.getValue();
if (StompCommand.CONNECT.equals(command) &&
StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) {
values = Arrays.asList(StompHeaderAccessor.getPasscode(headers));
}
byte[] encodedKey = encodeHeaderString(entry.getKey(), shouldEscape);
for (String value : values) {
output.write(key);
output.write(encodedKey);
output.write(COLON);
output.write(encodeHeaderString(value, shouldEscape));
output.write(LF);
}
}
if (command.requiresContentLength()) {
int contentLength = payload.length;
output.write("content-length:".getBytes(StandardCharsets.UTF_8));

Loading…
Cancel
Save