Example usage for javax.jms MapMessage getStringProperty

List of usage examples for javax.jms MapMessage getStringProperty

Introduction

In this page you can find the example usage for javax.jms MapMessage getStringProperty.

Prototype


String getStringProperty(String name) throws JMSException;

Source Link

Document

Returns the value of the String property with the specified name.

Usage

From source file:hermes.ext.imq.ImqAdmin.java

@Override
public void onMessage(Message msg) {

    try {/*from   w w  w.j  a  v  a  2  s.c om*/

        MapMessage mapMsg = (MapMessage) msg;
        String type = mapMsg.getStringProperty("type");

        LOG.debug("Got admin message from broker of type: " + type);

        if (type.equals(DEST_LIST_TOPIC_NAME)) {
            List<DestinationConfig> result = new ArrayList<DestinationConfig>();

            for (@SuppressWarnings("unchecked")
            Enumeration e = mapMsg.getMapNames(); e.hasMoreElements();) {
                String name = (String) e.nextElement();

                @SuppressWarnings("unchecked")
                Map<String, String> object = (Map<String, String>) mapMsg.getObject(name);

                DestinationConfig dest = HermesBrowser.getConfigDAO().createDestinationConfig();
                dest.setName(object.get("name"));
                dest.setShortName(object.get("name"));
                dest.setDomain("queue".equals(object.get("type")) ? Domain.QUEUE.getId()
                        : ("topic".equals(object.get("type")) ? Domain.TOPIC.getId() : Domain.UNKNOWN.getId()));

                result.add(dest);
            }

            Collections.sort(result, new Comparator<DestinationConfig>() {
                @Override
                public int compare(DestinationConfig o1, DestinationConfig o2) {
                    return o1.getShortName().compareTo(o2.getShortName());
                }
            });

            destinations = result;

            synchronized (destListGuard) {
                destListGuard.notifyAll();
            }

        } else if (type.startsWith(QUEUE_METRICS_TOPIC_PREFIX)) {
            LOG.debug("Got queue metrics: " + type);

            String queueName = type.substring(QUEUE_METRICS_TOPIC_PREFIX.length());
            messageCounts.put(queueName, mapMsg.getLong("numMsgs"));
            HashMap<String, Long> map = new HashMap<String, Long>();

            @SuppressWarnings("unchecked")
            Enumeration<String> e = mapMsg.getMapNames();
            while (e.hasMoreElements()) {
                String name = e.nextElement();
                map.put(name, mapMsg.getLong(name));
            }
            stats.put(queueName, map);
            LOG.debug("Stored stats for: " + queueName);

            synchronized (destMetricGuard) {
                destMetricGuard.notifyAll();
            }

        } else if (type.startsWith(TOPIC_METRICS_TOPIC_PREFIX)) {
            LOG.debug("Got topic metrics: " + type);

            String topicName = type.substring(TOPIC_METRICS_TOPIC_PREFIX.length());
            messageCounts.put(topicName, mapMsg.getLong("numMsgs"));

            HashMap<String, Long> map = new HashMap<String, Long>();

            @SuppressWarnings("unchecked")
            Enumeration<String> e = mapMsg.getMapNames();
            while (e.hasMoreElements()) {
                String name = e.nextElement();
                map.put(name, mapMsg.getLong(name));
            }
            stats.put(topicName, map);
            LOG.debug("Stored stats for: " + topicName);

            synchronized (destMetricGuard) {
                destMetricGuard.notifyAll();
            }
        }

    } catch (JMSException e) {
        throw new RuntimeException(e);
    }
}

From source file:eu.domibus.submission.transformer.impl.JMSMessageTransformer.java

/**
 * Transforms {@link javax.jms.MapMessage} to {@link eu.domibus.submission.Submission}
 *
 * @param messageIn the message ({@link javax.jms.MapMessage}) to be tranformed
 * @return the result of the transformation as {@link eu.domibus.submission.Submission}
 *//*  w  w  w  .  j  a v a 2  s. c  o  m*/
@Override
public Submission transformToSubmission(final MapMessage messageIn) {

    final Submission target = new Submission();

    try {

        target.setAction(messageIn.getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_ACTION));
        target.setService(messageIn.getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_SERVICE));
        target.setServiceType(
                messageIn.getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_SERVICE_TYPE));
        target.setConversationId(
                messageIn.getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_CONVERSATION_ID));
        final String fromPartyID = messageIn
                .getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_FROM_PARTY_ID);
        final String fromPartyType = messageIn
                .getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_FROM_PARTY_TYPE);
        target.addFromParty(fromPartyID, fromPartyType);
        target.setFromRole(
                messageIn.getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_FROM_ROLE));
        final String toPartyID = messageIn
                .getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TO_PARTY_ID);
        final String toPartyType = messageIn
                .getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TO_PARTY_TYPE);
        target.addToParty(toPartyID, toPartyType);
        target.setToRole(messageIn.getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TO_ROLE));
        target.addMessageProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_ORIGINAL_SENDER,
                messageIn.getStringProperty(
                        JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_ORIGINAL_SENDER));
        target.addMessageProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_FINAL_RECIPIENT,
                messageIn.getStringProperty(
                        JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_FINAL_RECIPIENT));
        target.setRefToMessageId(
                messageIn.getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_REF_TO_MESSAGE_ID));
        target.setAgreementRef(
                messageIn.getStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_AGREEMENT_REF));
        final int numPayloads = messageIn
                .getIntProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TOTAL_NUMBER_OF_PAYLOADS);

        for (int i = 1; i <= numPayloads; i++) {
            final String propPayload = String.valueOf(MessageFormat
                    .format(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_NAME_FORMAT, i));

            final String bodyloadFileName = JMSMessageTransformer.BODYLOAD_FILE_NAME_FORMAT;

            final String contentId;
            final String mimeType;
            String description = null;
            final byte[] payloadData;
            payloadData = messageIn.getBytes(propPayload);
            final String payMimeTypeProp = String.valueOf(MessageFormat
                    .format(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_MIME_TYPE_FORMAT, i));
            mimeType = messageIn.getStringProperty(payMimeTypeProp);
            final String payDescrip = String.valueOf(MessageFormat
                    .format(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_DESCRIPTION_FORMAT, i));

            if (messageIn.getStringProperty(payDescrip) != null) {
                description = messageIn.getStringProperty(payDescrip);
            }

            final String payContID = String.valueOf(MessageFormat
                    .format(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_MIME_CONTENT_ID_FORMAT, i));

            contentId = messageIn.getStringProperty(payContID);

            final Properties partProperties = new Properties();
            if (mimeType != null && !mimeType.trim().equals("")) {
                partProperties.setProperty(Property.MIME_TYPE, mimeType);
            }

            target.addPayload(contentId, payloadData, partProperties, i == 1, description, null);
        }

    } catch (final JMSException ex) {
        JMSMessageTransformer.LOG.error("Error while getting properties from MapMessage", ex);
        throw new RuntimeException(ex);
    }

    return target;

}