use of javax.jms.TextMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method fromTextMessageAsObject.
@Test
public void fromTextMessageAsObject() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
String text = "{\"foo\":\"bar\"}";
given(textMessageMock.getStringProperty("__typeid__")).willReturn(Object.class.getName());
given(textMessageMock.getText()).willReturn(text);
Object result = converter.fromMessage(textMessageMock);
assertEquals("Invalid result", result, unmarshalled);
}
use of javax.jms.TextMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method testToTextMessageWithReturnType.
private void testToTextMessageWithReturnType(MethodParameter returnType) throws JMSException, NoSuchMethodException {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
MyAnotherBean bean = new MyAnotherBean("test", "lengthy description");
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
converter.toMessage(bean, sessionMock, returnType);
verify(textMessageMock).setStringProperty("__typeid__", MyAnotherBean.class.getName());
}
use of javax.jms.TextMessage in project spring-framework by spring-projects.
the class MarshallingMessageConverterTests method toTextMessage.
@Test
public void toTextMessage() throws Exception {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
Object toBeMarshalled = new Object();
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
converter.toMessage(toBeMarshalled, sessionMock);
verify(marshallerMock).marshal(eq(toBeMarshalled), isA(Result.class));
}
use of javax.jms.TextMessage in project spring-framework by spring-projects.
the class MessagingMessageConverterTests method customPayloadConverter.
@Test
public void customPayloadConverter() throws JMSException {
TextMessage jmsMsg = new StubTextMessage("1224");
this.converter.setPayloadConverter(new TestMessageConverter());
Message<?> msg = (Message<?>) this.converter.fromMessage(jmsMsg);
assertEquals(1224L, msg.getPayload());
}
use of javax.jms.TextMessage in project sling by apache.
the class JMSQueueManager method add.
/**
* Add a message to the queue. The message is added to the queue transactionally and auto acknowledged.
* @param name the name of the queue.
* @param message the message to post to the queue.
*/
@Override
public void add(@Nonnull Types.QueueName name, @Nonnull Map<String, Object> message) {
Session session = null;
try {
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
//TODO Instead of copy do addition at JSON writer level
Map<String, Object> msgCopy = new HashMap<>(message);
// set the number of retries to 0.
msgCopy.put(NRETRIES, 0L);
TextMessage textMessage = session.createTextMessage(Json.toJson(msgCopy));
textMessage.setJMSType(JMSMessageTypes.JSON.toString());
LOGGER.info("Sending to {} message {} ", name, textMessage);
session.createProducer(session.createQueue(name.toString())).send(textMessage);
session.commit();
session.close();
} catch (JMSException e) {
LOGGER.error("Unable to send message to queue " + name, e);
close(session);
}
}
Aggregations