类javax.jms.MessageFormatRuntimeException源码实例Demo

下面列出了怎么用javax.jms.MessageFormatRuntimeException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: activemq-artemis   文件: JMSContextTest.java
@Test
public void testJMSContextConsumerThrowsMessageFormatExceptionOnMalformedBody() throws Exception {
   Queue queue = createQueue(true, "ContextMalformedBodyTestQueue");

   JMSContext context = qraConnectionFactory.createContext();
   JMSProducer producer = context.createProducer();

   TextMessage message = context.createTextMessage("TestMessage");
   producer.send(queue, message);

   JMSConsumer consumer = context.createConsumer(queue);

   try {
      consumer.receiveBody(Boolean.class);
      fail("Should thrown MessageFormatException");
   } catch (MessageFormatRuntimeException mfre) {
      // Do nothing test passed
   } catch (Exception e) {
      fail("Threw wrong exception, should be MessageFormatRuntimeException, instead got: " + e.getClass().getCanonicalName());
   }
}
 
源代码2 项目: activemq-artemis   文件: JmsProducerTest.java
@Test
public void testSetters() {
   long v = random.nextLong();
   producer.setDeliveryDelay(v);
   Assert.assertEquals(v, producer.getDeliveryDelay());

   long l = random.nextLong();
   producer.setTimeToLive(l);
   Assert.assertEquals(l, producer.getTimeToLive());

   String id = "ID: jms2-tests-correlation-id" + random.nextLong();
   producer.setJMSCorrelationID(id);
   Assert.assertEquals(id, producer.getJMSCorrelationID());

   //set a property of an invalid type (ArrayList)
   try {
      producer.setProperty("name1", new ArrayList<String>(2));
      fail("didn't get expected MessageFormatRuntimeException");
   } catch (MessageFormatRuntimeException e) {
      //expected.
   }
}
 
源代码3 项目: pooled-jms   文件: JmsPoolJMSProducerTest.java
@Test
public void testSetPropertyConversions() {
    JMSProducer producer = context.createProducer();

    producer.setProperty(STRING_PROPERTY_NAME, STRING_PROPERTY_VALUE);
    producer.setProperty(BYTE_PROPERTY_NAME, Byte.valueOf(BYTE_PROPERTY_VALUE));
    producer.setProperty(BOOLEAN_PROPERTY_NAME, Boolean.valueOf(BOOLEAN_PROPERTY_VALUE));
    producer.setProperty(SHORT_PROPERTY_NAME, Short.valueOf(SHORT_PROPERTY_VALUE));
    producer.setProperty(INTEGER_PROPERTY_NAME, Integer.valueOf(INTEGER_PROPERTY_VALUE));
    producer.setProperty(LONG_PROPERTY_NAME, Long.valueOf(LONG_PROPERTY_VALUE));
    producer.setProperty(FLOAT_PROPERTY_NAME, Float.valueOf(FLOAT_PROPERTY_VALUE));
    producer.setProperty(DOUBLE_PROPERTY_NAME, Double.valueOf(DOUBLE_PROPERTY_VALUE));

    try {
        producer.setProperty(STRING_PROPERTY_NAME, UUID.randomUUID());
        fail("Should not be able to set non-primitive type");
    } catch (MessageFormatRuntimeException mfe) {
    }

    assertNull(producer.getObjectProperty("Unknown"));

    assertEquals(STRING_PROPERTY_VALUE, producer.getStringProperty(STRING_PROPERTY_NAME));
    assertEquals(BYTE_PROPERTY_VALUE, producer.getByteProperty(BYTE_PROPERTY_NAME));
    assertEquals(BOOLEAN_PROPERTY_VALUE, producer.getBooleanProperty(BOOLEAN_PROPERTY_NAME));
    assertEquals(SHORT_PROPERTY_VALUE, producer.getShortProperty(SHORT_PROPERTY_NAME));
    assertEquals(INTEGER_PROPERTY_VALUE, producer.getIntProperty(INTEGER_PROPERTY_NAME));
    assertEquals(LONG_PROPERTY_VALUE, producer.getLongProperty(LONG_PROPERTY_NAME));
    assertEquals(FLOAT_PROPERTY_VALUE, producer.getFloatProperty(FLOAT_PROPERTY_NAME), 0.0);
    assertEquals(DOUBLE_PROPERTY_VALUE, producer.getDoubleProperty(DOUBLE_PROPERTY_NAME), 0.0);

    assertEquals(STRING_PROPERTY_VALUE, producer.getObjectProperty(STRING_PROPERTY_NAME));
    assertEquals(BYTE_PROPERTY_VALUE, producer.getObjectProperty(BYTE_PROPERTY_NAME));
    assertEquals(BOOLEAN_PROPERTY_VALUE, producer.getObjectProperty(BOOLEAN_PROPERTY_NAME));
    assertEquals(SHORT_PROPERTY_VALUE, producer.getObjectProperty(SHORT_PROPERTY_NAME));
    assertEquals(INTEGER_PROPERTY_VALUE, producer.getObjectProperty(INTEGER_PROPERTY_NAME));
    assertEquals(LONG_PROPERTY_VALUE, producer.getObjectProperty(LONG_PROPERTY_NAME));
    assertEquals(FLOAT_PROPERTY_VALUE, producer.getObjectProperty(FLOAT_PROPERTY_NAME));
    assertEquals(DOUBLE_PROPERTY_VALUE, producer.getObjectProperty(DOUBLE_PROPERTY_NAME));
}
 
