Add session attributes to SimpMessageHeaderAccessor

This change exposes the WebSocketSession attributes through a message header.
The StompSubProtocolHandler adds this to incoming messages.
For now messaging handling  methods can access the map via @Header, e.g.:

@Header(StompHeaderAccessor.SESSION_ATTRIBUTES) Map<String, Object> attrs) {

Issue: SPR-11566
This commit is contained in:
Rossen Stoyanchev
2014-03-19 13:45:40 -04:00
parent 48b62e80d5
commit 1bab8a3916
9 changed files with 34 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,6 +46,8 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor {
public static final String SESSION_ID_HEADER = "simpSessionId";
public static final String SESSION_ATTRIBUTES = "simpSessionAttributes";
public static final String SUBSCRIPTION_ID_HEADER = "simpSubscriptionId";
public static final String USER_HEADER = "simpUser";
@@ -127,6 +129,15 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor {
setHeader(SESSION_ID_HEADER, sessionId);
}
@SuppressWarnings("unchecked")
public Map<String, Object> getSessionAttributes() {
return (Map<String, Object>) getHeader(SESSION_ATTRIBUTES);
}
public void setSessionAttributes(Map<String, Object> attributes) {
setHeader(SESSION_ATTRIBUTES, attributes);
}
public Principal getUser() {
return (Principal) getHeader(USER_HEADER);
}