1 package de.spring.stomp.interceptors;
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;
11 public class CustomChannelInterceptor extends ChannelInterceptorAdapter {
12 private static final Logger LOGGER = LoggerFactory.getLogger(CustomChannelInterceptor.class);
15 public Message<?> preSend(Message<?> message, MessageChannel channel) {
16 StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
17 StompCommand command = accessor.getCommand();
19 LOGGER.info("CustomChannelInterceptor preSend, StompCommand: " + command);
20 LOGGER.info("CustomChannelInterceptor preSend, login: " + accessor.getLogin());
22 long[] heartBeats = accessor.getHeartbeat();
23 for (long heartBeat : heartBeats) {
24 LOGGER.info("CustomChannelInterceptor preSend, heartBeat: " + heartBeat);
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());
33 byte[] payload = (byte[])message.getPayload();
34 String stringPayload = new String(payload);
35 LOGGER.info("CustomChannelInterceptor preSend, payload: " + stringPayload);
41 public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
42 StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
43 StompCommand command = accessor.getCommand();
45 LOGGER.info("CustomChannelInterceptor postSend, StompCommand: " + command);
46 LOGGER.info("CustomChannelInterceptor postSend, login: " + accessor.getLogin());
48 long[] heartBeats = accessor.getHeartbeat();
49 for (long heartBeat : heartBeats) {
50 LOGGER.info("CustomChannelInterceptor postSend, heartBeat: " + heartBeat);
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());
58 byte[] payload = (byte[])message.getPayload();
59 String stringPayload = new String(payload);
60 LOGGER.info("CustomChannelInterceptor preSend, payload: " + stringPayload);