@Override public String getConversationId() { return SimpAttributesContextHolder.currentAttributes().getSessionId(); }
/** * Register a callback to execute on destruction of the specified attribute. * The callback is executed when the session is closed. * @param name the name of the attribute to register the callback for * @param callback the destruction callback to be executed */ public void registerDestructionCallback(String name, Runnable callback) { synchronized (getSessionMutex()) { if (isSessionCompleted()) { throw new IllegalStateException("Session id=" + getSessionId() + " already completed"); } this.attributes.put(DESTRUCTION_CALLBACK_NAME_PREFIX + name, callback); } }
@Test public void setAttributesFromMessage() { String sessionId = "session1"; ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<>(); SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create(); headerAccessor.setSessionId(sessionId); headerAccessor.setSessionAttributes(map); Message<?> message = MessageBuilder.createMessage("", headerAccessor.getMessageHeaders()); SimpAttributesContextHolder.setAttributesFromMessage(message); SimpAttributes attrs = SimpAttributesContextHolder.getAttributes(); assertThat(attrs, notNullValue()); assertThat(attrs.getSessionId(), is(sessionId)); attrs.setAttribute("name1", "value1"); assertThat(map.get("name1"), is("value1")); }
@Override public String getConversationId() { return SimpAttributesContextHolder.currentAttributes().getSessionId(); }
/** * Register a callback to execute on destruction of the specified attribute. * The callback is executed when the session is closed. * @param name the name of the attribute to register the callback for * @param callback the destruction callback to be executed */ public void registerDestructionCallback(String name, Runnable callback) { synchronized (getSessionMutex()) { if (isSessionCompleted()) { throw new IllegalStateException("Session id=" + getSessionId() + " already completed"); } this.attributes.put(DESTRUCTION_CALLBACK_NAME_PREFIX + name, callback); } }
@Autowired public Stomp(@Qualifier("clientOutboundChannel") MessageChannel clientChannel, SimpMessagingTemplate template) { SimpAttributes sa = SimpAttributesContextHolder.currentAttributes(); this.sessionId = sa.getSessionId(); this.template = template; this.clientChannel = clientChannel; }
@Override public String getConversationId() { return SimpAttributesContextHolder.currentAttributes().getSessionId(); }
@Override public String getConversationId() { return SimpAttributesContextHolder.currentAttributes().getSessionId(); }
/** * Register a callback to execute on destruction of the specified attribute. * The callback is executed when the session is closed. * @param name the name of the attribute to register the callback for * @param callback the destruction callback to be executed */ public void registerDestructionCallback(String name, Runnable callback) { synchronized (getSessionMutex()) { if (isSessionCompleted()) { throw new IllegalStateException("Session id=" + getSessionId() + " already completed"); } this.attributes.put(DESTRUCTION_CALLBACK_NAME_PREFIX + name, callback); } }
/** * Register a callback to execute on destruction of the specified attribute. * The callback is executed when the session is closed. * @param name the name of the attribute to register the callback for * @param callback the destruction callback to be executed */ public void registerDestructionCallback(String name, Runnable callback) { synchronized (getSessionMutex()) { if (isSessionCompleted()) { throw new IllegalStateException("Session id=" + getSessionId() + " already completed"); } this.attributes.put(DESTRUCTION_CALLBACK_NAME_PREFIX + name, callback); } }