static protected MapMessage createMapMessage() throws JMSException { MapMessage mapMessage = new ActiveMQMapMessage(); mapMessage.setString("name", "Arnold"); mapMessage.setInt("age", 97); mapMessage.setDouble("xyz", 89686.564); mapMessage.setBoolean("good", true); return mapMessage; }
message.setShort(name, (Short) v); } else if (v instanceof Boolean) { message.setBoolean(name, (Boolean) v); } else if (v instanceof Float) { message.setFloat(name, (Float) v);
@Override public void setBoolean(final String name, final boolean value) throws JMSException { message.setBoolean(name, value); }
public void setBoolean(String name, boolean value) throws JMSException { ((MapMessage) message).setBoolean(name, value); }
public void setBoolean(String name, boolean value) throws JMSException { ((MapMessage) message).setBoolean(name, value); }
/** * Set * @param name The name * @param value The value * @exception JMSException Thrown if an error occurs */ public void setBoolean(final String name, final boolean value) throws JMSException { if (_log.isTraceEnabled()) { _log.trace("setBoolean(" + name + ", " + value + ")"); } ((MapMessage)_message).setBoolean(name, value); }
/** * Set * * @param name The name * @param value The value * @throws JMSException Thrown if an error occurs */ @Override public void setBoolean(final String name, final boolean value) throws JMSException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("setBoolean(" + name + ", " + value + ")"); } ((MapMessage) message).setBoolean(name, value); }
/** * Set * * @param name The name * @param value The value * @throws JMSException Thrown if an error occurs */ @Override public void setBoolean(final String name, final boolean value) throws JMSException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("setBoolean(" + name + ", " + value + ")"); } ((MapMessage) message).setBoolean(name, value); }
/** * Test that the if the name parameter of the set methods of a <code>MapMessage</code> is an empty String, * the method must throw the error <code>java.lang.IllegalArgumentException</code>. * <br /> * @since JMS 1.1 */ public void testEmptyStringInSetMethodsForMapMessage() { try { MapMessage message = senderSession.createMapMessage(); message.setBoolean("", true); fail("Should throw an IllegalArgumentException"); } catch (IllegalArgumentException e) { } catch (JMSException e) { fail("Should throw an IllegalArgumentException, not a" + e); } }
/** * Test that the if the name parameter of the set methods of a <code>MapMessage</code> is <code>null</code>, * the method must throw the error <code>java.lang.IllegalArgumentException</code>. * <br /> * @since JMS 1.1 */ public void testNullInSetMethodsForMapMessage() { try { MapMessage message = senderSession.createMapMessage(); message.setBoolean(null, true); fail("Should throw an IllegalArgumentException"); } catch (IllegalArgumentException e) { } catch (JMSException e) { fail("Should throw an IllegalArgumentException, not a" + e); } }
private void mapToMapMessage(final Map<?, ?> map, MapMessage mapMessage) throws JMSException { for(Entry<?, ?> entry : map.entrySet()) { String key = entry.getKey().toString(); Object value = entry.getValue(); if(value instanceof String) { mapMessage.setString(key, (String)value); } else if(value instanceof Integer) { mapMessage.setInt(key, (Integer)value); } else if(value instanceof Long) { mapMessage.setLong(key, (Long)value); } else if(value instanceof Double) { mapMessage.setDouble(key, (Double)value); } else if(value instanceof Float) { mapMessage.setFloat(key, (Float)value); } else if(value instanceof Boolean) { mapMessage.setBoolean(key, (Boolean)value); } else if(value instanceof Short) { mapMessage.setShort(key, (Short)value); } else if(value instanceof Byte) { mapMessage.setByte(key, (Byte)value); } else if(value instanceof Character) { mapMessage.setChar(key, (Character)value); } else if(value instanceof byte[]) { mapMessage.setBytes(key, (byte[])value); } else { mapMessage.setString(key, value.toString()); } } }
private void sendMapMessageUsingCoreJms(String queueName) throws Exception { Connection jmsConn = null; try { jmsConn = coreCf.createConnection(); Session session = jmsConn.createSession(false, Session.AUTO_ACKNOWLEDGE); MapMessage mapMessage = session.createMapMessage(); mapMessage.setBoolean("aboolean", true); mapMessage.setByte("abyte", (byte) 4); mapMessage.setBytes("abytes", new byte[]{4, 5}); mapMessage.setChar("achar", 'a'); mapMessage.setDouble("adouble", 4.4); mapMessage.setFloat("afloat", 4.5f); mapMessage.setInt("aint", 40); mapMessage.setLong("along", 80L); mapMessage.setShort("ashort", (short) 65); mapMessage.setString("astring", "hello"); Queue queue = session.createQueue(queueName); MessageProducer producer = session.createProducer(queue); producer.send(mapMessage); } finally { if (jmsConn != null) { jmsConn.close(); } } }
/** * Test that the if the name parameter of the set methods of a <code>MapMessage</code> is an empty String, * the method must throw the error <code>java.lang.IllegalArgumentException</code>. * <br /> * * @since JMS 1.1 */ @Test public void testEmptyStringInSetMethodsForMapMessage() { try { MapMessage message = senderSession.createMapMessage(); message.setBoolean("", true); Assert.fail("Should throw an IllegalArgumentException"); } catch (IllegalArgumentException e) { } catch (JMSException e) { Assert.fail("Should throw an IllegalArgumentException, not a" + e); } }
/** * Test that the if the name parameter of the set methods of a <code>MapMessage</code> is <code>null</code>, * the method must throw the error <code>java.lang.IllegalArgumentException</code>. * <br /> * * @since JMS 1.1 */ @Test public void testNullInSetMethodsForMapMessage() { try { MapMessage message = senderSession.createMapMessage(); message.setBoolean(null, true); Assert.fail("Should throw an IllegalArgumentException"); } catch (IllegalArgumentException e) { } catch (JMSException e) { Assert.fail("Should throw an IllegalArgumentException, not a" + e); } }
@Test public void testMapMessage() throws Exception { // Receive a message with the JMS API connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = createDestination(session, destinationType); MessageConsumer consumer = session.createConsumer(destination); MessageProducer producer = session.createProducer(destination); // send the message. { MapMessage message = session.createMapMessage(); message.setBoolean("boolKey", true); producer.send(message); } // get the message. { MapMessage message = (MapMessage) consumer.receive(1000); assertNotNull(message); assertTrue(message.getBoolean("boolKey")); } assertNull(consumer.receiveNoWait()); }
public static void setMapProperty(String name, Object value, MapMessage msg) throws JMSException { if (value == null || msg == null || name == null) return; if (value instanceof String) msg.setString(name, (String)value); else if (value instanceof Boolean) msg.setBoolean(name, (Boolean)value); else if (value instanceof Integer) msg.setInt(name, (Integer)value); else if (value instanceof Long) msg.setLong(name, (Long)value); else if (value instanceof Double) msg.setDouble(name, (Double)value); else if (value instanceof Byte) msg.setByte(name, (Byte)value); else if (value instanceof Float) msg.setFloat(name, (Float)value); else if (value instanceof Short) msg.setShort(name, (Short)value); else msg.setObject(name, value); }
@Test public void testResendWithMapMessagesOnly() throws Exception { conn = cf.createConnection(); conn.start(); Session sess = conn.createSession(true, Session.SESSION_TRANSACTED); ArrayList<Message> msgs = new ArrayList<>(); for (int i = 0; i < 1; i++) { MapMessage mm = sess.createMapMessage(); mm.setBoolean("boolean", true); mm.setByte("byte", (byte) 3); mm.setBytes("bytes", new byte[]{(byte) 3, (byte) 4, (byte) 5}); mm.setChar("char", (char) 6); mm.setDouble("double", 7.0); mm.setFloat("float", 8.0f); mm.setInt("int", 9); mm.setLong("long", 10L); mm.setObject("object", new String("this is an object")); mm.setShort("short", (short) 11); mm.setString("string", "this is a string"); msgs.add(mm); MapMessage emptyMap = sess.createMapMessage(); msgs.add(emptyMap); } internalTestResend(msgs, sess); }
private void sendCompressedMapMessageUsingOpenWire() throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE); final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination); MapMessage mapMessage = session.createMapMessage(); mapMessage.setBoolean("boolean-type", true); mapMessage.setByte("byte-type", (byte) 10); mapMessage.setBytes("bytes-type", TEXT.getBytes()); mapMessage.setChar("char-type", 'A'); mapMessage.setDouble("double-type", 55.3D); mapMessage.setFloat("float-type", 79.1F); mapMessage.setInt("int-type", 37); mapMessage.setLong("long-type", 56652L); mapMessage.setObject("object-type", new String("VVVV")); mapMessage.setShort("short-type", (short) 333); mapMessage.setString("string-type", TEXT); producer.send(mapMessage); }
private void sendMapMessageUsingOpenWire() throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE); System.out.println("destination: " + destination); final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination); MapMessage mapMessage = session.createMapMessage(); mapMessage.setBoolean("aboolean", true); mapMessage.setByte("abyte", (byte) 4); mapMessage.setBytes("abytes", new byte[]{4, 5}); mapMessage.setChar("achar", 'a'); mapMessage.setDouble("adouble", 4.4); mapMessage.setFloat("afloat", 4.5f); mapMessage.setInt("aint", 40); mapMessage.setLong("along", 80L); mapMessage.setShort("ashort", (short) 65); mapMessage.setString("astring", "hello"); producer.send(mapMessage); }
@Override protected void prepareMessage(final Message m) throws JMSException { super.prepareMessage(m); MapMessage mm = (MapMessage) m; mm.setBoolean("boolean", true); mm.setByte("byte", (byte) 3); mm.setBytes("bytes", new byte[]{(byte) 3, (byte) 4, (byte) 5}); mm.setChar("char", (char) 6); mm.setDouble("double", 7.0); mm.setFloat("float", 8.0f); mm.setInt("int", 9); mm.setLong("long", 10L); mm.setObject("object", new String("this is an object")); mm.setShort("short", (short) 11); mm.setString("string", "this is a string"); }