use of javax.jms.MapMessage in project spring-framework by spring-projects.
the class SimpleMessageConverterTests method testMapConversionWhereMapHasNonStringTypesForKeys.
@Test
public void testMapConversionWhereMapHasNonStringTypesForKeys() throws JMSException {
MapMessage message = mock(MapMessage.class);
Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
Map<Integer, String> content = new HashMap<>(1);
content.put(1, "value1");
SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) {
/* expected */
}
}
use of javax.jms.MapMessage in project camel by apache.
the class JmsBinding method extractBodyFromJms.
/**
* Extracts the body from the JMS message
*
* @param exchange the exchange
* @param message the message to extract its body
* @return the body, can be <tt>null</tt>
*/
public Object extractBodyFromJms(Exchange exchange, Message message) {
try {
// if we are configured to not map the jms message then return it as body
if (!mapJmsMessage) {
LOG.trace("Option map JMS message is false so using JMS message as body: {}", message);
return message;
}
if (message instanceof ObjectMessage) {
LOG.trace("Extracting body as a ObjectMessage from JMS message: {}", message);
ObjectMessage objectMessage = (ObjectMessage) message;
Object payload = objectMessage.getObject();
if (payload instanceof DefaultExchangeHolder) {
DefaultExchangeHolder holder = (DefaultExchangeHolder) payload;
DefaultExchangeHolder.unmarshal(exchange, holder);
return exchange.getIn().getBody();
} else {
return objectMessage.getObject();
}
} else if (message instanceof TextMessage) {
LOG.trace("Extracting body as a TextMessage from JMS message: {}", message);
TextMessage textMessage = (TextMessage) message;
return textMessage.getText();
} else if (message instanceof MapMessage) {
LOG.trace("Extracting body as a MapMessage from JMS message: {}", message);
return createMapFromMapMessage((MapMessage) message);
} else if (message instanceof BytesMessage) {
LOG.trace("Extracting body as a BytesMessage from JMS message: {}", message);
return createByteArrayFromBytesMessage((BytesMessage) message);
} else if (message instanceof StreamMessage) {
LOG.trace("Extracting body as a StreamMessage from JMS message: {}", message);
return message;
} else {
return null;
}
} catch (JMSException e) {
throw new RuntimeCamelException("Failed to extract body due to: " + e + ". Message: " + message, e);
}
}
use of javax.jms.MapMessage in project ACS by ACS-Community.
the class HelloWorld method onMessage.
/**
* Method implementing the message handler defined in the
* SubscriptionListener interface.
*
* @param m
*/
public void onMessage(javax.jms.Message m) {
try {
MapMessage message = (MapMessage) m;
String txt = message.getString(TEXT_MAP_FIELD);
java.util.Date date = new java.util.Date(message.getLong(TIMESTAMP_MAP_FIELD));
cat.info("got message : [" + date.toString() + "] " + txt);
} catch (Exception e) {
cat.info("Exception caught", e);
}
close();
}
use of javax.jms.MapMessage in project jmeter by apache.
the class SubscriberSampler method extractContent.
private void extractContent(StringBuilder buffer, StringBuilder propBuffer, Message msg, boolean isLast) {
if (msg != null) {
try {
if (msg instanceof TextMessage) {
buffer.append(((TextMessage) msg).getText());
} else if (msg instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) msg;
if (objectMessage.getObject() != null) {
buffer.append(objectMessage.getObject().getClass());
} else {
buffer.append("object is null");
}
} else if (msg instanceof BytesMessage) {
BytesMessage bytesMessage = (BytesMessage) msg;
buffer.append(bytesMessage.getBodyLength() + " bytes received in BytesMessage");
} else if (msg instanceof MapMessage) {
MapMessage mapm = (MapMessage) msg;
// MapNames are Strings
@SuppressWarnings("unchecked") Enumeration<String> enumb = mapm.getMapNames();
while (enumb.hasMoreElements()) {
String name = enumb.nextElement();
Object obj = mapm.getObject(name);
buffer.append(name);
buffer.append(",");
buffer.append(obj.getClass().getCanonicalName());
buffer.append(",");
buffer.append(obj);
buffer.append("\n");
}
}
Utils.messageProperties(propBuffer, msg);
if (!isLast && !StringUtils.isEmpty(separator)) {
propBuffer.append(separator);
buffer.append(separator);
}
} catch (JMSException e) {
log.error(e.getMessage());
}
}
}
use of javax.jms.MapMessage in project wildfly by wildfly.
the class EnvEntryTestCase method testEnvEntriesMDB.
@Test
public void testEnvEntriesMDB() throws Exception {
ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
Connection con = factory.createConnection();
try {
Destination dest = (Destination) ctx.lookup("java:jboss/queue/testEnvEntry");
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(dest);
Queue replyQueue = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(replyQueue);
con.start();
TextMessage msg = session.createTextMessage();
msg.setJMSReplyTo(replyQueue);
msg.setText("This is message one");
producer.send(msg);
MapMessage replyMsg = (MapMessage) consumer.receive(5000);
Assert.assertNotNull(replyMsg);
Assert.assertEquals(16, replyMsg.getInt("maxExceptions"));
Assert.assertEquals(12, replyMsg.getInt("numExceptions"));
Assert.assertEquals(7, replyMsg.getInt("minExceptions"));
} finally {
con.close();
}
}
Aggregations