Search in sources :

Example 1 with MessageHeaders

use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.

the class MessagingMessageConverter method toMessage.

@Override
public javax.jms.Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
    if (!(object instanceof Message)) {
        throw new IllegalArgumentException("Could not convert [" + object + "] - only [" + Message.class.getName() + "] is handled by this converter");
    }
    Message<?> input = (Message<?>) object;
    MessageHeaders headers = input.getHeaders();
    Object conversionHint = (headers != null ? headers.get(AbstractMessagingTemplate.CONVERSION_HINT_HEADER) : null);
    javax.jms.Message reply = createMessageForPayload(input.getPayload(), session, conversionHint);
    this.headerMapper.fromHeaders(headers, reply);
    return reply;
}
Also used : Message(org.springframework.messaging.Message) MessageHeaders(org.springframework.messaging.MessageHeaders)

Example 2 with MessageHeaders

use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.

the class AbstractSubscriptionRegistry method findSubscriptions.

@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);
}
Also used : SimpMessageType(org.springframework.messaging.simp.SimpMessageType) MessageHeaders(org.springframework.messaging.MessageHeaders)

Example 3 with MessageHeaders

use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.

the class AbstractSubscriptionRegistry method unregisterSubscription.

@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);
}
Also used : SimpMessageType(org.springframework.messaging.simp.SimpMessageType) MessageHeaders(org.springframework.messaging.MessageHeaders)

Example 4 with MessageHeaders

use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.

the class TestMessagePostProcessor method convertAndSendNoMatchingConverter.

@Test(expected = MessageConversionException.class)
public void convertAndSendNoMatchingConverter() {
    MessageConverter converter = new CompositeMessageConverter(Arrays.<MessageConverter>asList(new MappingJackson2MessageConverter()));
    this.template.setMessageConverter(converter);
    this.headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_XML);
    this.template.convertAndSend("home", "payload", new MessageHeaders(this.headers));
}
Also used : MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) MessageHeaders(org.springframework.messaging.MessageHeaders) MessageConverter(org.springframework.messaging.converter.MessageConverter) CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) Test(org.junit.Test)

Example 5 with MessageHeaders

use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.

the class HeadersMethodArgumentResolverTests method resolveArgumentMessageHeaders.

@Test
public void resolveArgumentMessageHeaders() throws Exception {
    Object resolved = this.resolver.resolveArgument(this.paramMessageHeaders, this.message);
    assertTrue(resolved instanceof MessageHeaders);
    MessageHeaders headers = (MessageHeaders) resolved;
    assertEquals("bar", headers.get("foo"));
}
Also used : MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

Aggregations

MessageHeaders (org.springframework.messaging.MessageHeaders)54 Test (org.junit.Test)39 HashMap (java.util.HashMap)15 Message (org.springframework.messaging.Message)9 SimpMessageType (org.springframework.messaging.simp.SimpMessageType)6 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)5 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)4 MimeType (org.springframework.util.MimeType)3 Principal (java.security.Principal)2 HashSet (java.util.HashSet)2 MessageConverter (org.springframework.messaging.converter.MessageConverter)2 StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)2 TestPrincipal (org.springframework.messaging.simp.TestPrincipal)2 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2 Method (java.lang.reflect.Method)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Destination (javax.jms.Destination)1 JMSException (javax.jms.JMSException)1