Search in sources :

Example 6 with MessageFormatRuntimeException

use of javax.jms.MessageFormatRuntimeException in project activemq-artemis by apache.

the class ActiveMQJMSProducer method send.

@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;
}
Also used : CompletionListener(javax.jms.CompletionListener) JMSException(javax.jms.JMSException) MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException)

Example 7 with MessageFormatRuntimeException

use of javax.jms.MessageFormatRuntimeException in project activemq-artemis by apache.

the class ActiveMQJMSProducer method getObjectProperty.

@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());
    }
}
Also used : MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException) JMSRuntimeException(javax.jms.JMSRuntimeException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException) ActiveMQPropertyConversionException(org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException) JMSRuntimeException(javax.jms.JMSRuntimeException)

Example 8 with MessageFormatRuntimeException

use of javax.jms.MessageFormatRuntimeException in project activemq-artemis by apache.

the class JmsContextTest method testInvalidMessage.

@Test
public void testInvalidMessage() {
    JMSProducer producer = context.createProducer();
    try {
        producer.send(queue1, (Message) null);
        Assert.fail("null msg");
    } catch (MessageFormatRuntimeException expected) {
    // no-op
    }
}
Also used : JMSProducer(javax.jms.JMSProducer) MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException) Test(org.junit.Test)

Example 9 with MessageFormatRuntimeException

use of javax.jms.MessageFormatRuntimeException in project tomee by apache.

the class JMSProducerImpl method send.

@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;
}
Also used : MapMessage(javax.jms.MapMessage) JMSException(javax.jms.JMSException) MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with MessageFormatRuntimeException

use of javax.jms.MessageFormatRuntimeException in project tomee by apache.

the class JMSProducerImpl method send.

@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;
}
Also used : BytesMessage(javax.jms.BytesMessage) JMSException(javax.jms.JMSException) MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException)

Aggregations

MessageFormatRuntimeException (javax.jms.MessageFormatRuntimeException)10 JMSException (javax.jms.JMSException)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 Test (org.junit.Test)3 BytesMessage (javax.jms.BytesMessage)2 JMSProducer (javax.jms.JMSProducer)2 JMSRuntimeException (javax.jms.JMSRuntimeException)2 MapMessage (javax.jms.MapMessage)2 ActiveMQPropertyConversionException (org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 CompletionListener (javax.jms.CompletionListener)1 JMSContext (javax.jms.JMSContext)1 MessageFormatException (javax.jms.MessageFormatException)1