use of org.springframework.jms.support.converter.MessageConverter in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method incomingMessageUsesMessageConverter.
@Test
public void incomingMessageUsesMessageConverter() throws JMSException {
javax.jms.Message jmsMessage = mock(javax.jms.Message.class);
Session session = mock(Session.class);
MessageConverter messageConverter = mock(MessageConverter.class);
given(messageConverter.fromMessage(jmsMessage)).willReturn("FooBar");
MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.class);
listener.setMessageConverter(messageConverter);
listener.onMessage(jmsMessage, session);
verify(messageConverter, times(1)).fromMessage(jmsMessage);
assertEquals(1, sample.simples.size());
assertEquals("FooBar", sample.simples.get(0).getPayload());
}
use of org.springframework.jms.support.converter.MessageConverter in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method convertMessageConversionExceptionOnReceive.
@Test
public void convertMessageConversionExceptionOnReceive() throws JMSException {
javax.jms.Message message = createJmsTextMessage();
MessageConverter messageConverter = mock(MessageConverter.class);
willThrow(org.springframework.jms.support.converter.MessageConversionException.class).given(messageConverter).fromMessage(message);
messagingTemplate.setJmsMessageConverter(messageConverter);
given(jmsTemplate.receive("myQueue")).willReturn(message);
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
messagingTemplate.receive("myQueue");
}
use of org.springframework.jms.support.converter.MessageConverter in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method convertMessageFormatException.
@Test
public void convertMessageFormatException() throws JMSException {
Message<String> message = createTextMessage();
MessageConverter messageConverter = mock(MessageConverter.class);
willThrow(MessageFormatException.class).given(messageConverter).toMessage(eq(message), any());
messagingTemplate.setJmsMessageConverter(messageConverter);
invokeMessageCreator("myQueue");
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
messagingTemplate.send("myQueue", message);
}
use of org.springframework.jms.support.converter.MessageConverter in project spring-framework by spring-projects.
the class MethodJmsListenerEndpoint method createMessageListener.
@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
Assert.state(this.messageHandlerMethodFactory != null, "Could not create message listener - MessageHandlerMethodFactory not set");
MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod());
messageListener.setHandlerMethod(invocableHandlerMethod);
String responseDestination = getDefaultResponseDestination();
if (StringUtils.hasText(responseDestination)) {
if (container.isReplyPubSubDomain()) {
messageListener.setDefaultResponseTopicName(responseDestination);
} else {
messageListener.setDefaultResponseQueueName(responseDestination);
}
}
MessageConverter messageConverter = container.getMessageConverter();
if (messageConverter != null) {
messageListener.setMessageConverter(messageConverter);
}
DestinationResolver destinationResolver = container.getDestinationResolver();
if (destinationResolver != null) {
messageListener.setDestinationResolver(destinationResolver);
}
return messageListener;
}
use of org.springframework.jms.support.converter.MessageConverter in project spring-framework by spring-projects.
the class AbstractAdaptableMessageListener method buildMessage.
/**
* Build a JMS message to be sent as response based on the given result object.
* @param session the JMS Session to operate on
* @param result the content of the message, as returned from the listener method
* @return the JMS {@code Message} (never {@code null})
* @throws JMSException if thrown by JMS API methods
* @see #setMessageConverter
*/
protected Message buildMessage(Session session, Object result) throws JMSException {
Object content = preProcessResponse(result instanceof JmsResponse ? ((JmsResponse<?>) result).getResponse() : result);
MessageConverter converter = getMessageConverter();
if (converter != null) {
if (content instanceof org.springframework.messaging.Message) {
return this.messagingMessageConverter.toMessage(content, session);
} else {
return converter.toMessage(content, session);
}
}
if (!(content instanceof Message)) {
throw new MessageConversionException("No MessageConverter specified - cannot handle message [" + content + "]");
}
return (Message) content;
}
Aggregations