7936bf8fd570d4632455921d52bf412c2003e21e
[JavaForFun] /
1 package de.spring.stomp.interceptors;
2
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 import org.springframework.messaging.Message;
6 import org.springframework.messaging.MessageChannel;
7 import org.springframework.messaging.simp.stomp.StompCommand;
8 import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
9 import org.springframework.messaging.support.ChannelInterceptorAdapter;
10
11 public class CustomChannelInterceptor extends ChannelInterceptorAdapter {
12         private static final Logger LOGGER = LoggerFactory.getLogger(CustomChannelInterceptor.class);
13
14           @Override
15           public Message<?> preSend(Message<?> message, MessageChannel channel) {
16             StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
17             StompCommand command = accessor.getCommand();
18
19             LOGGER.info("CustomChannelInterceptor preSend, StompCommand: " + command);
20             LOGGER.info("CustomChannelInterceptor preSend, login: " + accessor.getLogin());
21             LOGGER.info("CustomChannelInterceptor preSend, heartBeat: " + accessor.getHeartbeat());
22             LOGGER.info("CustomChannelInterceptor preSend, destination: " + accessor.getDestination());
23             LOGGER.info("CustomChannelInterceptor preSend, host: " + accessor.getHost());
24             
25             return message;
26           }
27           
28           @Override
29           public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
30             StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
31             StompCommand command = accessor.getCommand();
32
33             LOGGER.info("CustomChannelInterceptor postSend, StompCommand: " + command);
34             LOGGER.info("CustomChannelInterceptor postSend, login: " + accessor.getLogin());
35             LOGGER.info("CustomChannelInterceptor postSend, heartBeat: " + accessor.getHeartbeat());
36             LOGGER.info("CustomChannelInterceptor postSend, destination: " + accessor.getDestination());
37             LOGGER.info("CustomChannelInterceptor postSend, host: " + accessor.getHost());
38             
39           }
40 }