@Test public void handleMessageFromClient() { TextMessage textMessage = StompTextMessageBuilder.create(StompCommand.CONNECT) .headers( "login:guest", "passcode:guest", "accept-version:1.1,1.0", "heart-beat:10000,10000") .build(); this.protocolHandler.handleMessageFromClient(this.session, textMessage, this.channel); verify(this.channel).send(this.messageCaptor.capture()); Message<?> actual = this.messageCaptor.getValue(); assertNotNull(actual); StompHeaderAccessor headers = StompHeaderAccessor.wrap(actual); assertEquals(StompCommand.CONNECT, headers.getCommand()); assertEquals("s1", headers.getSessionId()); assertEquals("joe", headers.getUser().getName()); assertEquals("guest", headers.getLogin()); assertEquals("PROTECTED", headers.getPasscode()); assertArrayEquals(new long[] {10000, 10000}, headers.getHeartbeat()); assertEquals(new HashSet<>(Arrays.asList("1.1", "1.0")), headers.getAcceptVersion()); assertEquals(0, this.session.getSentMessages().size()); }
@SubscribeMapping("/topic/activity") @SendTo("/topic/tracker") public ActivityDTO sendActivity( @Payload ActivityDTO activityDTO, StompHeaderAccessor stompHeaderAccessor, Principal principal) { activityDTO.setUserLogin(SecurityUtils.getCurrentLogin()); activityDTO.setUserLogin(principal.getName()); activityDTO.setSessionId(stompHeaderAccessor.getSessionId()); activityDTO.setIpAddress(stompHeaderAccessor.getSessionAttributes().get(IP_ADDRESS).toString()); activityDTO.setTime(dateTimeFormatter.print(Calendar.getInstance().getTimeInMillis())); log.debug("Sending user tracking data {}", activityDTO); return activityDTO; }