源代码4 项目: pooled-jms   文件: JmsPoolJMSProducerTest.java
@Test
public void testSetObjectPropertyWithInvalidObject() {
    JMSProducer producer = context.createProducer();

    try {
        producer.setProperty(GOOD_PROPERTY_NAME, UUID.randomUUID());
        fail("Should not accept invalid property name");
    } catch (MessageFormatRuntimeException mfre) {}
}
 
源代码5 项目: pooled-jms   文件: JmsPoolJMSProducerTest.java
@Test
public void testSendNullMessageThrowsMFRE() throws JMSException {
    JMSProducer producer = context.createProducer();

    try {
        producer.send(JMS_DESTINATION, (Message) null);
        fail("Should throw a MessageFormatRuntimeException");
    } catch (MessageFormatRuntimeException mfre) {
    } catch (Exception e) {
        fail("Should throw a MessageFormatRuntimeException");
    }
}
 
源代码6 项目: activemq-artemis   文件: JmsContextTest.java
@Test
public void testInvalidMessage() {
   JMSProducer producer = context.createProducer();
   try {
      producer.send(queue1, (Message) null);
      Assert.fail("null msg");
   } catch (MessageFormatRuntimeException expected) {
      // no-op
   }
}
 
源代码7 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public JMSProducer send(Destination destination, Message message) {
   if (message == null) {
      throw new MessageFormatRuntimeException("null message");
   }

   try {
      if (jmsHeaderCorrelationID != null) {
         message.setJMSCorrelationID(jmsHeaderCorrelationID);
      }
      if (jmsHeaderCorrelationIDAsBytes != null && jmsHeaderCorrelationIDAsBytes.length > 0) {
         message.setJMSCorrelationIDAsBytes(jmsHeaderCorrelationIDAsBytes);
      }
      if (jmsHeaderReplyTo != null) {
         message.setJMSReplyTo(jmsHeaderReplyTo);
      }
      if (jmsHeaderType != null) {
         message.setJMSType(jmsHeaderType);
      }
      // XXX HORNETQ-1209 "JMS 2.0" can this be a foreign msg?
      // if so, then "SimpleString" properties will trigger an error.
      setProperties(message);
      if (completionListener != null) {
         CompletionListener wrapped = new CompletionListenerWrapper(completionListener);
         producer.send(destination, message, wrapped);
      } else {
         producer.send(destination, message);
      }
   } catch (JMSException e) {
      throw JmsExceptionUtils.convertToRuntimeException(e);
   }
   return this;
}
 
源代码8 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public JMSProducer send(Destination destination, Map<String, Object> body) {
   MapMessage message = context.createMapMessage();
   if (body != null) {
      try {
         for (Entry<String, Object> entry : body.entrySet()) {
            final String name = entry.getKey();
            final Object v = entry.getValue();
            if (v instanceof String) {
               message.setString(name, (String) v);
            } else if (v instanceof Long) {
               message.setLong(name, (Long) v);
            } else if (v instanceof Double) {
               message.setDouble(name, (Double) v);
            } else if (v instanceof Integer) {
               message.setInt(name, (Integer) v);
            } else if (v instanceof Character) {
               message.setChar(name, (Character) v);
            } else if (v instanceof Short) {
               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);
            } else if (v instanceof Byte) {
               message.setByte(name, (Byte) v);
            } else if (v instanceof byte[]) {
               byte[] array = (byte[]) v;
               message.setBytes(name, array, 0, array.length);
            } else {
               message.setObject(name, v);
            }
         }
      } catch (JMSException e) {
         throw new MessageFormatRuntimeException(e.getMessage());
      }
   }
   send(destination, message);
   return this;
}
 
