Example usage for javax.jms Message getIntProperty

List of usage examples for javax.jms Message getIntProperty

Introduction

In this page you can find the example usage for javax.jms Message getIntProperty.

Prototype


int getIntProperty(String name) throws JMSException;

Source Link

Document

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

Usage

From source file:com.adaptris.core.jms.MessageTypeTranslatorCase.java

public static void assertJmsProperties(Message jmsMsg) throws JMSException {
    assertEquals(STRING_VALUE, jmsMsg.getStringProperty(STRING_METADATA));
    assertEquals(BOOLEAN_VALUE, jmsMsg.getStringProperty(BOOLEAN_METADATA));
    assertEquals(Boolean.valueOf(BOOLEAN_VALUE).booleanValue(), jmsMsg.getBooleanProperty(BOOLEAN_METADATA)); // default
    assertEquals(INTEGER_VALUE, jmsMsg.getStringProperty(INTEGER_METADATA));
    assertEquals(Integer.valueOf(INTEGER_VALUE).intValue(), jmsMsg.getIntProperty(INTEGER_METADATA));
}

From source file:net.homecredit.book.jms.JmsMessageListener.java

/**
 * Implementation of <code>MessageListener</code>.
 *//* ww  w .  ja v a2  s . c om*/
public void onMessage(Message message) {
    try {
        int messageCount = message.getIntProperty(JmsMessageProducer.MESSAGE_COUNT);

        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            String msg = tm.getText();

            logger.info("Processed message '{}'.  value={}", msg, messageCount);

            counter.incrementAndGet();
        }
    } catch (JMSException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:com.solveapuzzle.mapping.agnostic.JmsMessageListener.java

/**
 * Implementation of <code>MessageListener</code>.
 *//*from   w  ww .j ava2  s  .  com*/
public void onMessage(Message message) {
    try {
        int messageCount = message.getIntProperty(JmsMessageProducer.MESSAGE_COUNT);

        logger.info("Processed message '{}'.  value={}", message, messageCount);

        counter.incrementAndGet();

        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            String msg = tm.getText();

            logger.info(" Read Transform property " + message.getStringProperty(TRANSFORM));

            try {

                String parser = tm.getStringProperty(PARSER);
                String key = tm.getStringProperty(TRANSFORM);

                logger.info(" Read Transform propertys " + parser + " " + key);

                String response = engine.onTransformEvent(this.createConfig(parser, key), tm.getText(),
                        Charset.defaultCharset());

                logger.info(" Response " + response);

                logger.info("message ReplyTo ID " + tm.getJMSCorrelationID());

                tm.setJMSDestination(this.outDestination);

                javax.jms.Queue queue = (javax.jms.Queue) tm.getJMSDestination();
                logger.info("ReplyTo Queue name = " + queue.getQueueName());

                tm.clearBody();

                tm.setText(response);
                // Push to response queue

            } catch (MappingException e) {
                logger.error("Mapping exception from transformation ", e);
                // push to mapping error Queue?
                // May be fixable with input xml change or due to data quality, invalid against schema

                throw new RuntimeException(e);
            } catch (ConfigurationException e) {
                logger.error("Configuration exception from transformation", e);
                // Can't fix - dead letter queue - but worth tracing what config went missing?
                throw new RuntimeException(e);
            }

        }
    } catch (JMSException e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}

From source file:org.hawkular.apm.server.jms.RetryCapableMDB.java

@Override
public void onMessage(Message message) {
    if (log.isLoggable(Level.FINEST)) {
        log.finest("Message received=" + message);
    }//w  w w  .  j a  va  2s.  co  m

    try {
        String tenantId = message.getStringProperty("tenant");

        int retryCount;

        if (message.propertyExists("retryCount")) {
            retryCount = message.getIntProperty("retryCount");
        } else {
            retryCount = maxRetryCount;
        }

        String data = ((TextMessage) message).getText();

        List<S> items = mapper.readValue(data, getTypeReference());

        process(tenantId, items, retryCount);

    } catch (Exception e) {
        if (processor.isReportRetryExpirationAsWarning()) {
            serverMsgLogger.warnMaxRetryReached(e);
        } else if (log.isLoggable(Level.FINEST)) {
            log.log(Level.FINEST, "Maximum retry reached. Last exception to occur ....", e);
        }
    }
}

From source file:nl.nn.adapterframework.extensions.ifsa.jms.PushingIfsaProviderListener.java

public int getDeliveryCount(Object rawMessage) {
    try {//ww  w. j a va2s .  co  m
        Message message = (Message) rawMessage;
        int value = message.getIntProperty("JMSXDeliveryCount");
        if (log.isDebugEnabled())
            log.debug("determined delivery count [" + value + "]");
        return value;
    } catch (Exception e) {
        log.error(getLogPrefix() + "exception in determination of DeliveryCount", e);
        return -1;
    }
}

From source file:nl.nn.adapterframework.jms.PushingJmsListener.java

public int getDeliveryCount(Object rawMessage) {
    try {//from   www .ja v a2 s. c  o  m
        Message message = (Message) rawMessage;
        // Note: Tibco doesn't set the JMSXDeliveryCount for messages
        // delivered for the first time (when JMSRedelivered is set to
        // false). Hence when set is has a value of 2 or higher. When not
        // set a NumberFormatException is thrown.
        int value = message.getIntProperty("JMSXDeliveryCount");
        if (log.isDebugEnabled())
            log.debug("determined delivery count [" + value + "]");
        return value;
    } catch (NumberFormatException nfe) {
        if (log.isDebugEnabled())
            log.debug(getLogPrefix() + "NumberFormatException in determination of DeliveryCount");
        return -1;
    } catch (Exception e) {
        log.error(getLogPrefix() + "exception in determination of DeliveryCount", e);
        return -1;
    }
}

From source file:org.apache.activemq.store.jdbc.JmsTransactionCommitFailureTest.java

@Test
public void testJmsTransactionCommitFailure() throws Exception {
    String queueName = "testJmsTransactionCommitFailure";
    // Send 1.message
    sendMessage(queueName, 1);//from w  w  w. j  a va2  s  .c o  m
    // Check message count directly in database
    Assert.assertEquals(1L, getMessageCount());

    // Set failure flag on persistence adapter
    persistenceAdapter.setCommitFailureEnabled(true);
    // Send 2.message and 3.message in one JMS transaction
    try {
        LOGGER.warn("Attempt to send Message-2/Message-3 (first time)...");
        sendMessage(queueName, 2);
        LOGGER.warn("Message-2/Message-3 successfuly sent (first time)");
        Assert.fail();
    } catch (JMSException jmse) {
        // Expected - decrease message counter (I want to repeat message send)
        LOGGER.warn("Attempt to send Message-2/Message-3 failed", jmse);
        messageCounter -= 2;
        Assert.assertEquals(1L, getMessageCount());
    }

    // Reset failure flag on persistence adapter
    persistenceAdapter.setCommitFailureEnabled(false);
    // Send 2.message again
    LOGGER.warn("Attempt to send Message-2/Message-3 (second time)...");
    sendMessage(queueName, 2);
    LOGGER.warn("Message-2/Message-3 successfuly sent (second time)");

    int expectedMessageCount = 3;
    // Check message count directly in database
    Assert.assertEquals(3L, getMessageCount());
    // Attempt to receive 3 (expected) messages
    for (int i = 1; i <= expectedMessageCount; i++) {
        Message message = receiveMessage(queueName, 10000);
        LOGGER.warn(i + ". Message received (" + message + ")");
        Assert.assertNotNull(message);
        Assert.assertTrue(message instanceof TextMessage);
        Assert.assertEquals(i, message.getIntProperty("MessageId"));
        Assert.assertEquals("Message-" + i, ((TextMessage) message).getText());
        // Check message count directly in database
        //Assert.assertEquals(expectedMessageCount - i, getMessageCount());
    }

    // Check message count directly in database
    Assert.assertEquals(0, getMessageCount());
    // No next message is expected
    Assert.assertNull(receiveMessage(queueName, 4000));
}

From source file:org.apache.axis2.transport.jms.JMSUtils.java

/**
 * Extract transport level headers for JMS from the given message into a Map
 *
 * @param message the JMS message//from w w w. j a va2  s  .c  om
 * @return a Map of the transport headers
 */
public static Map<String, Object> getTransportHeaders(Message message) {
    // create a Map to hold transport headers
    Map<String, Object> map = new HashMap<String, Object>();

    // correlation ID
    try {
        if (message.getJMSCorrelationID() != null) {
            map.put(JMSConstants.JMS_COORELATION_ID, message.getJMSCorrelationID());
        }
    } catch (JMSException ignore) {
    }

    // set the delivery mode as persistent or not
    try {
        map.put(JMSConstants.JMS_DELIVERY_MODE, Integer.toString(message.getJMSDeliveryMode()));
    } catch (JMSException ignore) {
    }

    // destination name
    try {
        if (message.getJMSDestination() != null) {
            Destination dest = message.getJMSDestination();
            map.put(JMSConstants.JMS_DESTINATION,
                    dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName());
        }
    } catch (JMSException ignore) {
    }

    // expiration
    try {
        map.put(JMSConstants.JMS_EXPIRATION, Long.toString(message.getJMSExpiration()));
    } catch (JMSException ignore) {
    }

    // if a JMS message ID is found
    try {
        if (message.getJMSMessageID() != null) {
            map.put(JMSConstants.JMS_MESSAGE_ID, message.getJMSMessageID());
        }
    } catch (JMSException ignore) {
    }

    // priority
    try {
        map.put(JMSConstants.JMS_PRIORITY, Long.toString(message.getJMSPriority()));
    } catch (JMSException ignore) {
    }

    // redelivered
    try {
        map.put(JMSConstants.JMS_REDELIVERED, Boolean.toString(message.getJMSRedelivered()));
    } catch (JMSException ignore) {
    }

    // replyto destination name
    try {
        if (message.getJMSReplyTo() != null) {
            Destination dest = message.getJMSReplyTo();
            map.put(JMSConstants.JMS_REPLY_TO,
                    dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName());
        }
    } catch (JMSException ignore) {
    }

    // priority
    try {
        map.put(JMSConstants.JMS_TIMESTAMP, Long.toString(message.getJMSTimestamp()));
    } catch (JMSException ignore) {
    }

    // message type
    try {
        if (message.getJMSType() != null) {
            map.put(JMSConstants.JMS_TYPE, message.getJMSType());
        }
    } catch (JMSException ignore) {
    }

    // any other transport properties / headers
    Enumeration<?> e = null;
    try {
        e = message.getPropertyNames();
    } catch (JMSException ignore) {
    }

    if (e != null) {
        while (e.hasMoreElements()) {
            String headerName = (String) e.nextElement();
            try {
                map.put(headerName, message.getStringProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getBooleanProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getIntProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getLongProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getDoubleProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getFloatProperty(headerName));
            } catch (JMSException ignore) {
            }
        }
    }

    return map;
}

From source file:org.apache.synapse.transport.jms.JMSUtils.java

/**
 * Extract transport level headers for JMS from the given message into a Map
 *
 * @param message the JMS message//  w ww .jav a2s  . c  o m
 * @return a Map of the transport headers
 */
public static Map getTransportHeaders(Message message) {
    // create a Map to hold transport headers
    Map map = new HashMap();

    // correlation ID
    try {
        if (message.getJMSCorrelationID() != null) {
            map.put(JMSConstants.JMS_COORELATION_ID, message.getJMSCorrelationID());
        }
    } catch (JMSException ignore) {
    }

    // set the delivery mode as persistent or not
    try {
        map.put(JMSConstants.JMS_DELIVERY_MODE, Integer.toString(message.getJMSDeliveryMode()));
    } catch (JMSException ignore) {
    }

    // destination name
    try {
        if (message.getJMSDestination() != null) {
            Destination dest = message.getJMSDestination();
            map.put(JMSConstants.JMS_DESTINATION,
                    dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName());
        }
    } catch (JMSException ignore) {
    }

    // expiration
    try {
        map.put(JMSConstants.JMS_EXPIRATION, Long.toString(message.getJMSExpiration()));
    } catch (JMSException ignore) {
    }

    // if a JMS message ID is found
    try {
        if (message.getJMSMessageID() != null) {
            map.put(JMSConstants.JMS_MESSAGE_ID, message.getJMSMessageID());
        }
    } catch (JMSException ignore) {
    }

    // priority
    try {
        map.put(JMSConstants.JMS_PRIORITY, Long.toString(message.getJMSPriority()));
    } catch (JMSException ignore) {
    }

    // redelivered
    try {
        map.put(JMSConstants.JMS_REDELIVERED, Boolean.toString(message.getJMSRedelivered()));
    } catch (JMSException ignore) {
    }

    // replyto destination name
    try {
        if (message.getJMSReplyTo() != null) {
            Destination dest = message.getJMSReplyTo();
            map.put(JMSConstants.JMS_REPLY_TO,
                    dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName());
        }
    } catch (JMSException ignore) {
    }

    // priority
    try {
        map.put(JMSConstants.JMS_TIMESTAMP, Long.toString(message.getJMSTimestamp()));
    } catch (JMSException ignore) {
    }

    // message type
    try {
        if (message.getJMSType() != null) {
            map.put(JMSConstants.JMS_TYPE, message.getJMSType());
        }
    } catch (JMSException ignore) {
    }

    // any other transport properties / headers
    Enumeration e = null;
    try {
        e = message.getPropertyNames();
    } catch (JMSException ignore) {
    }

    if (e != null) {
        while (e.hasMoreElements()) {
            String headerName = (String) e.nextElement();
            try {
                map.put(headerName, message.getStringProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, Boolean.valueOf(message.getBooleanProperty(headerName)));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, new Integer(message.getIntProperty(headerName)));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, new Long(message.getLongProperty(headerName)));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, new Double(message.getDoubleProperty(headerName)));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, new Float(message.getFloatProperty(headerName)));
                continue;
            } catch (JMSException ignore) {
            }
        }
    }

    return map;
}

