Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,18 @@ private StringBuilder getBaseLogMessage() {
StringBuilder sb = new StringBuilder();
SimpMessageType messageType = getMessageType();
sb.append(messageType != null ? messageType.name() : SimpMessageType.OTHER);
if (getDestination() != null) {
sb.append(" destination=").append(getDestination());
String destination = getDestination();
if (destination != null) {
sb.append(" destination=").append(destination);
}
if (getSubscriptionId() != null) {
sb.append(" subscriptionId=").append(getSubscriptionId());
String subscriptionId = getSubscriptionId();
if (subscriptionId != null) {
sb.append(" subscriptionId=").append(subscriptionId);
}
sb.append(" session=").append(getSessionId());
if (getUser() != null) {
sb.append(" user=").append(getUser().getName());
Principal user = getUser();
if (user != null) {
sb.append(" user=").append(user.getName());
}
return sb;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private Message<byte[]> decodeMessage(ByteBuffer byteBuffer, @Nullable MultiValu
if (payload.length > 0) {
StompCommand stompCommand = headerAccessor.getCommand();
if (stompCommand != null && !stompCommand.isBodyAllowed()) {
throw new StompConversionException(headerAccessor.getCommand() +
throw new StompConversionException(stompCommand +
" shouldn't have a payload: length=" + payload.length + ", headers=" + headers);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.Principal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -165,11 +166,13 @@ else if (StompCommand.CONNECT.equals(command)) {
}

void updateStompHeadersFromSimpMessageHeaders() {
if (getDestination() != null) {
setNativeHeader(STOMP_DESTINATION_HEADER, getDestination());
String destination = getDestination();
if (destination != null) {
setNativeHeader(STOMP_DESTINATION_HEADER, destination);
}
if (getContentType() != null) {
setNativeHeader(STOMP_CONTENT_TYPE_HEADER, getContentType().toString());
MimeType contentType = getContentType();
if (contentType != null) {
setNativeHeader(STOMP_CONTENT_TYPE_HEADER, contentType.toString());
}
trySetStompHeaderForSubscriptionId();
}
Expand All @@ -188,21 +191,24 @@ protected Map<String, List<String>> getNativeHeaders() {
}

public StompCommand updateStompCommandAsClientMessage() {
if (getMessageType() != SimpMessageType.MESSAGE) {
throw new IllegalStateException("Unexpected message type " + getMessageType());
SimpMessageType messageType = getMessageType();
if (messageType != SimpMessageType.MESSAGE) {
throw new IllegalStateException("Unexpected message type " + messageType);
}
if (getCommand() == null) {
StompCommand command = getCommand();
if (command == null) {
setHeader(COMMAND_HEADER, StompCommand.SEND);
}
else if (!getCommand().equals(StompCommand.SEND)) {
throw new IllegalStateException("Unexpected STOMP command " + getCommand());
else if (!command.equals(StompCommand.SEND)) {
throw new IllegalStateException("Unexpected STOMP command " + command);
}
return getCommand();
return command;
}

public void updateStompCommandAsServerMessage() {
if (getMessageType() != SimpMessageType.MESSAGE) {
throw new IllegalStateException("Unexpected message type " + getMessageType());
SimpMessageType messageType = getMessageType();
if (messageType != SimpMessageType.MESSAGE) {
throw new IllegalStateException("Unexpected message type " + messageType);
}
StompCommand command = getCommand();
if ((command == null) || StompCommand.SEND.equals(command)) {
Expand Down Expand Up @@ -278,7 +284,8 @@ public void setSubscriptionId(@Nullable String subscriptionId) {
private void trySetStompHeaderForSubscriptionId() {
String subscriptionId = getSubscriptionId();
if (subscriptionId != null) {
if (getCommand() != null && StompCommand.MESSAGE.equals(getCommand())) {
StompCommand command = getCommand();
if (command != null && StompCommand.MESSAGE.equals(command)) {
setNativeHeader(STOMP_SUBSCRIPTION_HEADER, subscriptionId);
}
else {
Expand Down Expand Up @@ -403,23 +410,26 @@ public void setVersion(@Nullable String version) {

@Override
public String getShortLogMessage(Object payload) {
if (StompCommand.SUBSCRIBE.equals(getCommand())) {
StompCommand command = getCommand();
if (StompCommand.SUBSCRIBE.equals(command)) {
return "SUBSCRIBE " + getDestination() + " id=" + getSubscriptionId() + appendSession();
}
else if (StompCommand.UNSUBSCRIBE.equals(getCommand())) {
else if (StompCommand.UNSUBSCRIBE.equals(command)) {
return "UNSUBSCRIBE id=" + getSubscriptionId() + appendSession();
}
else if (StompCommand.SEND.equals(getCommand())) {
else if (StompCommand.SEND.equals(command)) {
return "SEND " + getDestination() + appendSession() + appendPayload(payload);
}
else if (StompCommand.CONNECT.equals(getCommand())) {
return "CONNECT" + (getUser() != null ? " user=" + getUser().getName() : "") + appendSession();
else if (StompCommand.CONNECT.equals(command)) {
Principal user = getUser();
return "CONNECT" + (user != null ? " user=" + user.getName() : "") + appendSession();
}
else if (StompCommand.CONNECTED.equals(getCommand())) {
else if (StompCommand.CONNECTED.equals(command)) {
return "CONNECTED heart-beat=" + Arrays.toString(getHeartbeat()) + appendSession();
}
else if (StompCommand.DISCONNECT.equals(getCommand())) {
return "DISCONNECT" + (getReceipt() != null ? " receipt=" + getReceipt() : "") + appendSession();
else if (StompCommand.DISCONNECT.equals(command)) {
String receipt = getReceipt();
return "DISCONNECT" + (receipt != null ? " receipt=" + receipt : "") + appendSession();
}
else {
return getDetailedLogMessage(payload);
Expand Down Expand Up @@ -462,11 +472,12 @@ private String appendPayload(Object payload) {
"Expected byte array payload but got: " + ClassUtils.getQualifiedName(payload.getClass()));
}
byte[] bytes = (byte[]) payload;
String contentType = (getContentType() != null ? " " + getContentType().toString() : "");
if (bytes.length == 0 || getContentType() == null || !isReadableContentType()) {
MimeType mimeType = getContentType();
String contentType = (mimeType != null ? " " + mimeType.toString() : "");
if (bytes.length == 0 || mimeType == null || !isReadableContentType()) {
return contentType;
}
Charset charset = getContentType().getCharset();
Charset charset = mimeType.getCharset();
charset = (charset != null ? charset : StandardCharsets.UTF_8);
return (bytes.length < 80) ?
contentType + " payload=" + new String(bytes, charset) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,9 @@ else if (payload instanceof byte[]) {
}

protected boolean isReadableContentType() {
MimeType contentType = getContentType();
for (MimeType mimeType : READABLE_MIME_TYPES) {
if (mimeType.includes(getContentType())) {
if (mimeType.includes(contentType)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,12 @@ else if (webSocketMessage instanceof BinaryMessage) {
logger.trace("From client: " + headerAccessor.getShortLogMessage(message.getPayload()));
}

boolean isConnect = StompCommand.CONNECT.equals(headerAccessor.getCommand());
StompCommand command = headerAccessor.getCommand();
boolean isConnect = StompCommand.CONNECT.equals(command);
if (isConnect) {
this.stats.incrementConnectCount();
}
else if (StompCommand.DISCONNECT.equals(headerAccessor.getCommand())) {
else if (StompCommand.DISCONNECT.equals(command)) {
this.stats.incrementDisconnectCount();
}

Expand All @@ -292,10 +293,10 @@ else if (StompCommand.DISCONNECT.equals(headerAccessor.getCommand())) {
if (isConnect) {
publishEvent(this.eventPublisher, new SessionConnectEvent(this, message, user));
}
else if (StompCommand.SUBSCRIBE.equals(headerAccessor.getCommand())) {
else if (StompCommand.SUBSCRIBE.equals(command)) {
publishEvent(this.eventPublisher, new SessionSubscribeEvent(this, message, user));
}
else if (StompCommand.UNSUBSCRIBE.equals(headerAccessor.getCommand())) {
else if (StompCommand.UNSUBSCRIBE.equals(command)) {
publishEvent(this.eventPublisher, new SessionUnsubscribeEvent(this, message, user));
}
}
Expand Down