Spring STOMP: a few improvements
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 13 Jul 2016 00:23:58 +0000 (02:23 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 13 Jul 2016 00:23:58 +0000 (02:23 +0200)
SpringJava/STOMP/spring-stomp-server-full/src/main/resources/log4j2.xml
SpringJava/STOMP/spring-stomp-server-simple/src/main/java/de/spring/stomp/interceptors/CustomChannelInterceptor.java
SpringJava/STOMP/spring-stomp-server-simple/src/main/java/de/spring/stomp/listeners/SessionConnectListener.java
SpringJava/STOMP/spring-stomp-server-simple/src/main/java/de/spring/stomp/listeners/SessionConnectedListener.java
SpringJava/STOMP/spring-stomp-server-simple/src/main/java/de/spring/stomp/listeners/SessionDisconnectListener.java
SpringJava/STOMP/spring-stomp-server-simple/src/main/java/de/spring/stomp/listeners/SessionSubscribeListener.java
SpringJava/STOMP/spring-stomp-server-simple/src/main/resources/log4j2.xml

index 281da4f..fe6e7db 100644 (file)
                        level="TRACE" additivity="false">
             <AppenderRef ref="STDOUT" />
         </Logger>
+        
+        
+        <!-- 
+               Separate logger to use on network IO failure after a client has gone away.
+               See: DISCONNECTED_CLIENT_LOG_CATEGORY in org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession
+         -->
+        <Logger
+               name="org.springframework.web.socket.sockjs.DisconnectedClient"
+                       level="TRACE" additivity="false">
+            <AppenderRef ref="STDOUT" />
+        </Logger>
     
                <!-- 
                General logging Spring.
index 7936bf8..533ab23 100644 (file)
@@ -15,12 +15,24 @@ public class CustomChannelInterceptor extends ChannelInterceptorAdapter {
          public Message<?> preSend(Message<?> message, MessageChannel channel) {
            StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
            StompCommand command = accessor.getCommand();
-
+           
            LOGGER.info("CustomChannelInterceptor preSend, StompCommand: " + command);
            LOGGER.info("CustomChannelInterceptor preSend, login: " + accessor.getLogin());
-           LOGGER.info("CustomChannelInterceptor preSend, heartBeat: " + accessor.getHeartbeat());
+           
+           long[] heartBeats = accessor.getHeartbeat();
+           for (long heartBeat : heartBeats) {
+               LOGGER.info("CustomChannelInterceptor preSend, heartBeat: " + heartBeat);
+           }
+           
            LOGGER.info("CustomChannelInterceptor preSend, destination: " + accessor.getDestination());
            LOGGER.info("CustomChannelInterceptor preSend, host: " + accessor.getHost());
+           LOGGER.info("CustomChannelInterceptor preSend, message: " + accessor.getMessage());
+           LOGGER.info("CustomChannelInterceptor preSend, sessionId: " + accessor.getSessionId());
+           
+           
+           byte[] payload = (byte[])message.getPayload();
+           String stringPayload = new String(payload);
+           LOGGER.info("CustomChannelInterceptor preSend, payload: " + stringPayload);
            
            return message;
          }
@@ -32,9 +44,21 @@ public class CustomChannelInterceptor extends ChannelInterceptorAdapter {
 
            LOGGER.info("CustomChannelInterceptor postSend, StompCommand: " + command);
            LOGGER.info("CustomChannelInterceptor postSend, login: " + accessor.getLogin());
-           LOGGER.info("CustomChannelInterceptor postSend, heartBeat: " + accessor.getHeartbeat());
+           
+           long[] heartBeats = accessor.getHeartbeat();
+           for (long heartBeat : heartBeats) {
+               LOGGER.info("CustomChannelInterceptor postSend, heartBeat: " + heartBeat);
+           }
+           
            LOGGER.info("CustomChannelInterceptor postSend, destination: " + accessor.getDestination());
            LOGGER.info("CustomChannelInterceptor postSend, host: " + accessor.getHost());
+           LOGGER.info("CustomChannelInterceptor postSend, message: " + accessor.getMessage());
+           LOGGER.info("CustomChannelInterceptor postSend, sessionId: " + accessor.getSessionId());
+           
+           byte[] payload = (byte[])message.getPayload();
+           String stringPayload = new String(payload);
+           LOGGER.info("CustomChannelInterceptor preSend, payload: " + stringPayload);
            
          }
+
 }
index da374e5..49bc9c7 100644 (file)
@@ -3,16 +3,39 @@ package de.spring.stomp.listeners;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationListener;
+import org.springframework.messaging.simp.stomp.StompCommand;
+import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
 import org.springframework.web.socket.messaging.SessionConnectEvent;
 
 public class SessionConnectListener implements ApplicationListener<SessionConnectEvent> {
        private static final Logger LOGGER = LoggerFactory.getLogger(SessionConnectListener.class);
        
        @Override
-       public void onApplicationEvent(SessionConnectEvent event) {
+       public void onApplicationEvent(SessionConnectEvent event) {             
                LOGGER.info("SessionConnectEvent timestamp: " + event.getTimestamp());
                LOGGER.info("SessionConnectEvent user: " + event.getUser());
                LOGGER.info("SessionConnectEvent: " + event.toString());
+               
+               StompHeaderAccessor accessor = StompHeaderAccessor.wrap(event.getMessage());
+           StompCommand command = accessor.getCommand();
+           
+           LOGGER.info("SessionConnectEvent, StompCommand: " + command);
+           LOGGER.info("SessionConnectEvent, login: " + accessor.getLogin()); 
+           
+           long[] heartBeats = accessor.getHeartbeat();
+           for (long heartBeat : heartBeats) {
+               LOGGER.info("SessionConnectEvent, heartBeat: " + heartBeat);
+           }
+           
+           LOGGER.info("SessionConnectEvent, destination: " + accessor.getDestination());
+           LOGGER.info("SessionConnectEvent, host: " + accessor.getHost());
+           LOGGER.info("SessionConnectEvent, message: " + accessor.getMessage());
+           LOGGER.info("SessionConnectEvent, sessionId: " + accessor.getSessionId());
+           LOGGER.info("SessionConnectEvent, subscriptionId: " + accessor.getSubscriptionId());
+           
+           byte[] payload = (byte[])event.getMessage().getPayload();
+           String stringPayload = new String(payload);
+           LOGGER.info("SessionConnectEvent, payload: " + stringPayload);
        }
 
 }
index b0444f3..cc5d482 100644 (file)
@@ -3,6 +3,8 @@ package de.spring.stomp.listeners;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationListener;
+import org.springframework.messaging.simp.stomp.StompCommand;
+import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
 import org.springframework.web.socket.messaging.SessionConnectedEvent;
 
 public class SessionConnectedListener implements ApplicationListener<SessionConnectedEvent> {
@@ -13,6 +15,28 @@ public class SessionConnectedListener implements ApplicationListener<SessionConn
                LOGGER.info("SessionConnectedEvent timestamp: " + event.getTimestamp());
                LOGGER.info("SessionConnectedEvent user: " + event.getUser());
                LOGGER.info("SessionConnectedEvent: " + event.toString());
+               
+               StompHeaderAccessor accessor = StompHeaderAccessor.wrap(event.getMessage());
+           StompCommand command = accessor.getCommand();
+           
+           LOGGER.info("SessionConnectedEvent, StompCommand: " + command);
+           LOGGER.info("SessionConnectedEvent, login: " + accessor.getLogin()); 
+           
+           long[] heartBeats = accessor.getHeartbeat();
+           for (long heartBeat : heartBeats) {
+               LOGGER.info("SessionConnectedEvent, heartBeat: " + heartBeat);
+           }
+           
+           LOGGER.info("SessionConnectedEvent, destination: " + accessor.getDestination());
+           LOGGER.info("SessionConnectedEvent, host: " + accessor.getHost());
+           LOGGER.info("SessionConnectedEvent, message: " + accessor.getMessage());
+           LOGGER.info("SessionConnectedEvent, sessionId: " + accessor.getSessionId());
+           LOGGER.info("SessionConnectedEvent, subscriptionId: " + accessor.getSubscriptionId());
+           
+           
+           byte[] payload = (byte[])event.getMessage().getPayload();
+           String stringPayload = new String(payload);
+           LOGGER.info("SessionConnectedEvent, payload: " + stringPayload);
        }
 
 }
index 59ff3e4..cf66764 100644 (file)
@@ -3,6 +3,8 @@ package de.spring.stomp.listeners;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationListener;
+import org.springframework.messaging.simp.stomp.StompCommand;
+import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
 import org.springframework.web.socket.messaging.SessionDisconnectEvent;
 
 public class SessionDisconnectListener implements ApplicationListener<SessionDisconnectEvent> {
@@ -15,6 +17,27 @@ public class SessionDisconnectListener implements ApplicationListener<SessionDis
                LOGGER.info("SessionDisconnectEvent sessionId: " + event.getSessionId());
                LOGGER.info("SessionDisconnectEvent close status: " + event.getCloseStatus());
                LOGGER.info("SessionDisconnectEvent: " + event.toString());
+               
+               StompHeaderAccessor accessor = StompHeaderAccessor.wrap(event.getMessage());
+           StompCommand command = accessor.getCommand();
+           
+           LOGGER.info("SessionDisconnectEvent, StompCommand: " + command);
+           LOGGER.info("SessionDisconnectEvent, login: " + accessor.getLogin()); 
+           
+           long[] heartBeats = accessor.getHeartbeat();
+           for (long heartBeat : heartBeats) {
+               LOGGER.info("SessionDisconnectEvent, heartBeat: " + heartBeat);
+           }
+           
+           LOGGER.info("SessionDisconnectEvent, destination: " + accessor.getDestination());
+           LOGGER.info("SessionDisconnectEvent, host: " + accessor.getHost());
+           LOGGER.info("SessionDisconnectEvent, message: " + accessor.getMessage());
+           LOGGER.info("SessionDisconnectEvent, sessionId: " + accessor.getSessionId());
+           LOGGER.info("SessionDisconnectEvent, subscriptionId: " + accessor.getSubscriptionId());
+           
+           byte[] payload = (byte[])event.getMessage().getPayload();
+           String stringPayload = new String(payload);
+           LOGGER.info("SessionDisconnectEvent, payload: " + stringPayload);
        }
 
 }
