-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 36 additions & 36 deletions
72
src/main/java/getaguitar/site/demo/Controller/StompController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
72
src/main/java/getaguitar/site/demo/Interceptor/StompHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
} |