533ab23b5adbecda785217e1f3fa08f9ec0c6f65
[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             
22             long[] heartBeats = accessor.getHeartbeat();
23             for (long heartBeat : heartBeats) {
24                 LOGGER.info("CustomChannelInterceptor preSend, heartBeat: " + heartBeat);
25             }
26             
27             LOGGER.info("CustomChannelInterceptor preSend, destination: " + accessor.getDestination());
28             LOGGER.info("CustomChannelInterceptor preSend, host: " + accessor.getHost());
29             LOGGER.info("CustomChannelInterceptor preSend, message: " + accessor.getMessage());
30             LOGGER.info("CustomChannelInterceptor preSend, sessionId: " + accessor.getSessionId());
31             
32             
33             byte[] payload = (byte[])message.getPayload();
34             String stringPayload = new String(payload);
35             LOGGER.info("CustomChannelInterceptor preSend, payload: " + stringPayload);
36             
37             return message;
38           }
39           
40           @Override
41           public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
42             StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
43             StompCommand command = accessor.getCommand();
44
45             LOGGER.info("CustomChannelInterceptor postSend, StompCommand: " + command);
46             LOGGER.info("CustomChannelInterceptor postSend, login: " + accessor.getLogin());
47             
48             long[] heartBeats = accessor.getHeartbeat();
49             for (long heartBeat : heartBeats) {
50                 LOGGER.info("CustomChannelInterceptor postSend, heartBeat: " + heartBeat);
51             }
52             
53             LOGGER.info("CustomChannelInterceptor postSend, destination: " + accessor.getDestination());
54             LOGGER.info("CustomChannelInterceptor postSend, host: " + accessor.getHost());
55             LOGGER.info("CustomChannelInterceptor postSend, message: " + accessor.getMessage());
56             LOGGER.info("CustomChannelInterceptor postSend, sessionId: " + accessor.getSessionId());
57             
58             byte[] payload = (byte[])message.getPayload();
59             String stringPayload = new String(payload);
60             LOGGER.info("CustomChannelInterceptor preSend, payload: " + stringPayload);
61             
62           }
63
64 }