Skip to content

Commit

Permalink
Merge pull request #105 from fourix4/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
TaeHoon0 authored Jul 23, 2024
2 parents d22bf56 + 561b59b commit af3a184
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}
5 changes: 3 additions & 2 deletions src/main/java/com/example/CatchStudy/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public List<MessageResponseDto> getMessageList(long chatRoomId) {
List<ChatNotification> chatNotificationList = chatNotificationRepository.findAllByChatRoom_ChatRoomIdAndUser_UserId(chatRoomId, userId);
// 알림 읽음 처리
for(ChatNotification chatNotification : chatNotificationList) {
chatNotification.readNotification();
chatNotification.readNotification();
}

return messageRepository.findByChatRoomId(chatRoomId).stream().map(MessageResponseDto::new).toList();
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit af3a184

Please sign in to comment.