源代码9 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public JMSProducer send(Destination destination, byte[] body) {
   BytesMessage message = context.createBytesMessage();
   if (body != null) {
      try {
         message.writeBytes(body);
      } catch (JMSException e) {
         throw new MessageFormatRuntimeException(e.getMessage());
      }
   }
   send(destination, message);
   return this;
}
 
源代码10 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public JMSProducer setProperty(String name, Object value) {
   checkName(name);
   try {
      TypedProperties.setObjectProperty(new SimpleString(name), value, properties);
   } catch (ActiveMQPropertyConversionException amqe) {
      throw new MessageFormatRuntimeException(amqe.getMessage());
   } catch (RuntimeException e) {
      throw new JMSRuntimeException(e.getMessage());
   }
   return this;
}
 
源代码11 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public boolean getBooleanProperty(String name) {
   try {
      return properties.getBooleanProperty(new SimpleString(name));
   } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
   } catch (RuntimeException e) {
      throw new JMSRuntimeException(e.getMessage());
   }
}
 
源代码12 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public byte getByteProperty(String name) {
   try {
      return properties.getByteProperty(new SimpleString(name));
   } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
   }
}
 
源代码13 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public short getShortProperty(String name) {
   try {
      return properties.getShortProperty(new SimpleString(name));
   } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
   }
}
 
源代码14 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public int getIntProperty(String name) {
   try {
      return properties.getIntProperty(new SimpleString(name));
   } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
   }
}
 
源代码15 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public long getLongProperty(String name) {
   try {
      return properties.getLongProperty(new SimpleString(name));
   } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
   }
}
 
源代码16 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public float getFloatProperty(String name) {
   try {
      return properties.getFloatProperty(new SimpleString(name));
   } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
   }
}
 
源代码17 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public double getDoubleProperty(String name) {
   try {
      return properties.getDoubleProperty(new SimpleString(name));
   } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
   }
}
 
源代码18 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public String getStringProperty(String name) {
   try {
      SimpleString prop = properties.getSimpleStringProperty(new SimpleString(name));
      if (prop == null)
         return null;
      return prop.toString();
   } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
   } catch (RuntimeException e) {
      throw new JMSRuntimeException(e.getMessage());
   }
}
 
源代码19 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public Object getObjectProperty(String name) {
   try {
      SimpleString key = new SimpleString(name);
      Object property = properties.getProperty(key);
      if (stringPropertyNames.contains(key)) {
         property = property.toString();
      }
      return property;
   } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
   } catch (RuntimeException e) {
      throw new JMSRuntimeException(e.getMessage());
   }
}
 
源代码20 项目: activemq-artemis   文件: ActiveMQJMSProducer.java
@Override
public Set<String> getPropertyNames() {
   try {
      return properties.getMapNames();
   } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
   } catch (RuntimeException e) {
      throw new JMSRuntimeException(e.getMessage());
   }
}
 
源代码21 项目: activemq-artemis   文件: JmsExceptionUtils.java
/**
 * Converts instances of sub-classes of {@link JMSException} into the corresponding sub-class of
 * {@link JMSRuntimeException}.
 *
 * @param e
 * @return
 */
