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;
}
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);
}
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);
}
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));
}
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"));
}
Aggregations