use of javax.jms.MessageNotWriteableException in project qpid-broker-j by apache.
the class ObjectMessageTest method testClearBodyAndProperties.
@Test
public void testClearBodyAndProperties() throws Exception {
Queue queue = createQueue(getTestName());
Connection connection = getConnection();
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
A object = new A(1, "test");
ObjectMessage msg = session.createObjectMessage(object);
msg.setStringProperty("testProperty", "testValue");
MessageProducer producer = session.createProducer(queue);
producer.send(msg);
MessageConsumer consumer = session.createConsumer(queue);
connection.start();
Message receivedMessage = consumer.receive(getReceiveTimeout());
assertTrue("ObjectMessage should be received", receivedMessage instanceof ObjectMessage);
ObjectMessage objectMessage = (ObjectMessage) receivedMessage;
Object received = objectMessage.getObject();
assertTrue("Unexpected object type received", received instanceof A);
assertEquals("Unexpected object received", object, received);
assertEquals("Unexpected property value", "testValue", receivedMessage.getStringProperty("testProperty"));
try {
objectMessage.setObject("Test text");
fail("Message should not be writable");
} catch (MessageNotWriteableException e) {
// pass
}
objectMessage.clearBody();
try {
objectMessage.setObject("Test text");
} catch (MessageNotWriteableException e) {
fail("Message should be writable");
}
try {
objectMessage.setStringProperty("test", "test");
fail("Message should not be writable");
} catch (MessageNotWriteableException mnwe) {
// pass
}
objectMessage.clearProperties();
try {
objectMessage.setStringProperty("test", "test");
} catch (MessageNotWriteableException mnwe) {
fail("Message should be writable");
}
} finally {
connection.close();
}
}
use of javax.jms.MessageNotWriteableException in project qpid-broker-j by apache.
the class StreamMessageTest method testStreamMessageEOF.
@Test
public void testStreamMessageEOF() throws Exception {
Queue queue = createQueue(getTestName());
Connection consumerConnection = getConnection();
try {
Session consumerSession = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageConsumer consumer = consumerSession.createConsumer(queue);
Connection producerConnection = getConnection();
try {
Session producerSession = producerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageProducer producer = producerSession.createProducer(queue);
StreamMessage msg = producerSession.createStreamMessage();
msg.writeByte((byte) 42);
producer.send(msg);
consumerConnection.start();
Message receivedMessage = consumer.receive(getReceiveTimeout());
assertTrue(receivedMessage instanceof StreamMessage);
StreamMessage streamMessage = (StreamMessage) receivedMessage;
streamMessage.readByte();
try {
streamMessage.readByte();
fail("Expected exception not thrown");
} catch (Exception e) {
assertTrue("Expected MessageEOFException: " + e, e instanceof MessageEOFException);
}
try {
streamMessage.writeByte((byte) 42);
fail("Expected exception not thrown");
} catch (MessageNotWriteableException e) {
// pass
}
} finally {
producerConnection.close();
}
} finally {
consumerConnection.close();
}
}
use of javax.jms.MessageNotWriteableException in project rabbitmq-jms-client by rabbitmq.
the class RMQObjectMessage method setObject.
@Override
public void setObject(Serializable object) throws JMSException {
if (isReadonlyBody())
throw new MessageNotWriteableException("Message not writeable");
try {
if (object == null) {
buf = null;
} else {
/*
* We have to serialise the object now
*/
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(object);
out.flush();
buf = bout.toByteArray();
}
} catch (IOException x) {
throw new RMQJMSException(x);
}
}
use of javax.jms.MessageNotWriteableException in project activemq-artemis by apache.
the class BrokerTestSupport 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;
}
use of javax.jms.MessageNotWriteableException in project activemq-artemis by apache.
the class BrokerNetworkWithStuckMessagesTest 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