public static JMSRuntimeException convertToRuntimeException(JMSException e) {
   if (e instanceof javax.jms.IllegalStateException) {
      return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidClientIDException) {
      return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidDestinationException) {
      return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidSelectorException) {
      return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof JMSSecurityException) {
      return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof MessageFormatException) {
      return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof MessageNotWriteableException) {
      return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof ResourceAllocationException) {
      return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof TransactionInProgressException) {
      return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof TransactionRolledBackException) {
      return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
 
源代码22 项目: qpid-jms   文件: JmsProducerTest.java
@Test
public void testSetPropertyConversions() {
    JMSProducer producer = context.createProducer();

    producer.setProperty(STRING_PROPERTY_NAME, STRING_PROPERTY_VALUE);
    producer.setProperty(BYTE_PROPERTY_NAME, Byte.valueOf(BYTE_PROPERTY_VALUE));
    producer.setProperty(BOOLEAN_PROPERTY_NAME, Boolean.valueOf(BOOLEAN_PROPERTY_VALUE));
    producer.setProperty(SHORT_PROPERTY_NAME, Short.valueOf(SHORT_PROPERTY_VALUE));
    producer.setProperty(INTEGER_PROPERTY_NAME, Integer.valueOf(INTEGER_PROPERTY_VALUE));
    producer.setProperty(LONG_PROPERTY_NAME, Long.valueOf(LONG_PROPERTY_VALUE));
    producer.setProperty(FLOAT_PROPERTY_NAME, Float.valueOf(FLOAT_PROPERTY_VALUE));
    producer.setProperty(DOUBLE_PROPERTY_NAME, Double.valueOf(DOUBLE_PROPERTY_VALUE));

    try {
        producer.setProperty(STRING_PROPERTY_NAME, UUID.randomUUID());
        fail("Should not be able to set non-primitive type");
    } catch (MessageFormatRuntimeException mfe) {
    }

    assertNull(producer.getObjectProperty("Unknown"));

    assertEquals(STRING_PROPERTY_VALUE, producer.getStringProperty(STRING_PROPERTY_NAME));
    assertEquals(BYTE_PROPERTY_VALUE, producer.getByteProperty(BYTE_PROPERTY_NAME));
    assertEquals(BOOLEAN_PROPERTY_VALUE, producer.getBooleanProperty(BOOLEAN_PROPERTY_NAME));
    assertEquals(SHORT_PROPERTY_VALUE, producer.getShortProperty(SHORT_PROPERTY_NAME));
    assertEquals(INTEGER_PROPERTY_VALUE, producer.getIntProperty(INTEGER_PROPERTY_NAME));
    assertEquals(LONG_PROPERTY_VALUE, producer.getLongProperty(LONG_PROPERTY_NAME));
    assertEquals(FLOAT_PROPERTY_VALUE, producer.getFloatProperty(FLOAT_PROPERTY_NAME), 0.0);
    assertEquals(DOUBLE_PROPERTY_VALUE, producer.getDoubleProperty(DOUBLE_PROPERTY_NAME), 0.0);

    assertEquals(STRING_PROPERTY_VALUE, producer.getObjectProperty(STRING_PROPERTY_NAME));
    assertEquals(BYTE_PROPERTY_VALUE, producer.getObjectProperty(BYTE_PROPERTY_NAME));
    assertEquals(BOOLEAN_PROPERTY_VALUE, producer.getObjectProperty(BOOLEAN_PROPERTY_NAME));
    assertEquals(SHORT_PROPERTY_VALUE, producer.getObjectProperty(SHORT_PROPERTY_NAME));
    assertEquals(INTEGER_PROPERTY_VALUE, producer.getObjectProperty(INTEGER_PROPERTY_NAME));
    assertEquals(LONG_PROPERTY_VALUE, producer.getObjectProperty(LONG_PROPERTY_NAME));
    assertEquals(FLOAT_PROPERTY_VALUE, producer.getObjectProperty(FLOAT_PROPERTY_NAME));
    assertEquals(DOUBLE_PROPERTY_VALUE, producer.getObjectProperty(DOUBLE_PROPERTY_NAME));
}
 
源代码23 项目: qpid-jms   文件: JmsProducerTest.java
@Test
public void testSetObjectPropetryWithInvalidObject() {
    JMSProducer producer = context.createProducer();

    try {
        producer.setProperty(GOOD_PROPERTY_NAME, UUID.randomUUID());
        fail("Should not accept invalid property name");
    } catch (MessageFormatRuntimeException mfre) {}
}
 
源代码24 项目: qpid-jms   文件: JmsProducerTest.java
@Test
public void testSendNullMessageThrowsMFRE() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);

    JmsProducer producer = new JmsProducer(session, messageProducer);

    try {
        producer.send(JMS_DESTINATION, (Message) null);
        fail("Should throw a MessageFormatRuntimeException");
    } catch (MessageFormatRuntimeException mfre) {
    } catch (Exception e) {
        fail("Should throw a MessageFormatRuntimeException");
    }
}
 
