Skip to content

Commit

Permalink
fix : cors에러 test
Browse files Browse the repository at this point in the history
  • Loading branch information
yunuo46 committed May 10, 2024
1 parent 79009a0 commit 5552955
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,7 +13,7 @@ public class APIController {
private final APIService apiService;

@GetMapping("/user")
public ResUserDto getUser() throws JsonProcessingException {
public ResUserDto getUser() {
return apiService.getUser();
}
}
72 changes: 36 additions & 36 deletions src/main/java/getaguitar/site/demo/Controller/StompController.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
72 changes: 36 additions & 36 deletions src/main/java/getaguitar/site/demo/Interceptor/StompHandler.java
Original file line number Diff line number Diff line change
@@ -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;
// }
//
// }
//}
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;
}

}
}

0 comments on commit 5552955

Please sign in to comment.