Skip to content

Commit 94753b5

Browse files
authored
Merge pull request #1185 from dreis2211/stomp-encoder-improvement
Improve performance of StompEncoder Issue: SPR-14747
2 parents 099350a + 774e4c3 commit 94753b5

File tree

1 file changed

+9
-3
lines changed
  • spring-messaging/src/main/java/org/springframework/messaging/simp/stomp

1 file changed

+9
-3
lines changed

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public byte[] encode(Map<String, Object> headers, byte[] payload) {
8181
}
8282
else {
8383
StompCommand command = StompHeaderAccessor.getCommand(headers);
84-
Assert.notNull(command, "Missing STOMP command: " + headers);
84+
if (command == null) {
85+
throw new IllegalStateException("Missing STOMP command: " + headers);
86+
}
87+
8588
output.write(command.toString().getBytes(StandardCharsets.UTF_8));
8689
output.write(LF);
8790
writeHeaders(command, headers, payload, output);
@@ -115,22 +118,25 @@ private void writeHeaders(StompCommand command, Map<String, Object> headers, byt
115118
boolean shouldEscape = (command != StompCommand.CONNECT && command != StompCommand.CONNECTED);
116119

117120
for (Entry<String, List<String>> entry : nativeHeaders.entrySet()) {
118-
byte[] key = encodeHeaderString(entry.getKey(), shouldEscape);
119121
if (command.requiresContentLength() && "content-length".equals(entry.getKey())) {
120122
continue;
121123
}
124+
122125
List<String> values = entry.getValue();
123126
if (StompCommand.CONNECT.equals(command) &&
124127
StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) {
125128
values = Arrays.asList(StompHeaderAccessor.getPasscode(headers));
126129
}
130+
131+
byte[] encodedKey = encodeHeaderString(entry.getKey(), shouldEscape);
127132
for (String value : values) {
128-
output.write(key);
133+
output.write(encodedKey);
129134
output.write(COLON);
130135
output.write(encodeHeaderString(value, shouldEscape));
131136
output.write(LF);
132137
}
133138
}
139+
134140
if (command.requiresContentLength()) {
135141
int contentLength = payload.length;
136142
output.write("content-length:".getBytes(StandardCharsets.UTF_8));

0 commit comments

Comments
 (0)