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;
}
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());
}
}
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
}
}
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;
}
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;
}
Aggregations