From source file:org.mule.transport.jms.filters.JmsPropertyFilter.java

public boolean accept(MuleMessage message) {
    if (StringUtils.isBlank(propertyName)) {
        logger.warn("No property name was specified");
        return false;
    }/* w w  w .ja v  a2s  .  com*/

    if (StringUtils.isBlank(expression) && pattern == null) {
        logger.warn("Either no expression or pattern was specified");
        return false;
    }

    if (message.getPayload() instanceof javax.jms.Message) {
        try {
            Message m = (javax.jms.Message) message.getPayload();

            if (StringUtils.isBlank(propertyClass)) {
                Object object = m.getObjectProperty(propertyName);
                if (object == null) {
                    return false;
                }
                String value = object.toString();

                if (pattern != null) {
                    return pattern.matcher(value).find();
                } else {
                    return value.equals(expression);
                }
            } else if (propertyClass.equals("java.lang.String")) {
                String value = m.getStringProperty(propertyName);
                if (value == null) {
                    return false;
                }

                if (pattern != null) {
                    return pattern.matcher(value).find();
                } else {
                    return value.equals(expression);
                }
            } else if (propertyClass.equals("java.lang.Integer")) {
                int value = m.getIntProperty(propertyName);
                int match = Integer.parseInt(expression);
                return (value == match);
            } else if (propertyClass.equals("java.lang.Short")) {
                short value = m.getShortProperty(propertyName);
                short match = Short.parseShort(expression);
                return (value == match);
            }
        } catch (NumberFormatException nfe) {
            logger.warn("Unable to convert expression " + expression + " to " + propertyClass + ": "
                    + nfe.toString());
        } catch (Exception e) {
            logger.warn("Error filtering on property " + propertyName + ": " + e.toString());
        }
    } else {
        logger.warn("Expected a payload of javax.jms.Message but instead received "
                + ClassUtils.getSimpleName(message.getPayload().getClass()));
    }

    return false;
}