|
|
|
@ -131,6 +131,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { |
|
|
|
super(SimpMessageType.HEARTBEAT, null); |
|
|
|
super(SimpMessageType.HEARTBEAT, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void updateSimpMessageHeadersFromStompHeaders() { |
|
|
|
void updateSimpMessageHeadersFromStompHeaders() { |
|
|
|
if (getNativeHeaders() == null) { |
|
|
|
if (getNativeHeaders() == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
@ -171,35 +172,6 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { |
|
|
|
trySetStompHeaderForSubscriptionId(); |
|
|
|
trySetStompHeaderForSubscriptionId(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create an instance for the given STOMP command. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static StompHeaderAccessor create(StompCommand command) { |
|
|
|
|
|
|
|
return new StompHeaderAccessor(command, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create an instance for the given STOMP command and headers. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static StompHeaderAccessor create(StompCommand command, Map<String, List<String>> headers) { |
|
|
|
|
|
|
|
return new StompHeaderAccessor(command, headers); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create headers for a heartbeat. While a STOMP heartbeat frame does not |
|
|
|
|
|
|
|
* have headers, a session id is needed for processing purposes at a minimum. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static StompHeaderAccessor createForHeartbeat() { |
|
|
|
|
|
|
|
return new StompHeaderAccessor(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create an instance from the payload and headers of the given Message. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static StompHeaderAccessor wrap(Message<?> message) { |
|
|
|
|
|
|
|
return new StompHeaderAccessor(message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected MessageHeaderAccessor createAccessor(Message<?> message) { |
|
|
|
protected MessageHeaderAccessor createAccessor(Message<?> message) { |
|
|
|
@ -213,23 +185,18 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public StompCommand updateStompCommandAsClientMessage() { |
|
|
|
public StompCommand updateStompCommandAsClientMessage() { |
|
|
|
|
|
|
|
|
|
|
|
Assert.state(SimpMessageType.MESSAGE.equals(getMessageType()), "Unexpected message type " + getMessage()); |
|
|
|
Assert.state(SimpMessageType.MESSAGE.equals(getMessageType()), "Unexpected message type " + getMessage()); |
|
|
|
|
|
|
|
|
|
|
|
if (getCommand() == null) { |
|
|
|
if (getCommand() == null) { |
|
|
|
setHeader(COMMAND_HEADER, StompCommand.SEND); |
|
|
|
setHeader(COMMAND_HEADER, StompCommand.SEND); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (!getCommand().equals(StompCommand.SEND)) { |
|
|
|
else if (!getCommand().equals(StompCommand.SEND)) { |
|
|
|
throw new IllegalStateException("Unexpected STOMP command " + getCommand()); |
|
|
|
throw new IllegalStateException("Unexpected STOMP command " + getCommand()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return getCommand(); |
|
|
|
return getCommand(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void updateStompCommandAsServerMessage() { |
|
|
|
public void updateStompCommandAsServerMessage() { |
|
|
|
|
|
|
|
|
|
|
|
Assert.state(SimpMessageType.MESSAGE.equals(getMessageType()), "Unexpected message type " + getMessage()); |
|
|
|
Assert.state(SimpMessageType.MESSAGE.equals(getMessageType()), "Unexpected message type " + getMessage()); |
|
|
|
|
|
|
|
|
|
|
|
StompCommand command = getCommand(); |
|
|
|
StompCommand command = getCommand(); |
|
|
|
if ((command == null) || StompCommand.SEND.equals(command)) { |
|
|
|
if ((command == null) || StompCommand.SEND.equals(command)) { |
|
|
|
setHeader(COMMAND_HEADER, StompCommand.MESSAGE); |
|
|
|
setHeader(COMMAND_HEADER, StompCommand.MESSAGE); |
|
|
|
@ -237,9 +204,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { |
|
|
|
else if (!StompCommand.MESSAGE.equals(command)) { |
|
|
|
else if (!StompCommand.MESSAGE.equals(command)) { |
|
|
|
throw new IllegalStateException("Unexpected STOMP command " + command); |
|
|
|
throw new IllegalStateException("Unexpected STOMP command " + command); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
trySetStompHeaderForSubscriptionId(); |
|
|
|
trySetStompHeaderForSubscriptionId(); |
|
|
|
|
|
|
|
|
|
|
|
if (getMessageId() == null) { |
|
|
|
if (getMessageId() == null) { |
|
|
|
String messageId = getSessionId() + "-" + messageIdCounter.getAndIncrement(); |
|
|
|
String messageId = getSessionId() + "-" + messageIdCounter.getAndIncrement(); |
|
|
|
setNativeHeader(STOMP_MESSAGE_ID_HEADER, messageId); |
|
|
|
setNativeHeader(STOMP_MESSAGE_ID_HEADER, messageId); |
|
|
|
@ -247,22 +212,15 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return the STOMP command, or {@code null} if not yet set. |
|
|
|
* Return the STOMP command, or {@code null} if not yet set. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public StompCommand getCommand() { |
|
|
|
public StompCommand getCommand() { |
|
|
|
return (StompCommand) getHeader(COMMAND_HEADER); |
|
|
|
return (StompCommand) getHeader(COMMAND_HEADER); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* A static alternative for access to the STOMP command. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static StompCommand getCommand(Map<String, Object> headers) { |
|
|
|
|
|
|
|
return (StompCommand) headers.get(COMMAND_HEADER); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Set<String> getAcceptVersion() { |
|
|
|
public Set<String> getAcceptVersion() { |
|
|
|
String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER); |
|
|
|
String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER); |
|
|
|
return (rawValue != null) ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.<String>emptySet(); |
|
|
|
return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.<String>emptySet()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean isHeartbeat() { |
|
|
|
public boolean isHeartbeat() { |
|
|
|
@ -329,15 +287,6 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Integer getContentLength(Map<String, List<String>> nativeHeaders) { |
|
|
|
|
|
|
|
if (nativeHeaders.containsKey(STOMP_CONTENT_LENGTH_HEADER)) { |
|
|
|
|
|
|
|
List<String> values = nativeHeaders.get(STOMP_CONTENT_LENGTH_HEADER); |
|
|
|
|
|
|
|
String value = (values != null ? values.get(0) : null); |
|
|
|
|
|
|
|
return Integer.valueOf(value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setContentLength(int contentLength) { |
|
|
|
public void setContentLength(int contentLength) { |
|
|
|
setNativeHeader(STOMP_CONTENT_LENGTH_HEADER, String.valueOf(contentLength)); |
|
|
|
setNativeHeader(STOMP_CONTENT_LENGTH_HEADER, String.valueOf(contentLength)); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -370,7 +319,6 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { |
|
|
|
return getFirstNativeHeader(STOMP_LOGIN_HEADER); |
|
|
|
return getFirstNativeHeader(STOMP_LOGIN_HEADER); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setPasscode(String passcode) { |
|
|
|
public void setPasscode(String passcode) { |
|
|
|
setNativeHeader(STOMP_PASSCODE_HEADER, passcode); |
|
|
|
setNativeHeader(STOMP_PASSCODE_HEADER, passcode); |
|
|
|
protectPasscode(); |
|
|
|
protectPasscode(); |
|
|
|
@ -385,21 +333,13 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return the passcode header value or {@code null}. |
|
|
|
* Return the passcode header value, or {@code null} if not set. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String getPasscode() { |
|
|
|
public String getPasscode() { |
|
|
|
StompPasscode credentials = (StompPasscode) getHeader(CREDENTIALS_HEADER); |
|
|
|
StompPasscode credentials = (StompPasscode) getHeader(CREDENTIALS_HEADER); |
|
|
|
return (credentials != null ? credentials.passcode : null); |
|
|
|
return (credentials != null ? credentials.passcode : null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* A static alternative for access to the passcode header. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static String getPasscode(Map<String, Object> headers) { |
|
|
|
|
|
|
|
StompPasscode credentials = (StompPasscode) headers.get(CREDENTIALS_HEADER); |
|
|
|
|
|
|
|
return (credentials != null ? credentials.passcode : null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setReceiptId(String receiptId) { |
|
|
|
public void setReceiptId(String receiptId) { |
|
|
|
setNativeHeader(STOMP_RECEIPT_ID_HEADER, receiptId); |
|
|
|
setNativeHeader(STOMP_RECEIPT_ID_HEADER, receiptId); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -440,6 +380,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { |
|
|
|
setNativeHeader(STOMP_VERSION_HEADER, version); |
|
|
|
setNativeHeader(STOMP_VERSION_HEADER, version); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Logging related
|
|
|
|
// Logging related
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -506,6 +447,62 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Static factory methods and accessors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create an instance for the given STOMP command. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static StompHeaderAccessor create(StompCommand command) { |
|
|
|
|
|
|
|
return new StompHeaderAccessor(command, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create an instance for the given STOMP command and headers. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static StompHeaderAccessor create(StompCommand command, Map<String, List<String>> headers) { |
|
|
|
|
|
|
|
return new StompHeaderAccessor(command, headers); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create headers for a heartbeat. While a STOMP heartbeat frame does not |
|
|
|
|
|
|
|
* have headers, a session id is needed for processing purposes at a minimum. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static StompHeaderAccessor createForHeartbeat() { |
|
|
|
|
|
|
|
return new StompHeaderAccessor(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create an instance from the payload and headers of the given Message. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static StompHeaderAccessor wrap(Message<?> message) { |
|
|
|
|
|
|
|
return new StompHeaderAccessor(message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the STOMP command from the given headers, or {@code null} if not set. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static StompCommand getCommand(Map<String, Object> headers) { |
|
|
|
|
|
|
|
return (StompCommand) headers.get(COMMAND_HEADER); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the passcode header value, or {@code null} if not set. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static String getPasscode(Map<String, Object> headers) { |
|
|
|
|
|
|
|
StompPasscode credentials = (StompPasscode) headers.get(CREDENTIALS_HEADER); |
|
|
|
|
|
|
|
return (credentials != null ? credentials.passcode : null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Integer getContentLength(Map<String, List<String>> nativeHeaders) { |
|
|
|
|
|
|
|
if (nativeHeaders.containsKey(STOMP_CONTENT_LENGTH_HEADER)) { |
|
|
|
|
|
|
|
List<String> values = nativeHeaders.get(STOMP_CONTENT_LENGTH_HEADER); |
|
|
|
|
|
|
|
String value = (values != null ? values.get(0) : null); |
|
|
|
|
|
|
|
return Integer.valueOf(value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class StompPasscode { |
|
|
|
private static class StompPasscode { |
|
|
|
|
|
|
|
|
|
|
|
private final String passcode; |
|
|
|
private final String passcode; |
|
|
|
|