use of javax.jms.MessageNotWriteableException in project activemq-artemis by apache.
the class MessageHeaderTest method testProperties.
@Test
public void testProperties() throws Exception {
Message m1 = queueProducerSession.createMessage();
// Some arbitrary values
boolean myBool = true;
byte myByte = 13;
short myShort = 15321;
int myInt = 0x71ab6c80;
long myLong = 0x20bf1e3fb6fa31dfL;
float myFloat = Float.MAX_VALUE - 23465;
double myDouble = Double.MAX_VALUE - 72387633;
String myString = "abcdef&^*&!^ghijkl";
m1.setBooleanProperty("myBool", myBool);
m1.setByteProperty("myByte", myByte);
m1.setShortProperty("myShort", myShort);
m1.setIntProperty("myInt", myInt);
m1.setLongProperty("myLong", myLong);
m1.setFloatProperty("myFloat", myFloat);
m1.setDoubleProperty("myDouble", myDouble);
m1.setStringProperty("myString", myString);
m1.setObjectProperty("myBool", new Boolean(myBool));
m1.setObjectProperty("myByte", new Byte(myByte));
m1.setObjectProperty("myShort", new Short(myShort));
m1.setObjectProperty("myInt", new Integer(myInt));
m1.setObjectProperty("myLong", new Long(myLong));
m1.setObjectProperty("myFloat", new Float(myFloat));
m1.setObjectProperty("myDouble", new Double(myDouble));
m1.setObjectProperty("myString", myString);
try {
m1.setObjectProperty("myIllegal", new Object());
ProxyAssertSupport.fail();
} catch (javax.jms.MessageFormatException e) {
}
queueProducer.send(m1);
Message m2 = queueConsumer.receive(2000);
ProxyAssertSupport.assertNotNull(m2);
ProxyAssertSupport.assertEquals(myBool, m2.getBooleanProperty("myBool"));
ProxyAssertSupport.assertEquals(myByte, m2.getByteProperty("myByte"));
ProxyAssertSupport.assertEquals(myShort, m2.getShortProperty("myShort"));
ProxyAssertSupport.assertEquals(myInt, m2.getIntProperty("myInt"));
ProxyAssertSupport.assertEquals(myLong, m2.getLongProperty("myLong"));
ProxyAssertSupport.assertEquals(myFloat, m2.getFloatProperty("myFloat"), 0);
ProxyAssertSupport.assertEquals(myDouble, m2.getDoubleProperty("myDouble"), 0);
ProxyAssertSupport.assertEquals(myString, m2.getStringProperty("myString"));
// Properties should now be read-only
try {
m2.setBooleanProperty("myBool", myBool);
ProxyAssertSupport.fail();
} catch (MessageNotWriteableException e) {
}
try {
m2.setByteProperty("myByte", myByte);
ProxyAssertSupport.fail();
} catch (MessageNotWriteableException e) {
}
try {
m2.setShortProperty("myShort", myShort);
ProxyAssertSupport.fail();
} catch (MessageNotWriteableException e) {
}
try {
m2.setIntProperty("myInt", myInt);
ProxyAssertSupport.fail();
} catch (MessageNotWriteableException e) {
}
try {
m2.setLongProperty("myLong", myLong);
ProxyAssertSupport.fail();
} catch (MessageNotWriteableException e) {
}
try {
m2.setFloatProperty("myFloat", myFloat);
ProxyAssertSupport.fail();
} catch (MessageNotWriteableException e) {
}
try {
m2.setDoubleProperty("myDouble", myDouble);
ProxyAssertSupport.fail();
} catch (MessageNotWriteableException e) {
}
try {
m2.setStringProperty("myString", myString);
ProxyAssertSupport.fail();
} catch (MessageNotWriteableException e) {
}
ProxyAssertSupport.assertTrue(m2.propertyExists("myBool"));
ProxyAssertSupport.assertTrue(m2.propertyExists("myByte"));
ProxyAssertSupport.assertTrue(m2.propertyExists("myShort"));
ProxyAssertSupport.assertTrue(m2.propertyExists("myInt"));
ProxyAssertSupport.assertTrue(m2.propertyExists("myLong"));
ProxyAssertSupport.assertTrue(m2.propertyExists("myFloat"));
ProxyAssertSupport.assertTrue(m2.propertyExists("myDouble"));
ProxyAssertSupport.assertTrue(m2.propertyExists("myString"));
ProxyAssertSupport.assertFalse(m2.propertyExists("sausages"));
Set<String> propNames = new HashSet<>();
Enumeration en = m2.getPropertyNames();
while (en.hasMoreElements()) {
String propName = (String) en.nextElement();
propNames.add(propName);
}
ProxyAssertSupport.assertTrue(propNames.size() >= 9);
ProxyAssertSupport.assertTrue(propNames.contains("myBool"));
ProxyAssertSupport.assertTrue(propNames.contains("myByte"));
ProxyAssertSupport.assertTrue(propNames.contains("myShort"));
ProxyAssertSupport.assertTrue(propNames.contains("myInt"));
ProxyAssertSupport.assertTrue(propNames.contains("myLong"));
ProxyAssertSupport.assertTrue(propNames.contains("myFloat"));
ProxyAssertSupport.assertTrue(propNames.contains("myDouble"));
ProxyAssertSupport.assertTrue(propNames.contains("myString"));
// Check property conversions
// Boolean property can be read as String but not anything else
ProxyAssertSupport.assertEquals(String.valueOf(myBool), m2.getStringProperty("myBool"));
try {
m2.getByteProperty("myBool");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getShortProperty("myBool");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getIntProperty("myBool");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getLongProperty("myBool");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getFloatProperty("myBool");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getDoubleProperty("myBool");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
// byte property can be read as short, int, long or String
ProxyAssertSupport.assertEquals(myByte, m2.getShortProperty("myByte"));
ProxyAssertSupport.assertEquals(myByte, m2.getIntProperty("myByte"));
ProxyAssertSupport.assertEquals(myByte, m2.getLongProperty("myByte"));
ProxyAssertSupport.assertEquals(String.valueOf(myByte), m2.getStringProperty("myByte"));
try {
m2.getBooleanProperty("myByte");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getFloatProperty("myByte");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getDoubleProperty("myByte");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
// short property can be read as int, long or String
ProxyAssertSupport.assertEquals(myShort, m2.getIntProperty("myShort"));
ProxyAssertSupport.assertEquals(myShort, m2.getLongProperty("myShort"));
ProxyAssertSupport.assertEquals(String.valueOf(myShort), m2.getStringProperty("myShort"));
try {
m2.getByteProperty("myShort");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getBooleanProperty("myShort");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getFloatProperty("myShort");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getDoubleProperty("myShort");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
// int property can be read as long or String
ProxyAssertSupport.assertEquals(myInt, m2.getLongProperty("myInt"));
ProxyAssertSupport.assertEquals(String.valueOf(myInt), m2.getStringProperty("myInt"));
try {
m2.getShortProperty("myInt");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getByteProperty("myInt");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getBooleanProperty("myInt");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getFloatProperty("myInt");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getDoubleProperty("myInt");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
// long property can be read as String
ProxyAssertSupport.assertEquals(String.valueOf(myLong), m2.getStringProperty("myLong"));
try {
m2.getIntProperty("myLong");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getShortProperty("myLong");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getByteProperty("myLong");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getBooleanProperty("myLong");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getFloatProperty("myLong");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getDoubleProperty("myLong");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
// float property can be read as double or String
ProxyAssertSupport.assertEquals(String.valueOf(myFloat), m2.getStringProperty("myFloat"));
ProxyAssertSupport.assertEquals(myFloat, m2.getDoubleProperty("myFloat"), 0);
try {
m2.getIntProperty("myFloat");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getShortProperty("myFloat");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getLongProperty("myFloat");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getByteProperty("myFloat");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getBooleanProperty("myFloat");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
// double property can be read as String
ProxyAssertSupport.assertEquals(String.valueOf(myDouble), m2.getStringProperty("myDouble"));
try {
m2.getFloatProperty("myDouble");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getIntProperty("myDouble");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getShortProperty("myDouble");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getByteProperty("myDouble");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getBooleanProperty("myDouble");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
try {
m2.getFloatProperty("myDouble");
ProxyAssertSupport.fail();
} catch (MessageFormatException e) {
}
m2.clearProperties();
Enumeration en2 = m2.getPropertyNames();
ProxyAssertSupport.assertTrue(en2.hasMoreElements());
en2.nextElement();
ProxyAssertSupport.assertFalse(en2.hasMoreElements());
// Test String -> Numeric and bool conversions
Message m3 = queueProducerSession.createMessage();
m3.setStringProperty("myBool", String.valueOf(myBool));
m3.setStringProperty("myByte", String.valueOf(myByte));
m3.setStringProperty("myShort", String.valueOf(myShort));
m3.setStringProperty("myInt", String.valueOf(myInt));
m3.setStringProperty("myLong", String.valueOf(myLong));
m3.setStringProperty("myFloat", String.valueOf(myFloat));
m3.setStringProperty("myDouble", String.valueOf(myDouble));
m3.setStringProperty("myIllegal", "xyz123");
ProxyAssertSupport.assertEquals(myBool, m3.getBooleanProperty("myBool"));
ProxyAssertSupport.assertEquals(myByte, m3.getByteProperty("myByte"));
ProxyAssertSupport.assertEquals(myShort, m3.getShortProperty("myShort"));
ProxyAssertSupport.assertEquals(myInt, m3.getIntProperty("myInt"));
ProxyAssertSupport.assertEquals(myLong, m3.getLongProperty("myLong"));
ProxyAssertSupport.assertEquals(myFloat, m3.getFloatProperty("myFloat"), 0);
ProxyAssertSupport.assertEquals(myDouble, m3.getDoubleProperty("myDouble"), 0);
m3.getBooleanProperty("myIllegal");
try {
m3.getByteProperty("myIllegal");
ProxyAssertSupport.fail();
} catch (NumberFormatException e) {
}
try {
m3.getShortProperty("myIllegal");
ProxyAssertSupport.fail();
} catch (NumberFormatException e) {
}
try {
m3.getIntProperty("myIllegal");
ProxyAssertSupport.fail();
} catch (NumberFormatException e) {
}
try {
m3.getLongProperty("myIllegal");
ProxyAssertSupport.fail();
} catch (NumberFormatException e) {
}
try {
m3.getFloatProperty("myIllegal");
ProxyAssertSupport.fail();
} catch (NumberFormatException e) {
}
try {
m3.getDoubleProperty("myIllegal");
ProxyAssertSupport.fail();
} catch (NumberFormatException e) {
}
}
use of javax.jms.MessageNotWriteableException in project activemq-artemis by apache.
the class MessageBodyTest method testTextMessage.
@Test
public void testTextMessage() throws Exception {
TextMessage m = queueProducerSession.createTextMessage();
// Arbitrary string with some Chinese characters to make sure UTF encoding
// is ok
String myString = "wwiuhdiuwhdwuhdwuhduqwhdiuwhdiuhwed8u29837482787\uD5E2\uCAC7\uD2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
m.setText(myString);
queueProducer.send(m);
TextMessage m2 = (TextMessage) queueConsumer.receive(2000);
ProxyAssertSupport.assertEquals(myString, m2.getText());
m = queueProducerSession.createTextMessage(myString);
queueProducer.send(m);
m2 = (TextMessage) queueConsumer.receive(2000);
ProxyAssertSupport.assertEquals(myString, m2.getText());
try {
m2.setText("Should be read-only");
ProxyAssertSupport.fail();
} catch (MessageNotWriteableException e) {
}
m2.clearBody();
ProxyAssertSupport.assertNull(m2.getText());
m2.setText("Now it is read-write");
}
use of javax.jms.MessageNotWriteableException in project activemq-artemis by apache.
the class UdpTestSupport method assertSendTextMessage.
protected void assertSendTextMessage(ActiveMQDestination destination, String text) throws MessageNotWriteableException {
large = true;
ActiveMQTextMessage expected = new ActiveMQTextMessage();
expected.setText(text);
expected.setDestination(destination);
try {
LOG.info("About to send message of type: " + expected.getClass());
producer.oneway(expected);
// lets send a dummy command to ensure things don't block if we
// discard the last one
// keepalive does not have a commandId...
// producer.oneway(new KeepAliveInfo());
producer.oneway(new ProducerInfo());
producer.oneway(new ProducerInfo());
Command received = assertCommandReceived();
assertTrue("Should have received an ActiveMQTextMessage but was: " + received, received instanceof ActiveMQTextMessage);
ActiveMQTextMessage actual = (ActiveMQTextMessage) received;
assertEquals("getDestination", expected.getDestination(), actual.getDestination());
assertEquals("getText", expected.getText(), actual.getText());
LOG.info("Received text message with: " + actual.getText().length() + " character(s)");
} catch (Exception e) {
LOG.info("Caught: " + e);
e.printStackTrace();
fail("Failed to send to transport: " + e);
}
}
use of javax.jms.MessageNotWriteableException in project activemq-artemis by apache.
the class FanoutTransportBrokerTest method createMessage.
protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination) {
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setMessageId(new MessageId(producerInfo, ++msgIdGenerator));
message.setDestination(destination);
message.setPersistent(false);
try {
message.setText("Test Message Payload.");
} catch (MessageNotWriteableException e) {
}
return message;
}
Aggregations