源代码25 项目: qpid-jms   文件: JMSConsumerIntegrationTest.java
public void doTestReceiveBodyFailsDoesNotAcceptMessage(int sessionMode) throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JMSContext context = testFixture.createJMSContext(testPeer);

        testPeer.expectBegin();

        final String content = "Message-Content";
        Queue queue = context.createQueue("myQueue");

        DescribedType amqpValueContent = new AmqpValueDescribedType(content);

        testPeer.expectReceiverAttach();
        testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, amqpValueContent);
        testPeer.expectEnd();
        testPeer.expectClose();

        JMSConsumer messageConsumer = context.createConsumer(queue);
        try {
            messageConsumer.receiveBody(Boolean.class, 3000);
            fail("Should not read as Boolean type");
        } catch (MessageFormatRuntimeException mfre) {
        }

        context.close();

        testPeer.waitForAllHandlersToComplete(3000);
    }
}
 
源代码26 项目: tomee   文件: JMS2.java
public static JMSRuntimeException toRuntimeException(final JMSException e) {
    if (e instanceof javax.jms.IllegalStateException) {
        return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidClientIDException) {
        return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidDestinationException) {
        return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidSelectorException) {
        return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof JMSSecurityException) {
        return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof MessageFormatException) {
        return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof MessageNotWriteableException) {
        return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof ResourceAllocationException) {
        return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof TransactionInProgressException) {
        return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof TransactionRolledBackException) {
        return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
 
源代码27 项目: tomee   文件: JMSProducerImpl.java
private <T> T getProperty(final String key, final Class<T> type) {
    final Object val = properties.get(key);
    if (val == null || type.isInstance(val)) {
        return type.cast(val);
    }
    try {
        return type.cast(propertyEditorRegistry.getValue(type, val.toString()));
    } catch (final PropertyEditorException pee) {
        throw new MessageFormatRuntimeException(pee.getMessage());
    }
}
 
源代码28 项目: tomee   文件: JMSProducerImpl.java
@Override
public JMSProducer send(final Destination destination, final Message message) {
    if (message == null) {
        throw new MessageFormatRuntimeException("null message");
    }

    try {
        if (jmsHeaderCorrelationID != null) {
            message.setJMSCorrelationID(jmsHeaderCorrelationID);
        }
        if (jmsHeaderCorrelationIDAsBytes != null && jmsHeaderCorrelationIDAsBytes.length > 0) {
            message.setJMSCorrelationIDAsBytes(jmsHeaderCorrelationIDAsBytes);
        }
        if (jmsHeaderReplyTo != null) {
            message.setJMSReplyTo(jmsHeaderReplyTo);
        }
        if (jmsHeaderType != null) {
            message.setJMSType(jmsHeaderType);
        }

        setProperties(message);
        if (completionListener != null) {
            producer.send(destination, message, completionListener);
        } else {
            producer.send(destination, message);
        }
    } catch (final JMSException e) {
        throw toRuntimeException(e);
    }
    return this;
}
 
源代码29 项目: tomee   文件: JMSProducerImpl.java
@Override
public JMSProducer send(final Destination destination, final Map<String, Object> body) {
    final MapMessage message = wrap(context.createMapMessage());
    if (body != null) {
        try {
            for (final Map.Entry<String, Object> entry : body.entrySet()) {
                final String name = entry.getKey();
                final Object v = entry.getValue();
                if (v instanceof String) {
                    message.setString(name, (String) v);
                } else if (v instanceof Long) {
                    message.setLong(name, (Long) v);
                } else if (v instanceof Double) {
                    message.setDouble(name, (Double) v);
                } else if (v instanceof Integer) {
                    message.setInt(name, (Integer) v);
                } else if (v instanceof Character) {
                    message.setChar(name, (Character) v);
                } else if (v instanceof Short) {
                    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);
                } else if (v instanceof Byte) {
                    message.setByte(name, (Byte) v);
                } else if (v instanceof byte[]) {
                    byte[] array = (byte[]) v;
                    message.setBytes(name, array, 0, array.length);
                } else {
                    message.setObject(name, v);
                }
            }
        } catch (final JMSException e) {
            throw new MessageFormatRuntimeException(e.getMessage());
        }
    }
    send(destination, message);
    return this;
}
 
源代码30 项目: tomee   文件: JMSProducerImpl.java
@Override
public JMSProducer send(final Destination destination, final byte[] body) {
    final BytesMessage message = wrap(context.createBytesMessage());
    if (body != null) {
        try {
            message.writeBytes(body);
        } catch (final JMSException e) {
            throw new MessageFormatRuntimeException(e.getMessage());
        }
    }
    send(destination, message);
    return this;
}
 
 类所在包
 类方法
 同包方法