List of usage examples for org.springframework.messaging.simp SimpMessageHeaderAccessor getMessageType
@Nullable
public SimpMessageType getMessageType()
From source file:org.springframework.messaging.simp.handler.AbstractSubscriptionRegistry.java
@Override public final void registerSubscription(Message<?> message) { SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message); if (!SimpMessageType.SUBSCRIBE.equals(headers.getMessageType())) { logger.error("Expected SUBSCRIBE message: " + message); return;// www .ja v a 2 s . com } String sessionId = headers.getSessionId(); if (sessionId == null) { logger.error("Ignoring subscription. No sessionId in message: " + message); return; } String subscriptionId = headers.getSubscriptionId(); if (subscriptionId == null) { logger.error("Ignoring subscription. No subscriptionId in message: " + message); return; } String destination = headers.getDestination(); if (destination == null) { logger.error("Ignoring destination. No destination in message: " + message); return; } if (logger.isDebugEnabled()) { logger.debug("Subscribe request: " + message); } addSubscriptionInternal(sessionId, subscriptionId, destination, message); }
From source file:org.springframework.messaging.simp.handler.AbstractSubscriptionRegistry.java
@Override public final void unregisterSubscription(Message<?> message) { SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message); if (!SimpMessageType.UNSUBSCRIBE.equals(headers.getMessageType())) { logger.error("Expected UNSUBSCRIBE message: " + message); return;//from ww w. j av a 2 s . c o m } String sessionId = headers.getSessionId(); if (sessionId == null) { logger.error("Ignoring subscription. No sessionId in message: " + message); return; } String subscriptionId = headers.getSubscriptionId(); if (subscriptionId == null) { logger.error("Ignoring subscription. No subscriptionId in message: " + message); return; } if (logger.isDebugEnabled()) { logger.debug("Unubscribe request: " + message); } removeSubscriptionInternal(sessionId, subscriptionId, message); }
From source file:org.springframework.messaging.simp.handler.AbstractSubscriptionRegistry.java
@Override public final MultiValueMap<String, String> findSubscriptions(Message<?> message) { SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message); if (!SimpMessageType.MESSAGE.equals(headers.getMessageType())) { logger.error("Unexpected message type: " + message); return null; }/*from w ww .j a v a 2s .co m*/ String destination = headers.getDestination(); if (destination == null) { logger.error("Ignoring destination. No destination in message: " + message); return null; } if (logger.isTraceEnabled()) { logger.trace("Find subscriptions, destination=" + headers.getDestination()); } return findSubscriptionsInternal(destination, message); }
From source file:org.springframework.messaging.simp.handler.AnnotationMethodMessageHandler.java
@Override public void handleMessage(Message<?> message) throws MessagingException { SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message); SimpMessageType messageType = headers.getMessageType(); if (SimpMessageType.MESSAGE.equals(messageType)) { handleMessageInternal(message, this.messageMethods); } else if (SimpMessageType.SUBSCRIBE.equals(messageType)) { handleMessageInternal(message, this.subscribeMethods); } else if (SimpMessageType.UNSUBSCRIBE.equals(messageType)) { handleMessageInternal(message, this.unsubscribeMethods); }/*from w w w . j a v a 2 s .com*/ }
From source file:org.springframework.messaging.simp.handler.DefaultUserDestinationResolver.java
private UserDestinationInfo getUserDestinationInfo(SimpMessageHeaderAccessor headers) { String destination = headers.getDestination(); String targetUser;//from w w w.ja v a2 s.c o m String targetDestination; Principal user = headers.getUser(); SimpMessageType messageType = headers.getMessageType(); if (SimpMessageType.SUBSCRIBE.equals(messageType) || SimpMessageType.UNSUBSCRIBE.equals(messageType)) { if (!checkDestination(destination, this.subscriptionDestinationPrefix)) { return null; } if (user == null) { logger.warn("Ignoring message, no user information"); return null; } targetUser = user.getName(); targetDestination = destination.substring(this.destinationPrefix.length() - 1); } else if (SimpMessageType.MESSAGE.equals(messageType)) { if (!checkDestination(destination, this.destinationPrefix)) { return null; } int startIndex = this.destinationPrefix.length(); int endIndex = destination.indexOf('/', startIndex); Assert.isTrue(endIndex > 0, "Expected destination pattern \"/user/{userId}/**\""); targetUser = destination.substring(startIndex, endIndex); targetDestination = destination.substring(endIndex); } else { if (logger.isTraceEnabled()) { logger.trace("Ignoring " + messageType + " message"); } return null; } return new UserDestinationInfo(targetUser, targetDestination); }
From source file:org.springframework.messaging.simp.handler.SimpleBrokerMessageHandler.java
@Override public void handleMessage(Message<?> message) throws MessagingException { SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message); SimpMessageType messageType = headers.getMessageType(); String destination = headers.getDestination(); if (!checkDestinationPrefix(destination)) { return;/* w ww . ja va 2 s . c o m*/ } if (SimpMessageType.SUBSCRIBE.equals(messageType)) { preProcessMessage(message); this.subscriptionRegistry.registerSubscription(message); } else if (SimpMessageType.UNSUBSCRIBE.equals(messageType)) { preProcessMessage(message); this.subscriptionRegistry.unregisterSubscription(message); } else if (SimpMessageType.MESSAGE.equals(messageType)) { preProcessMessage(message); sendMessageToSubscribers(headers.getDestination(), message); } else if (SimpMessageType.DISCONNECT.equals(messageType)) { preProcessMessage(message); String sessionId = SimpMessageHeaderAccessor.wrap(message).getSessionId(); this.subscriptionRegistry.unregisterAllSubscriptions(sessionId); } }
From source file:org.springframework.messaging.simp.handler.UserDestinationMessageHandler.java
@Override public void handleMessage(Message<?> message) throws MessagingException { SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message); SimpMessageType messageType = headers.getMessageType(); String destination = headers.getDestination(); if (!SimpMessageType.MESSAGE.equals(messageType)) { return;/*w ww . j a v a 2s . com*/ } if (!checkDestination(destination)) { return; } if (logger.isTraceEnabled()) { logger.trace("Processing message to destination " + destination); } UserDestinationParser destinationParser = new UserDestinationParser(destination); String user = destinationParser.getUser(); if (user == null) { if (logger.isErrorEnabled()) { logger.error("Ignoring message, expected destination pattern \"" + this.destinationPrefix + "{userId}/**\": " + destination); } return; } for (String sessionId : this.userQueueSuffixResolver.getUserQueueSuffixes(user)) { String targetDestination = destinationParser.getTargetDestination(sessionId); headers.setDestination(targetDestination); message = MessageBuilder.withPayloadAndHeaders(message.getPayload(), headers).build(); if (logger.isTraceEnabled()) { logger.trace("Sending message to resolved target destination " + targetDestination); } this.messagingTemplate.send(targetDestination, message); } }