Java Code Examples for org.springframework.messaging.simp.SimpMessageHeaderAccessor#getMessageType()
The following examples show how to use
org.springframework.messaging.simp.SimpMessageHeaderAccessor#getMessageType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultUserDestinationResolver.java From spring-analysis-note with MIT License | 6 votes |
@Nullable private ParseResult parse(Message<?> message) { MessageHeaders headers = message.getHeaders(); String sourceDestination = SimpMessageHeaderAccessor.getDestination(headers); if (sourceDestination == null || !checkDestination(sourceDestination, this.prefix)) { return null; } SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers); if (messageType != null) { switch (messageType) { case SUBSCRIBE: case UNSUBSCRIBE: return parseSubscriptionMessage(message, sourceDestination); case MESSAGE: return parseMessage(headers, sourceDestination); } } return null; }
Example 2
Source File: AbstractSubscriptionRegistry.java From spring-analysis-note with MIT License | 6 votes |
@Override public final MultiValueMap<String, String> findSubscriptions(Message<?> message) { MessageHeaders headers = message.getHeaders(); SimpMessageType type = SimpMessageHeaderAccessor.getMessageType(headers); if (!SimpMessageType.MESSAGE.equals(type)) { throw new IllegalArgumentException("Unexpected message type: " + type); } String destination = SimpMessageHeaderAccessor.getDestination(headers); if (destination == null) { if (logger.isErrorEnabled()) { logger.error("No destination in " + message); } return EMPTY_MAP; } return findSubscriptionsInternal(destination, message); }
Example 3
Source File: SessionRepositoryMessageInterceptor.java From spring-session with Apache License 2.0 | 6 votes |
@Override public Message<?> preSend(Message<?> message, MessageChannel channel) { if (message == null) { return message; } SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders()); if (!this.matchingMessageTypes.contains(messageType)) { return message; } Map<String, Object> sessionHeaders = SimpMessageHeaderAccessor.getSessionAttributes(message.getHeaders()); String sessionId = (sessionHeaders != null) ? (String) sessionHeaders.get(SPRING_SESSION_ID_ATTR_NAME) : null; if (sessionId != null) { S session = this.sessionRepository.findById(sessionId); if (session != null) { // update the last accessed time session.setLastAccessedTime(Instant.now()); this.sessionRepository.save(session); } } return message; }
Example 4
Source File: AbstractSubscriptionRegistry.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public final void unregisterSubscription(Message<?> message) { MessageHeaders headers = message.getHeaders(); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers); if (!SimpMessageType.UNSUBSCRIBE.equals(messageType)) { throw new IllegalArgumentException("Expected UNSUBSCRIBE: " + message); } String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); if (sessionId == null) { logger.error("No sessionId in " + message); return; } String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers); if (subscriptionId == null) { logger.error("No subscriptionId " + message); return; } removeSubscriptionInternal(sessionId, subscriptionId, message); }
Example 5
Source File: DefaultUserDestinationResolver.java From java-technology-stack with MIT License | 6 votes |
@Nullable private ParseResult parse(Message<?> message) { MessageHeaders headers = message.getHeaders(); String sourceDestination = SimpMessageHeaderAccessor.getDestination(headers); if (sourceDestination == null || !checkDestination(sourceDestination, this.prefix)) { return null; } SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers); if (messageType != null) { switch (messageType) { case SUBSCRIBE: case UNSUBSCRIBE: return parseSubscriptionMessage(message, sourceDestination); case MESSAGE: return parseMessage(headers, sourceDestination); } } return null; }
Example 6
Source File: AbstractSubscriptionRegistry.java From java-technology-stack with MIT License | 6 votes |
@Override public final MultiValueMap<String, String> findSubscriptions(Message<?> message) { MessageHeaders headers = message.getHeaders(); SimpMessageType type = SimpMessageHeaderAccessor.getMessageType(headers); if (!SimpMessageType.MESSAGE.equals(type)) { throw new IllegalArgumentException("Unexpected message type: " + type); } String destination = SimpMessageHeaderAccessor.getDestination(headers); if (destination == null) { if (logger.isErrorEnabled()) { logger.error("No destination in " + message); } return EMPTY_MAP; } return findSubscriptionsInternal(destination, message); }
Example 7
Source File: StompBrokerRelayMessageHandlerIntegrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public void handleMessage(Message<?> message) throws MessagingException { if (SimpMessageType.HEARTBEAT == SimpMessageHeaderAccessor.getMessageType(message.getHeaders())) { return; } this.queue.add(message); }
Example 8
Source File: AbstractBrokerMessageHandler.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public void afterSendCompletion(Message<?> message, MessageChannel channel, boolean sent, Exception ex) { if (!sent) { SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders()); if (SimpMessageType.DISCONNECT.equals(messageType)) { logger.debug("Detected unsent DISCONNECT message. Processing anyway."); handleMessage(message); } } }
Example 9
Source File: AbstractSubscriptionRegistry.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public final void registerSubscription(Message<?> message) { MessageHeaders headers = message.getHeaders(); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers); if (!SimpMessageType.SUBSCRIBE.equals(messageType)) { throw new IllegalArgumentException("Expected SUBSCRIBE: " + message); } String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); if (sessionId == null) { logger.error("No sessionId in " + message); return; } String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers); if (subscriptionId == null) { logger.error("No subscriptionId in " + message); return; } String destination = SimpMessageHeaderAccessor.getDestination(headers); if (destination == null) { logger.error("No destination in " + message); return; } addSubscriptionInternal(sessionId, subscriptionId, destination, message); }
Example 10
Source File: StompSubProtocolHandler.java From java-technology-stack with MIT License | 5 votes |
private StompHeaderAccessor getStompHeaderAccessor(Message<?> message) { MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class); if (accessor instanceof StompHeaderAccessor) { return (StompHeaderAccessor) accessor; } else { StompHeaderAccessor stompAccessor = StompHeaderAccessor.wrap(message); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders()); if (SimpMessageType.CONNECT_ACK.equals(messageType)) { stompAccessor = convertConnectAcktoStompConnected(stompAccessor); } else if (SimpMessageType.DISCONNECT_ACK.equals(messageType)) { String receipt = getDisconnectReceipt(stompAccessor); if (receipt != null) { stompAccessor = StompHeaderAccessor.create(StompCommand.RECEIPT); stompAccessor.setReceiptId(receipt); } else { stompAccessor = StompHeaderAccessor.create(StompCommand.ERROR); stompAccessor.setMessage("Session closed."); } } else if (SimpMessageType.HEARTBEAT.equals(messageType)) { stompAccessor = StompHeaderAccessor.createForHeartbeat(); } else if (stompAccessor.getCommand() == null || StompCommand.SEND.equals(stompAccessor.getCommand())) { stompAccessor.updateStompCommandAsServerMessage(); } return stompAccessor; } }
Example 11
Source File: StompBrokerRelayMessageHandlerIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
@Override public void handleMessage(Message<?> message) throws MessagingException { if (SimpMessageType.HEARTBEAT == SimpMessageHeaderAccessor.getMessageType(message.getHeaders())) { return; } this.queue.add(message); }
Example 12
Source File: AbstractBrokerMessageHandler.java From java-technology-stack with MIT License | 5 votes |
@Override public void afterSendCompletion( Message<?> message, MessageChannel channel, boolean sent, @Nullable Exception ex) { if (!sent) { SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders()); if (SimpMessageType.DISCONNECT.equals(messageType)) { logger.debug("Detected unsent DISCONNECT message. Processing anyway."); handleMessage(message); } } }
Example 13
Source File: AbstractSubscriptionRegistry.java From java-technology-stack with MIT License | 5 votes |
@Override public final void unregisterSubscription(Message<?> message) { MessageHeaders headers = message.getHeaders(); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers); if (!SimpMessageType.UNSUBSCRIBE.equals(messageType)) { throw new IllegalArgumentException("Expected UNSUBSCRIBE: " + message); } String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); if (sessionId == null) { if (logger.isErrorEnabled()) { logger.error("No sessionId in " + message); } return; } String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers); if (subscriptionId == null) { if (logger.isErrorEnabled()) { logger.error("No subscriptionId " + message); } return; } removeSubscriptionInternal(sessionId, subscriptionId, message); }
Example 14
Source File: AbstractSubscriptionRegistry.java From java-technology-stack with MIT License | 5 votes |
@Override public final void registerSubscription(Message<?> message) { MessageHeaders headers = message.getHeaders(); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers); if (!SimpMessageType.SUBSCRIBE.equals(messageType)) { throw new IllegalArgumentException("Expected SUBSCRIBE: " + message); } String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); if (sessionId == null) { if (logger.isErrorEnabled()) { logger.error("No sessionId in " + message); } return; } String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers); if (subscriptionId == null) { if (logger.isErrorEnabled()) { logger.error("No subscriptionId in " + message); } return; } String destination = SimpMessageHeaderAccessor.getDestination(headers); if (destination == null) { if (logger.isErrorEnabled()) { logger.error("No destination in " + message); } return; } addSubscriptionInternal(sessionId, subscriptionId, destination, message); }
Example 15
Source File: StompSubProtocolHandler.java From spring-analysis-note with MIT License | 5 votes |
private StompHeaderAccessor getStompHeaderAccessor(Message<?> message) { MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class); if (accessor instanceof StompHeaderAccessor) { return (StompHeaderAccessor) accessor; } else { StompHeaderAccessor stompAccessor = StompHeaderAccessor.wrap(message); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders()); if (SimpMessageType.CONNECT_ACK.equals(messageType)) { stompAccessor = convertConnectAcktoStompConnected(stompAccessor); } else if (SimpMessageType.DISCONNECT_ACK.equals(messageType)) { String receipt = getDisconnectReceipt(stompAccessor); if (receipt != null) { stompAccessor = StompHeaderAccessor.create(StompCommand.RECEIPT); stompAccessor.setReceiptId(receipt); } else { stompAccessor = StompHeaderAccessor.create(StompCommand.ERROR); stompAccessor.setMessage("Session closed."); } } else if (SimpMessageType.HEARTBEAT.equals(messageType)) { stompAccessor = StompHeaderAccessor.createForHeartbeat(); } else if (stompAccessor.getCommand() == null || StompCommand.SEND.equals(stompAccessor.getCommand())) { stompAccessor.updateStompCommandAsServerMessage(); } return stompAccessor; } }
Example 16
Source File: StompBrokerRelayMessageHandlerIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@Override public void handleMessage(Message<?> message) throws MessagingException { if (SimpMessageType.HEARTBEAT == SimpMessageHeaderAccessor.getMessageType(message.getHeaders())) { return; } this.queue.add(message); }
Example 17
Source File: AbstractBrokerMessageHandler.java From spring-analysis-note with MIT License | 5 votes |
@Override public void afterSendCompletion( Message<?> message, MessageChannel channel, boolean sent, @Nullable Exception ex) { if (!sent) { SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders()); if (SimpMessageType.DISCONNECT.equals(messageType)) { logger.debug("Detected unsent DISCONNECT message. Processing anyway."); handleMessage(message); } } }
Example 18
Source File: AbstractSubscriptionRegistry.java From spring-analysis-note with MIT License | 5 votes |
@Override public final void unregisterSubscription(Message<?> message) { MessageHeaders headers = message.getHeaders(); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers); if (!SimpMessageType.UNSUBSCRIBE.equals(messageType)) { throw new IllegalArgumentException("Expected UNSUBSCRIBE: " + message); } String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); if (sessionId == null) { if (logger.isErrorEnabled()) { logger.error("No sessionId in " + message); } return; } String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers); if (subscriptionId == null) { if (logger.isErrorEnabled()) { logger.error("No subscriptionId " + message); } return; } removeSubscriptionInternal(sessionId, subscriptionId, message); }
Example 19
Source File: AbstractSubscriptionRegistry.java From spring-analysis-note with MIT License | 5 votes |
@Override public final void registerSubscription(Message<?> message) { MessageHeaders headers = message.getHeaders(); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers); if (!SimpMessageType.SUBSCRIBE.equals(messageType)) { throw new IllegalArgumentException("Expected SUBSCRIBE: " + message); } String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); if (sessionId == null) { if (logger.isErrorEnabled()) { logger.error("No sessionId in " + message); } return; } String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers); if (subscriptionId == null) { if (logger.isErrorEnabled()) { logger.error("No subscriptionId in " + message); } return; } String destination = SimpMessageHeaderAccessor.getDestination(headers); if (destination == null) { if (logger.isErrorEnabled()) { logger.error("No destination in " + message); } return; } addSubscriptionInternal(sessionId, subscriptionId, destination, message); }
Example 20
Source File: SimpleBrokerMessageHandler.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override protected void handleMessageInternal(Message<?> message) { MessageHeaders headers = message.getHeaders(); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers); String destination = SimpMessageHeaderAccessor.getDestination(headers); String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); Principal user = SimpMessageHeaderAccessor.getUser(headers); updateSessionReadTime(sessionId); if (!checkDestinationPrefix(destination)) { return; } SimpMessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, SimpMessageHeaderAccessor.class); if (accessor == null) { throw new IllegalStateException( "No header accessor (not using the SimpMessagingTemplate?): " + message); } if (SimpMessageType.MESSAGE.equals(messageType)) { logMessage(message); sendMessageToSubscribers(destination, message); } else if (SimpMessageType.CONNECT.equals(messageType)) { logMessage(message); long[] clientHeartbeat = SimpMessageHeaderAccessor.getHeartbeat(headers); long[] serverHeartbeat = getHeartbeatValue(); this.sessions.put(sessionId, new SessionInfo(sessionId, user, clientHeartbeat, serverHeartbeat)); SimpMessageHeaderAccessor connectAck = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT_ACK); initHeaders(connectAck); connectAck.setSessionId(sessionId); connectAck.setUser(SimpMessageHeaderAccessor.getUser(headers)); connectAck.setHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER, message); connectAck.setHeader(SimpMessageHeaderAccessor.HEART_BEAT_HEADER, serverHeartbeat); Message<byte[]> messageOut = MessageBuilder.createMessage(EMPTY_PAYLOAD, connectAck.getMessageHeaders()); getClientOutboundChannel().send(messageOut); } else if (SimpMessageType.DISCONNECT.equals(messageType)) { logMessage(message); handleDisconnect(sessionId, user); } else if (SimpMessageType.SUBSCRIBE.equals(messageType)) { logMessage(message); this.subscriptionRegistry.registerSubscription(message); } else if (SimpMessageType.UNSUBSCRIBE.equals(messageType)) { logMessage(message); this.subscriptionRegistry.unregisterSubscription(message); } }