index 90ee1da..7f37671 100644 (file)
@@ -3,6 +3,8 @@ package de.spring.stomp.listeners;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationListener;
+import org.springframework.messaging.simp.stomp.StompCommand;
+import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
 import org.springframework.web.socket.messaging.SessionSubscribeEvent;
 
 public class SessionSubscribeListener implements ApplicationListener<SessionSubscribeEvent> {
@@ -13,6 +15,27 @@ public class SessionSubscribeListener implements ApplicationListener<SessionSubs
                LOGGER.info("SessionSubscribeEvent timestamp: " + event.getTimestamp());
                LOGGER.info("SessionSubscribeEvent user: " + event.getUser());
                LOGGER.info("SessionSubscribeEvent: " + event.toString());
+               
+               StompHeaderAccessor accessor = StompHeaderAccessor.wrap(event.getMessage());
+           StompCommand command = accessor.getCommand();
+           
+           LOGGER.info("SessionSubscribeEvent, StompCommand: " + command);
+           LOGGER.info("SessionSubscribeEvent, login: " + accessor.getLogin());
+           
+           long[] heartBeats = accessor.getHeartbeat();
+           for (long heartBeat : heartBeats) {
+               LOGGER.info("CustomChannelInterceptor preSend, heartBeat: " + heartBeat);
+           }
+           
+           LOGGER.info("SessionSubscribeEvent, destination: " + accessor.getDestination());
+           LOGGER.info("SessionSubscribeEvent, host: " + accessor.getHost());
+           LOGGER.info("SessionSubscribeEvent, message: " + accessor.getMessage());
+           LOGGER.info("SessionSubscribeEvent, sessionId: " + accessor.getSessionId());
+           LOGGER.info("SessionSubscribeEvent, subscriptionId: " + accessor.getSubscriptionId());
+           
+           byte[] payload = (byte[])event.getMessage().getPayload();
+           String stringPayload = new String(payload);
+           LOGGER.info("SessionSubscribeEvent, payload: " + stringPayload);
        }
 
 }
index 281da4f..fe6e7db 100644 (file)
                        level="TRACE" additivity="false">
             <AppenderRef ref="STDOUT" />
         </Logger>
+        
+        
+        <!-- 
+               Separate logger to use on network IO failure after a client has gone away.
+               See: DISCONNECTED_CLIENT_LOG_CATEGORY in org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession
+         -->
+        <Logger
+               name="org.springframework.web.socket.sockjs.DisconnectedClient"
+                       level="TRACE" additivity="false">
+            <AppenderRef ref="STDOUT" />
+        </Logger>
     
                <!-- 
                General logging Spring.