List of usage examples for org.springframework.messaging Message getHeaders
MessageHeaders getHeaders();
From source file:org.springframework.messaging.handler.invocation.reactive.AbstractEncoderMethodReturnValueHandler.java
@Override public Mono<Void> handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, Message<?> message) { if (returnValue == null) { return handleNoContent(returnType, message); }//from w ww. jav a 2 s . c o m DataBufferFactory bufferFactory = (DataBufferFactory) message.getHeaders().getOrDefault( HandlerMethodReturnValueHandler.DATA_BUFFER_FACTORY_HEADER, this.defaultBufferFactory); MimeType mimeType = (MimeType) message.getHeaders().get(MessageHeaders.CONTENT_TYPE); Flux<DataBuffer> encodedContent = encodeContent(returnValue, returnType, bufferFactory, mimeType, Collections.emptyMap()); return new ChannelSendOperator<>(encodedContent, publisher -> handleEncodedContent(Flux.from(publisher), returnType, message)); }
From source file:org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler.java
@Override @Nullable protected String getDestination(Message<?> message) { return SimpMessageHeaderAccessor.getDestination(message.getHeaders()); }
From source file:org.springframework.messaging.simp.annotation.support.SubscriptionMethodReturnValueHandler.java
@Override public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, Message<?> message) throws Exception { if (returnValue == null) { return;//from www .jav a2s .c o m } MessageHeaders headers = message.getHeaders(); String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers); String destination = SimpMessageHeaderAccessor.getDestination(headers); if (subscriptionId == null) { throw new IllegalStateException( "No simpSubscriptionId in " + message + " returned by: " + returnType.getMethod()); } if (destination == null) { throw new IllegalStateException( "No simpDestination in " + message + " returned by: " + returnType.getMethod()); } if (logger.isDebugEnabled()) { logger.debug("Reply to @SubscribeMapping: " + returnValue); } MessageHeaders headersToSend = createHeaders(sessionId, subscriptionId, returnType); this.messagingTemplate.convertAndSend(destination, returnValue, headersToSend); }
From source file:org.springframework.messaging.simp.broker.AbstractSubscriptionRegistry.java
@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); }//from ww w .j a v a 2 s. com 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); }
From source file:org.springframework.messaging.simp.broker.AbstractSubscriptionRegistry.java
@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); }/*from www .j av a2s . c o m*/ 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); }
From source file:org.springframework.messaging.simp.broker.AbstractSubscriptionRegistry.java
@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); }/*from w w w .j a v a 2 s .c o m*/ String destination = SimpMessageHeaderAccessor.getDestination(headers); if (destination == null) { if (logger.isErrorEnabled()) { logger.error("No destination in " + message); } return EMPTY_MAP; } return findSubscriptionsInternal(destination, message); }
From source file:org.springframework.messaging.simp.handler.AbstractBrokerMessageHandler.java
@Override public final void handleMessage(Message<?> message) { if (!this.running) { if (logger.isTraceEnabled()) { logger.trace("STOMP broker relay not running. Ignoring message id=" + message.getHeaders().getId()); }/*from w w w . ja v a 2 s .c om*/ return; } if (logger.isTraceEnabled()) { logger.trace("Processing message: " + message); } handleMessageInternal(message); }
From source file:org.springframework.messaging.simp.SimpAttributes.java
/** * Extract the SiMP session attributes from the given message and * wrap them in a {@link SimpAttributes} instance. * @param message the message to extract session attributes from *///from ww w . j a v a 2 s. com public static SimpAttributes fromMessage(Message<?> message) { Assert.notNull(message, "Message must not be null"); MessageHeaders headers = message.getHeaders(); String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); Map<String, Object> sessionAttributes = SimpMessageHeaderAccessor.getSessionAttributes(headers); if (sessionId == null) { throw new IllegalStateException("No session id in " + message); } if (sessionAttributes == null) { throw new IllegalStateException("No session attributes in " + message); } return new SimpAttributes(sessionId, sessionAttributes); }
From source file:org.springframework.messaging.simp.stomp.StompEncoder.java
/** * Encodes the given STOMP {@code message} into a {@code byte[]} * @param message the message to encode// w ww.ja va2s .co m * @return the encoded message */ public byte[] encode(Message<byte[]> message) { return encode(message.getHeaders(), message.getPayload()); }
From source file:org.springframework.messaging.simp.user.DefaultUserDestinationResolver.java
@Nullable private ParseResult parse(Message<?> message) { MessageHeaders headers = message.getHeaders(); String sourceDestination = SimpMessageHeaderAccessor.getDestination(headers); if (sourceDestination == null || !checkDestination(sourceDestination, this.prefix)) { return null; }//www . ja v a2s . co m 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; }