/** * This method is used to populate the individual properties. * * @param key - Property Key * @param value - Property Value * @param type - Type of the property. */ private void populateProperty(String key, Object value, int type, Message msg) throws JMSException { switch (type) { case MessagePropertyImpl.BOOLEAN_PROPERTY: msg.setBooleanProperty(key, (Boolean) value); break; case MessagePropertyImpl.BYTE_PROPERTY: msg.setByteProperty(key, (Byte) value); break; case MessagePropertyImpl.DOUBLE_PROPERTY: msg.setDoubleProperty(key, (Double) value); break; case MessagePropertyImpl.FLOAT_PROPERTY: msg.setFloatProperty(key, (Float) value); break; case MessagePropertyImpl.INTEGER_PROPERTY: msg.setIntProperty(key, (Integer) value); break; case MessagePropertyImpl.LONG_PROPERTY: msg.setLongProperty(key, (Long) value); break; case MessagePropertyImpl.SHORT_PROPERTY: msg.setShortProperty(key, (Short) value); break; case MessagePropertyImpl.STRING_PROPERTY: msg.setStringProperty(key, (String) value); break; case MessagePropertyImpl.OBJECT_PROPERTY: msg.setObjectProperty(key, value); break; default: msg.setObjectProperty(key, value); break; } }
protected Message createMessage() throws JMSException { Message message = createMessage("FOO.BAR"); message.setJMSType("selector-test"); message.setJMSMessageID("connection:1:1:1:1"); message.setObjectProperty("name", "James"); message.setObjectProperty("location", "London"); message.setByteProperty("byteProp", (byte) 123); message.setByteProperty("byteProp2", (byte) 33); message.setShortProperty("shortProp", (short) 123); message.setIntProperty("intProp", 123); message.setLongProperty("longProp", 123); message.setFloatProperty("floatProp", 123); message.setDoubleProperty("doubleProp", 123); message.setIntProperty("rank", 123); message.setIntProperty("version", 2); message.setStringProperty("quote", "'In God We Trust'"); message.setStringProperty("foo", "_foo"); message.setStringProperty("punctuation", "!#$&()*+,-./:;<=>?@[\\]^`{|}~"); message.setStringProperty("endingUnderScore", "XD7xlJIQn_"); message.setBooleanProperty("trueProp", true); message.setBooleanProperty("falseProp", false); return message; }
public static void setProperty(String name, Object value, Message jmsMessage) throws JMSException { if (jmsMessage == null || name == null) { return; } if (value instanceof Boolean) { jmsMessage.setBooleanProperty(name, ((Boolean) value).booleanValue()); } else if (value instanceof Byte) { jmsMessage.setByteProperty(name, ((Byte) value).byteValue()); } else if (value instanceof Double) { jmsMessage.setDoubleProperty(name, ((Double) value).doubleValue()); } else if (value instanceof Float) { jmsMessage.setFloatProperty(name, ((Float) value).floatValue()); } else if (value instanceof Integer) { jmsMessage.setIntProperty(name, ((Integer) value).intValue()); } else if (value instanceof Long) { jmsMessage.setLongProperty(name, ((Long) value).longValue()); } else if (value instanceof Short) { jmsMessage.setShortProperty(name, ((Short) value).shortValue()); } else if (value instanceof String) { jmsMessage.setStringProperty(name, (String) value); } else { jmsMessage.setObjectProperty(name, value); } }
/** * Set the specified properties in the message. * * @param properties * @throws JMSException */ protected void setMessageProperties(Message message, Map<String, ?> properties) throws JMSException { if (properties != null) { for (Map.Entry<String, ?> entry : properties.entrySet()) { Object value = entry.getValue(); if (value instanceof String) { message.setStringProperty(entry.getKey(), (String) value); } else if (value instanceof Integer) { message.setIntProperty(entry.getKey(), (Integer) value); } else if (value instanceof Boolean) { message.setBooleanProperty(entry.getKey(), (Boolean) value); } else if (value instanceof Byte) { message.setByteProperty(entry.getKey(), (Byte) value); } else if (value instanceof Double) { message.setDoubleProperty(entry.getKey(), (Double) value); } else if (value instanceof Float) { message.setFloatProperty(entry.getKey(), (Float) value); } else if (value instanceof Long) { message.setLongProperty(entry.getKey(), (Long) value); } else if (value instanceof Short) { message.setShortProperty(entry.getKey(), (Short) value); } else { message.setObjectProperty(entry.getKey(), value); } } } }
/** * Set property * * @param name The name * @param value The value * @throws JMSException Thrown if an error occurs */ @Override public void setShortProperty(final String name, final short value) throws JMSException { if (ActiveMQRAMessage.trace) { ActiveMQRALogger.LOGGER.trace("setShortProperty(" + name + ", " + value + ")"); } message.setShortProperty(name, value); }
Message createReportResponseMessage(String msg) throws JMSException { Message message = _session.createTextMessage(msg); // Shove some more field table type in the message just to see if the other end can handle it. message.setBooleanProperty("BOOLEAN", true); message.setByteProperty("BYTE", (byte) 5); message.setDoubleProperty("DOUBLE", Math.PI); message.setFloatProperty("FLOAT", 1.0f); message.setIntProperty("INT", 1); message.setShortProperty("SHORT", (short) 1); message.setLongProperty("LONG", (long) 1827361278); message.setStringProperty("STRING", "hello"); return message; }