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

The following examples show how to use javax.jms.MapMessage#getMapNames() . 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: JMSInjectHandler.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * @param message JMSMap message
 * @return XML representation of JMS Map message
 */
public static OMElement convertJMSMapToXML(MapMessage message) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace jmsMapNS = OMAbstractFactory.getOMFactory().createOMNamespace(JMSConstants.JMS_MAP_NS, "");
    OMElement jmsMap = fac.createOMElement(JMSConstants.JMS_MAP_ELEMENT_NAME, jmsMapNS);
    try {
        Enumeration names = message.getMapNames();
        while (names.hasMoreElements()) {
            String nextName = names.nextElement().toString();
            String nextVal = message.getString(nextName);
            OMElement next = fac.createOMElement(nextName.replace(" ", ""), jmsMapNS);
            next.setText(nextVal);
            jmsMap.addChild(next);
        }
    } catch (JMSException e) {
        log.error("Error while processing the JMS Map Message. " + e.getMessage());
    }
    return jmsMap;
}
 
Example 2
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 3
Source File: MessageTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void publishMapMessage() throws Exception
{
    final Map<String, Object> content = new HashMap<>();
    content.put("key1", "astring");
    content.put("key2", Integer.MIN_VALUE);
    content.put("key3", Long.MAX_VALUE);
    content.put("key4", null);
    MapMessage message = publishMessageWithContent(content, MapMessage.class);
    final Enumeration mapNames = message.getMapNames();
    int entryCount = 0;
    while(mapNames.hasMoreElements())
    {
        String key = (String) mapNames.nextElement();
        assertThat("Unexpected map content for key : " + key, message.getObject(key), is(equalTo(content.get(key))));
        entryCount++;
    }
    assertThat("Unexpected number of key/value pairs in map message", entryCount, is(equalTo(content.size())));
}
 
Example 4
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 5
Source File: SimpleMessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: SimpleMessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: JmsFactory.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private static byte[] getMessageBytes(MapMessage message) throws JMSException {
    Map<String, String> map = new HashMap<>();
    Enumeration elements = message.getMapNames();
    while (elements.hasMoreElements()) {
        String key = (String) elements.nextElement();
        map.put(key, message.getString(key));
    }
    return map.toString().getBytes();
}
 
Example 8
Source File: SimpleMessageConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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<String, Object>();
	Enumeration<String> en = message.getMapNames();
	while (en.hasMoreElements()) {
		String key = en.nextElement();
		map.put(key, message.getObject(key));
	}
	return map;
}
 
Example 9
Source File: JMSObjectInputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
protected Map<String, Object> extractMapFromMessage(MapMessage message) throws JMSException
{
  Map<String, Object> map = new HashMap<String, Object>();
  Enumeration<?> en = message.getMapNames();
  while (en.hasMoreElements()) {
    String key = (String)en.nextElement();
    map.put(key, message.getObject(key));
  }
  return map;
}
 
Example 10
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 11
Source File: GatewayTokenRevocationMessageListener.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public void onMessage(Message message) {

        try {
            if (message != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Event received in JMS Event Receiver - " + message);
                }
                Topic jmsDestination = (Topic) message.getJMSDestination();
                if (message instanceof MapMessage) {
                    MapMessage mapMessage = (MapMessage) message;
                    Map<String, Object> map = new HashMap<String, Object>();
                    Enumeration enumeration = mapMessage.getMapNames();
                    while (enumeration.hasMoreElements()) {
                        String key = (String) enumeration.nextElement();
                        map.put(key, mapMessage.getObject(key));
                    }
                    if (APIConstants.TopicNames.TOPIC_TOKEN_REVOCATION.equalsIgnoreCase(jmsDestination.getTopicName())) {
                        if (map.get(APIConstants.REVOKED_TOKEN_KEY) !=
                                null) {
                            /*
                             * This message contains revoked token data
                             * revokedToken - Revoked Token which should be removed from the cache
                             * expiryTime - ExpiryTime of the token if token is JWT, otherwise expiry is set to 0
                             */
                            handleRevokedTokenMessage((String) map.get(APIConstants.REVOKED_TOKEN_KEY),
                                    (Long) map.get(APIConstants.REVOKED_TOKEN_EXPIRY_TIME));
                        }

                    }
                } else {
                    log.warn("Event dropped due to unsupported message type " + message.getClass());
                }
            } else {
                log.warn("Dropping the empty/null event received through jms receiver");
            }
        } catch (JMSException e) {
            log.error("JMSException occurred when processing the received message ", e);
        }
    }
 
Example 12
Source File: JmsFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private static byte[] getMessageBytes(MapMessage message) throws JMSException {
    Map<String, String> map = new HashMap<>();
    Enumeration elements = message.getMapNames();
    while (elements.hasMoreElements()) {
        String key = (String) elements.nextElement();
        map.put(key, message.getString(key));
    }
    return map.toString().getBytes();
}
 
Example 13
Source File: GatewayJMSMessageListener.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public void onMessage(Message message) {

        try {
            if (message != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Event received in JMS Event Receiver - " + message);
                }
                Topic jmsDestination = (Topic) message.getJMSDestination();
                if (message instanceof MapMessage) {
                    MapMessage mapMessage = (MapMessage) message;
                    Map<String, Object> map = new HashMap<String, Object>();
                    Enumeration enumeration = mapMessage.getMapNames();
                    while (enumeration.hasMoreElements()) {
                        String key = (String) enumeration.nextElement();
                        map.put(key, mapMessage.getObject(key));
                    }
                    if (APIConstants.TopicNames.TOPIC_NOTIFICATION.equalsIgnoreCase(jmsDestination.getTopicName())) {
                        if (map.get(APIConstants.EVENT_TYPE) !=
                                null) {
                            /*
                             * This message contains notification
                             * eventType - type of the event
                             * timestamp - system time of the event published
                             * event - event data
                             */
                            handleNotificationMessage((String) map.get(APIConstants.EVENT_TYPE),
                                    (Long) map.get(APIConstants.EVENT_TIMESTAMP),
                                    (String) map.get(APIConstants.EVENT_PAYLOAD));
                        }
                    }

                } else {
                    log.warn("Event dropped due to unsupported message type " + message.getClass());
                }
            } else {
                log.warn("Dropping the empty/null event received through jms receiver");
            }
        } catch (JMSException e) {
            log.error("JMSException occurred when processing the received message ", e);
        }
    }