diff --git a/src/main/java/com/example/CatchStudy/global/config/StompHandler.java b/src/main/java/com/example/CatchStudy/global/config/StompHandler.java index 2574f0d..15f1b14 100644 --- a/src/main/java/com/example/CatchStudy/global/config/StompHandler.java +++ b/src/main/java/com/example/CatchStudy/global/config/StompHandler.java @@ -31,10 +31,16 @@ public Message preSend(Message message, MessageChannel channel) { System.out.println("-------------accessor : " + accessor); System.out.println("--------accessor header : " + accessor.getNativeHeader("Authorization")); - // 연결 요청에 대해 실행 - if(accessor.getCommand() == StompCommand.CONNECT) { + // 연결, 해제, 메시지 전송 요청에 대해 실행 + if((accessor.getCommand() == StompCommand.CONNECT) || (accessor.getCommand() == StompCommand.DISCONNECT) + || (accessor.getCommand() == StompCommand.SEND)) { + accessToken = accessor.getFirstNativeHeader("Authorization"); + if (StringUtils.hasText(accessToken) && accessToken.startsWith("Bearer ")) { + accessToken = accessToken.substring(7); + } + try { jwtUtil.validateAccessToken(accessToken); } catch (ExpiredJwtException e) { @@ -46,10 +52,6 @@ public Message preSend(Message message, MessageChannel channel) { accessor.setUser(authentication); } - if (StringUtils.hasText(accessToken) && accessToken.startsWith("Bearer ")) { - accessToken = accessToken.substring(7); - } - return message; } } diff --git a/src/main/java/com/example/CatchStudy/service/ChatService.java b/src/main/java/com/example/CatchStudy/service/ChatService.java index 8253919..b4c8dab 100644 --- a/src/main/java/com/example/CatchStudy/service/ChatService.java +++ b/src/main/java/com/example/CatchStudy/service/ChatService.java @@ -80,7 +80,7 @@ public List getMessageList(long chatRoomId) { List chatNotificationList = chatNotificationRepository.findAllByChatRoom_ChatRoomIdAndUser_UserId(chatRoomId, userId); // 알림 읽음 처리 for(ChatNotification chatNotification : chatNotificationList) { - chatNotification.readNotification(); + chatNotification.readNotification(); } return messageRepository.findByChatRoomId(chatRoomId).stream().map(MessageResponseDto::new).toList(); @@ -112,7 +112,8 @@ public MessageResponseDto createMessage(long chatRoomId, MessageRequestDto messa @EventListener public void handleSessionConnect(SessionConnectEvent event) { - MessageHeaderAccessor accessor = NativeMessageHeaderAccessor.getAccessor(event.getMessage(), SimpMessageHeaderAccessor.class); + StompHeaderAccessor accessor = StompHeaderAccessor.wrap(event.getMessage()); + System.out.println("chatService : " + accessor); GenericMessage generic = (GenericMessage) accessor.getHeader("simpConnectMessage"); Map nativeHeaders = (Map) generic.getHeaders().get("nativeHeaders");