use of org.springframework.messaging.simp.stomp.StompCommand in project JavaForFun by gumartinm.
the class SessionConnectedListener method onApplicationEvent.
@Override
public void onApplicationEvent(SessionConnectedEvent event) {
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);
}
use of org.springframework.messaging.simp.stomp.StompCommand in project JavaForFun by gumartinm.
the class SessionDisconnectListener method onApplicationEvent.
@Override
public void onApplicationEvent(SessionDisconnectEvent event) {
LOGGER.info("SessionDisconnectEvent timestamp: " + event.getTimestamp());
LOGGER.info("SessionDisconnectEvent user: " + event.getUser());
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);
}
use of org.springframework.messaging.simp.stomp.StompCommand in project JavaForFun by gumartinm.
the class SessionSubscribeListener method onApplicationEvent.
@Override
public void onApplicationEvent(SessionSubscribeEvent event) {
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);
}
use of org.springframework.messaging.simp.stomp.StompCommand in project spring-framework by spring-projects.
the class StompSubProtocolHandler method handleMessageToClient.
/**
* Handle STOMP messages going back out to WebSocket clients.
*/
@Override
@SuppressWarnings("unchecked")
public void handleMessageToClient(WebSocketSession session, Message<?> message) {
if (!(message.getPayload() instanceof byte[])) {
if (logger.isErrorEnabled()) {
logger.error("Expected byte[] payload. Ignoring " + message + ".");
}
return;
}
StompHeaderAccessor accessor = getStompHeaderAccessor(message);
StompCommand command = accessor.getCommand();
if (StompCommand.MESSAGE.equals(command)) {
if (accessor.getSubscriptionId() == null && logger.isWarnEnabled()) {
logger.warn("No STOMP \"subscription\" header in " + message);
}
String origDestination = accessor.getFirstNativeHeader(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION);
if (origDestination != null) {
accessor = toMutableAccessor(accessor, message);
accessor.removeNativeHeader(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION);
accessor.setDestination(origDestination);
}
} else if (StompCommand.CONNECTED.equals(command)) {
this.stats.incrementConnectedCount();
accessor = afterStompSessionConnected(message, accessor, session);
if (this.eventPublisher != null) {
try {
SimpAttributes simpAttributes = new SimpAttributes(session.getId(), session.getAttributes());
SimpAttributesContextHolder.setAttributes(simpAttributes);
Principal user = getUser(session);
publishEvent(this.eventPublisher, new SessionConnectedEvent(this, (Message<byte[]>) message, user));
} finally {
SimpAttributesContextHolder.resetAttributes();
}
}
}
byte[] payload = (byte[]) message.getPayload();
if (StompCommand.ERROR.equals(command) && getErrorHandler() != null) {
Message<byte[]> errorMessage = getErrorHandler().handleErrorMessageToClient((Message<byte[]>) message);
if (errorMessage != null) {
accessor = MessageHeaderAccessor.getAccessor(errorMessage, StompHeaderAccessor.class);
Assert.state(accessor != null, "No StompHeaderAccessor");
payload = errorMessage.getPayload();
}
}
Runnable task = OrderedMessageChannelDecorator.getNextMessageTask(message);
if (task != null) {
Assert.isInstanceOf(ConcurrentWebSocketSessionDecorator.class, session);
((ConcurrentWebSocketSessionDecorator) session).setMessageCallback(m -> task.run());
}
sendToClient(session, accessor, payload);
}
Aggregations