/** * Extract a Map from the given {@link MapMessage}. * @param message the message to convert * @return the resulting Map * @throws JMSException if thrown by JMS methods */ @SuppressWarnings("unchecked") protected Map<String, Object> extractMapFromMessage(MapMessage message) throws JMSException { Map<String, Object> map = new HashMap<>(); Enumeration<String> en = message.getMapNames(); while (en.hasMoreElements()) { String key = en.nextElement(); map.put(key, message.getObject(key)); } return map; }
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; }
/** * 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); } }
@Test public void testMapConversion() throws JMSException { Session session = mock(Session.class); MapMessage message = mock(MapMessage.class); Map<String, String> content = new HashMap<>(2); content.put("key1", "value1"); content.put("key2", "value2"); given(session.createMapMessage()).willReturn(message); given(message.getMapNames()).willReturn(Collections.enumeration(content.keySet())); given(message.getObject("key1")).willReturn("value1"); given(message.getObject("key2")).willReturn("value2"); SimpleMessageConverter converter = new SimpleMessageConverter(); Message msg = converter.toMessage(content, session); assertEquals(content, converter.fromMessage(msg)); verify(message).setObject("key1", "value1"); verify(message).setObject("key2", "value2"); }
msg.setObject(name, mapMsg.getObject(name));
@Override public Object getObject(final String name) throws JMSException { return message.getObject(name); }
public Object getObject(String name) throws JMSException { return ((MapMessage) message).getObject(name); }
MapMessageImpl(MapMessage map) throws JMSException { super(map); Enumeration e = map.getMapNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); _map.put(name, map.getObject(name)); } }
/** * Extracts a {@link Map} from a {@link MapMessage} */ public Map<String, Object> createMapFromMapMessage(MapMessage message) throws JMSException { Map<String, Object> answer = new HashMap<>(); Enumeration<?> names = message.getMapNames(); while (names.hasMoreElements()) { String name = names.nextElement().toString(); Object value = message.getObject(name); answer.put(name, value); } return answer; }
protected NevadoMapMessage(MapMessage message) throws JMSException { super(message); for (Enumeration keys = message.getMapNames(); keys.hasMoreElements();) { String key = keys.nextElement().toString(); Object value = message.getObject(key); setObject(key, value); } }
private static void copyMapObjects(RMQMapMessage rmqMsg, MapMessage msg) throws JMSException { @SuppressWarnings("unchecked") Enumeration<String> mapNames = (Enumeration<String>) msg.getMapNames(); while (mapNames.hasMoreElements()) { String name = mapNames.nextElement(); rmqMsg.setObject(name, msg.getObject(name)); } } }
public static IProperties getMapProperties(MapMessage msg) throws JMSException { MProperties out = new MProperties(); if (msg == null) return out; @SuppressWarnings("unchecked") Enumeration<String> enu = msg.getMapNames(); while (enu.hasMoreElements()) { String name = enu.nextElement(); out.setProperty( name, msg.getObject(name) ); } return out; }
private MessageImpl convertMapMessage(final MapMessage message) throws JMSException { MapMessageImpl mapMessage = createMapMessage(); Enumeration mapNames = message.getMapNames(); while (mapNames.hasMoreElements()) { String name = (String) mapNames.nextElement(); mapMessage.setObject(name, message.getObject(name)); } return mapMessage; }
@Override public Map<String, Object> getPayload() throws JMSException { final Map<String, Object> map = new HashMap<String, Object>(); for (final String name : new IterableAdapter(message.getMapNames())) { map.put(name, getMessage().getObject(name)); } return map; }
@Override public Object convert(MapMessage message) throws TransformationException { try { return message.getObject(configuration.getAttributeName()); } catch (JMSException e) { throw new TransformationException(e); } }
/** * Get * * @param name The name * @return The value * @throws JMSException Thrown if an error occurs */ @Override public Object getObject(final String name) throws JMSException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("getObject(" + name + ")"); } return ((MapMessage) message).getObject(name); }
/** * Get * * @param name The name * @return The value * @throws JMSException Thrown if an error occurs */ @Override public Object getObject(final String name) throws JMSException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("getObject(" + name + ")"); } return ((MapMessage) message).getObject(name); }
private static AbstractMessage duplicateMapMessage( MapMessage srcMessage ) throws JMSException { MapMessageImpl copy = new MapMessageImpl(); copyHeaders(srcMessage,copy); Enumeration<?> allNames = srcMessage.getMapNames(); while (allNames.hasMoreElements()) { String name = (String)allNames.nextElement(); Object value = srcMessage.getObject(name); copy.setObject(name, value); } return copy; }
public static void ensureEquivalent(final MapMessage m1, final ActiveMQMapMessage m2) throws JMSException { MessageHeaderTestBase.ensureEquivalent((Message) m1, m2); for (Enumeration<String> e = m1.getMapNames(); e.hasMoreElements(); ) { String name = e.nextElement(); ProxyAssertSupport.assertEquals(m1.getObject(name), m2.getObject(name)); } for (Enumeration<String> e = m2.getMapNames(); e.hasMoreElements(); ) { String name = e.nextElement(); ProxyAssertSupport.assertEquals(m2.getObject(name), m1.getObject(name)); } }
@Override protected void assertEquivalent(final Message m, final int mode, final boolean redelivery) throws JMSException { super.assertEquivalent(m, mode, redelivery); MapMessage map = (MapMessage) m; ProxyAssertSupport.assertTrue(map.getBoolean("boolean1")); ProxyAssertSupport.assertEquals(map.getChar("char1"), 'c'); ProxyAssertSupport.assertEquals(map.getDouble("double1"), 1.0D, 0.0D); ProxyAssertSupport.assertEquals(map.getFloat("float1"), 2.0F, 0.0F); ProxyAssertSupport.assertEquals(map.getInt("int1"), 3); ProxyAssertSupport.assertEquals(map.getLong("long1"), 4L); ProxyAssertSupport.assertEquals(map.getObject("object1"), obj); ProxyAssertSupport.assertEquals(map.getShort("short1"), (short) 5); ProxyAssertSupport.assertEquals(map.getString("string1"), "stringvalue"); } }