/** * Extract the SiMP session attributes from the given message, wrap them in * a {@link SimpAttributes} instance and bind it to the current thread. * @param message the message to extract session attributes from */ public static void setAttributesFromMessage(Message<?> message) { setAttributes(SimpAttributes.fromMessage(message)); }
@Test public void setAttributes() { SimpAttributesContextHolder.setAttributes(this.simpAttributes); assertThat(SimpAttributesContextHolder.getAttributes(), sameInstance(this.simpAttributes)); SimpAttributesContextHolder.setAttributes(null); assertThat(SimpAttributesContextHolder.getAttributes(), nullValue()); }
@Before public void setUp() { this.scope = new SimpSessionScope(); this.objectFactory = Mockito.mock(ObjectFactory.class); this.simpAttributes = new SimpAttributes("session1", new ConcurrentHashMap<>()); SimpAttributesContextHolder.setAttributes(this.simpAttributes); }
@Test public void getAttributes() { assertThat(SimpAttributesContextHolder.getAttributes(), nullValue()); SimpAttributesContextHolder.setAttributes(this.simpAttributes); assertThat(SimpAttributesContextHolder.getAttributes(), sameInstance(this.simpAttributes)); }
@Test public void currentAttributes() { SimpAttributesContextHolder.setAttributes(this.simpAttributes); assertThat(SimpAttributesContextHolder.currentAttributes(), sameInstance(this.simpAttributes)); }
@Override public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) { this.decoders.remove(session.getId()); Message<byte[]> message = createDisconnectMessage(session); SimpAttributes simpAttributes = SimpAttributes.fromMessage(message); try { SimpAttributesContextHolder.setAttributes(simpAttributes); if (this.eventPublisher != null) { Principal user = getUser(session); publishEvent(this.eventPublisher, new SessionDisconnectEvent(this, message, session.getId(), closeStatus, user)); } outputChannel.send(message); } finally { this.stompAuthentications.remove(session.getId()); SimpAttributesContextHolder.resetAttributes(); simpAttributes.sessionCompleted(); } }
@Test public void resetAttributes() { SimpAttributesContextHolder.setAttributes(this.simpAttributes); assertThat(SimpAttributesContextHolder.getAttributes(), sameInstance(this.simpAttributes)); SimpAttributesContextHolder.resetAttributes(); assertThat(SimpAttributesContextHolder.getAttributes(), nullValue()); }
try { SimpAttributes simpAttributes = new SimpAttributes(session.getId(), session.getAttributes()); SimpAttributesContextHolder.setAttributes(simpAttributes); Principal user = getUser(session); publishEvent(this.eventPublisher, new SessionConnectedEvent(this, (Message<byte[]>) message, user));
/** * Extract the SiMP session attributes from the given message, wrap them in * a {@link SimpAttributes} instance and bind it to the current thread. * @param message the message to extract session attributes from */ public static void setAttributesFromMessage(Message<?> message) { setAttributes(SimpAttributes.fromMessage(message)); }
/** * Extract the SiMP session attributes from the given message, wrap them in * a {@link SimpAttributes} instance and bind it to the current thread. * @param message the message to extract session attributes from */ public static void setAttributesFromMessage(Message<?> message) { setAttributes(SimpAttributes.fromMessage(message)); }
/** * Extract the SiMP session attributes from the given message, wrap them in * a {@link SimpAttributes} instance and bind it to the current thread. * @param message the message to extract session attributes from */ public static void setAttributesFromMessage(Message<?> message) { setAttributes(SimpAttributes.fromMessage(message)); }
@Override public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) { this.decoders.remove(session.getId()); Message<byte[]> message = createDisconnectMessage(session); SimpAttributes simpAttributes = SimpAttributes.fromMessage(message); try { SimpAttributesContextHolder.setAttributes(simpAttributes); if (this.eventPublisher != null) { Principal user = getUser(session); publishEvent(this.eventPublisher, new SessionDisconnectEvent(this, message, session.getId(), closeStatus, user)); } outputChannel.send(message); } finally { this.stompAuthentications.remove(session.getId()); SimpAttributesContextHolder.resetAttributes(); simpAttributes.sessionCompleted(); } }
@Override public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) { this.decoders.remove(session.getId()); Message<byte[]> message = createDisconnectMessage(session); SimpAttributes simpAttributes = SimpAttributes.fromMessage(message); try { SimpAttributesContextHolder.setAttributes(simpAttributes); if (this.eventPublisher != null) { Principal user = getUser(session); publishEvent(this.eventPublisher, new SessionDisconnectEvent(this, message, session.getId(), closeStatus, user)); } outputChannel.send(message); } finally { this.stompAuthentications.remove(session.getId()); SimpAttributesContextHolder.resetAttributes(); simpAttributes.sessionCompleted(); } }
try { SimpAttributes simpAttributes = new SimpAttributes(session.getId(), session.getAttributes()); SimpAttributesContextHolder.setAttributes(simpAttributes); Principal user = getUser(session); publishEvent(this.eventPublisher, new SessionConnectedEvent(this, (Message<byte[]>) message, user));
try { SimpAttributes simpAttributes = new SimpAttributes(session.getId(), session.getAttributes()); SimpAttributesContextHolder.setAttributes(simpAttributes); Principal user = getUser(session); publishEvent(this.eventPublisher, new SessionConnectedEvent(this, (Message<byte[]>) message, user));