Java Code Examples for javax.jms.MapMessage#getObject()

The following examples show how to use javax.jms.MapMessage#getObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsConsumer.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public static Map<String, String> createMapMessageValues(final MapMessage mapMessage) throws JMSException {
    final Map<String, String> valueMap = new HashMap<>();

    final Enumeration<?> enumeration = mapMessage.getMapNames();
    while (enumeration.hasMoreElements()) {
        final String name = (String) enumeration.nextElement();

        final Object value = mapMessage.getObject(name);
        if (value == null) {
            valueMap.put(MAP_MESSAGE_PREFIX + name, "");
        } else {
            valueMap.put(MAP_MESSAGE_PREFIX + name, value.toString());
        }
    }

    return valueMap;
}
 
Example 2
Source File: JmsConsumer.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static Map<String, String> createMapMessageValues(final MapMessage mapMessage) throws JMSException {
    final Map<String, String> valueMap = new HashMap<>();

    final Enumeration<?> enumeration = mapMessage.getMapNames();
    while (enumeration.hasMoreElements()) {
        final String name = (String) enumeration.nextElement();

        final Object value = mapMessage.getObject(name);
        if (value == null) {
            valueMap.put(MAP_MESSAGE_PREFIX + name, "");
        } else {
            valueMap.put(MAP_MESSAGE_PREFIX + name, value.toString());
        }
    }

    return valueMap;
}
 
Example 3
Source File: CompressedInteropTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void receiveMapMessage(boolean useCore) throws Exception {
   MapMessage mapMessage = (MapMessage) receiveMessage(useCore);

   boolean booleanVal = mapMessage.getBoolean("boolean-type");
   assertTrue(booleanVal);
   byte byteVal = mapMessage.getByte("byte-type");
   assertEquals((byte) 10, byteVal);
   byte[] bytesVal = mapMessage.getBytes("bytes-type");
   byte[] originVal = TEXT.getBytes();
   assertEquals(originVal.length, bytesVal.length);
   for (int i = 0; i < bytesVal.length; i++) {
      assertTrue(bytesVal[i] == originVal[i]);
   }
   char charVal = mapMessage.getChar("char-type");
   assertEquals('A', charVal);
   double doubleVal = mapMessage.getDouble("double-type");
   assertEquals(55.3D, doubleVal, 0.1D);
   float floatVal = mapMessage.getFloat("float-type");
   assertEquals(79.1F, floatVal, 0.1F);
   int intVal = mapMessage.getInt("int-type");
   assertEquals(37, intVal);
   long longVal = mapMessage.getLong("long-type");
   assertEquals(56652L, longVal);
   Object objectVal = mapMessage.getObject("object-type");
   Object origVal = new String("VVVV");
   assertTrue(objectVal.equals(origVal));
   short shortVal = mapMessage.getShort("short-type");
   assertEquals((short) 333, shortVal);
   String strVal = mapMessage.getString("string-type");
   assertEquals(TEXT, strVal);
}
 
Example 4
Source File: ActiveMQMapMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for a foreign MapMessage
 *
 * @param foreign
 * @throws JMSException
 */
public ActiveMQMapMessage(final MapMessage foreign, final ClientSession session) throws JMSException {
   super(foreign, ActiveMQMapMessage.TYPE, session);
   Enumeration<?> names = foreign.getMapNames();
   while (names.hasMoreElements()) {
      String name = (String) names.nextElement();
      Object obj = foreign.getObject(name);
      setObject(name, obj);
   }
}
 
Example 5
Source File: JmsAppenderTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws JMSException {
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    JmsAppender appender = new JmsAppender();
    appender.connectionFactory = cf;
    Dictionary<String, Object> config = new Hashtable<>();
    config.put("message.type", "map");
    appender.activate(config);
    
    Connection con = cf.createConnection();
    con.start();
    Session sess = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    
    MessageConsumer consumer = sess.createConsumer(sess.createQueue("decanter"));
    
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("timestamp", 1l);
    props.put("string", "test");
    props.put("boolean", true);
    props.put("integer", 1);
    props.put("testnull", null);
    props.put("map", new HashMap<String, String>());
    appender.handleEvent(new Event("decanter/collect", props));
    
    MapMessage message = (MapMessage)consumer.receive(1000);
    consumer.close();
    sess.close();
    con.close();
    
    Assert.assertEquals(1l, message.getObject("timestamp"));
    Assert.assertEquals("test", message.getObject("string"));
    Assert.assertEquals(true, message.getObject("boolean"));
    Assert.assertEquals(1, message.getObject("integer"));
    Object map = message.getObject("map");
    Assert.assertTrue(map instanceof Map);
}
 
Example 6
Source File: JmsAppenderTest.java    From karaf-decanter with Apache License 2.0 4 votes vote down vote up
@Test
public void testWithFilter() throws JMSException {
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    JmsAppender appender = new JmsAppender();
    appender.connectionFactory = cf;
    Dictionary<String, Object> config = new Hashtable<>();
    config.put("message.type", "map");
    config.put(EventFilter.PROPERTY_NAME_EXCLUDE_CONFIG, ".*refused.*");
    config.put(EventFilter.PROPERTY_VALUE_EXCLUDE_CONFIG, ".*refused.*");
    appender.activate(config);

    Connection con = cf.createConnection();
    con.start();
    Session sess = con.createSession(false, Session.AUTO_ACKNOWLEDGE);

    MessageConsumer consumer = sess.createConsumer(sess.createQueue("decanter"));

    Map<String, Object> data = new HashMap<String, Object>();
    data.put("timestamp", 1l);
    data.put("string", "test");
    data.put("boolean", true);
    data.put("integer", 1);
    data.put("testnull", null);
    data.put("map", new HashMap<String, String>());
    appender.handleEvent(new Event("decanter/collect", data));

    data = new HashMap<>();
    data.put("refused_property", "value");
    appender.handleEvent(new Event("decanter/collect", data));

    data = new HashMap<>();
    data.put("property", "refused_value");
    appender.handleEvent(new Event("decanter/collect", data));

    MapMessage message = (MapMessage)consumer.receive(1000);
    consumer.close();
    sess.close();
    con.close();

    Assert.assertEquals(1l, message.getObject("timestamp"));
    Assert.assertEquals("test", message.getObject("string"));
    Assert.assertEquals(true, message.getObject("boolean"));
    Assert.assertEquals(1, message.getObject("integer"));
    Object map = message.getObject("map");
    Assert.assertTrue(map instanceof Map);
}