diff --git a/src/main/java/getaguitar/site/demo/Controller/APIController.java b/src/main/java/getaguitar/site/demo/Controller/APIController.java index c15af8a..d0f123a 100644 --- a/src/main/java/getaguitar/site/demo/Controller/APIController.java +++ b/src/main/java/getaguitar/site/demo/Controller/APIController.java @@ -1,5 +1,4 @@ package getaguitar.site.demo.Controller; -import com.fasterxml.jackson.core.JsonProcessingException; import getaguitar.site.demo.Dto.ResUserDto; import getaguitar.site.demo.Service.APIService; import lombok.RequiredArgsConstructor; @@ -14,7 +13,7 @@ public class APIController { private final APIService apiService; @GetMapping("/user") - public ResUserDto getUser() throws JsonProcessingException { + public ResUserDto getUser() { return apiService.getUser(); } } diff --git a/src/main/java/getaguitar/site/demo/Controller/StompController.java b/src/main/java/getaguitar/site/demo/Controller/StompController.java index a52e307..d0587b6 100644 --- a/src/main/java/getaguitar/site/demo/Controller/StompController.java +++ b/src/main/java/getaguitar/site/demo/Controller/StompController.java @@ -1,36 +1,36 @@ -//package getaguitar.site.demo.Controller; -// -//import lombok.RequiredArgsConstructor; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.context.event.EventListener; -//import org.springframework.messaging.handler.annotation.MessageMapping; -//import org.springframework.messaging.handler.annotation.SendTo; -//import org.springframework.messaging.simp.SimpMessageSendingOperations; -//import org.springframework.messaging.simp.stomp.StompHeaderAccessor; -//import org.springframework.web.bind.annotation.RestController; -//import org.springframework.web.socket.messaging.SessionConnectEvent; -//import org.springframework.web.socket.messaging.SessionDisconnectEvent; -// -//import java.util.Map; -// -// -//@RestController -//@RequiredArgsConstructor -//public class StompController { -// private static final Logger LOGGER = LoggerFactory.getLogger( StompController.class ); -// -// private final SimpMessageSendingOperations simpleMessageSendingOperations; -// -// @EventListener -// public void handleWebSocketConnectListener(SessionConnectEvent event) { -// StompHeaderAccessor headerAccesor = StompHeaderAccessor.wrap(event.getMessage()); -// String sessionId = headerAccesor.getSessionId(); -// } -// -// @EventListener -// public void handleWebSocketDisconnectListener(SessionDisconnectEvent event) { -// StompHeaderAccessor headerAccesor = StompHeaderAccessor.wrap(event.getMessage()); -// String sessionId = headerAccesor.getSessionId(); -// } -//} +package getaguitar.site.demo.Controller; + +import lombok.RequiredArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.event.EventListener; +import org.springframework.messaging.handler.annotation.MessageMapping; +import org.springframework.messaging.handler.annotation.SendTo; +import org.springframework.messaging.simp.SimpMessageSendingOperations; +import org.springframework.messaging.simp.stomp.StompHeaderAccessor; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.socket.messaging.SessionConnectEvent; +import org.springframework.web.socket.messaging.SessionDisconnectEvent; + +import java.util.Map; + + +@RestController +@RequiredArgsConstructor +public class StompController { + private static final Logger LOGGER = LoggerFactory.getLogger( StompController.class ); + + private final SimpMessageSendingOperations simpleMessageSendingOperations; + + @EventListener + public void handleWebSocketConnectListener(SessionConnectEvent event) { + StompHeaderAccessor headerAccesor = StompHeaderAccessor.wrap(event.getMessage()); + String sessionId = headerAccesor.getSessionId(); + } + + @EventListener + public void handleWebSocketDisconnectListener(SessionDisconnectEvent event) { + StompHeaderAccessor headerAccesor = StompHeaderAccessor.wrap(event.getMessage()); + String sessionId = headerAccesor.getSessionId(); + } +} diff --git a/src/main/java/getaguitar/site/demo/Interceptor/StompHandler.java b/src/main/java/getaguitar/site/demo/Interceptor/StompHandler.java index 5a95936..c933f6c 100644 --- a/src/main/java/getaguitar/site/demo/Interceptor/StompHandler.java +++ b/src/main/java/getaguitar/site/demo/Interceptor/StompHandler.java @@ -1,36 +1,36 @@ -//package getaguitar.site.demo.Interceptor; -// -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.messaging.Message; -//import org.springframework.messaging.MessageChannel; -//import org.springframework.messaging.simp.stomp.StompHeaderAccessor; -//import org.springframework.messaging.support.ChannelInterceptor; -//import org.springframework.stereotype.Component; -//import org.springframework.web.bind.annotation.CrossOrigin; -//import org.springframework.web.bind.annotation.RequestMethod; -// -//@Component -//@CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET}) -//public class StompHandler implements ChannelInterceptor { -// -// private static final Logger LOGGER = LoggerFactory.getLogger( StompHandler.class ); -// -// @Override -// public void postSend(Message message, MessageChannel channel, boolean sent) { -// StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message); -// String sessionId = accessor.getSessionId(); -// -// switch ((accessor.getCommand())) { -// case CONNECT: -// LOGGER.info("Received a new web socket connection {}", sessionId); -// break; -// case DISCONNECT: -// LOGGER.info("sessionId Disconnected {}", sessionId); -// break; -// default: -// break; -// } -// -// } -//} \ No newline at end of file +package getaguitar.site.demo.Interceptor; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.simp.stomp.StompHeaderAccessor; +import org.springframework.messaging.support.ChannelInterceptor; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.RequestMethod; + +@Component +@CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET}) +public class StompHandler implements ChannelInterceptor { + + private static final Logger LOGGER = LoggerFactory.getLogger( StompHandler.class ); + + @Override + public void postSend(Message message, MessageChannel channel, boolean sent) { + StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message); + String sessionId = accessor.getSessionId(); + + switch ((accessor.getCommand())) { + case CONNECT: + LOGGER.info("Received a new web socket connection {}", sessionId); + break; + case DISCONNECT: + LOGGER.info("sessionId Disconnected {}", sessionId); + break; + default: + break; + } + + } +} \ No newline at end of file