use of javax.jms.MessageEOFException in project activemq-artemis by apache.
the class SimpleJMSStreamMessage method readObject.
@Override
public Object readObject() throws JMSException {
if (bodyWriteOnly) {
throw new MessageNotReadableException("The message body is writeonly");
}
try {
Object value = content.get(position);
position++;
offset = 0;
return value;
} catch (IndexOutOfBoundsException e) {
throw new MessageEOFException("");
}
}
use of javax.jms.MessageEOFException in project activemq-artemis by apache.
the class JMSMessageTest method testStreamMessage.
@Test
public void testStreamMessage() throws Exception {
// Receive a message with the JMS API
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination);
MessageProducer producer = session.createProducer(destination);
// Send the message.
{
StreamMessage message = session.createStreamMessage();
message.writeString("This is a test to see how it works.");
producer.send(message);
}
// Check the message.
{
StreamMessage message = (StreamMessage) consumer.receive(1000);
assertNotNull(message);
// position.
try {
message.readByte();
fail("Should have received NumberFormatException");
} catch (NumberFormatException e) {
}
assertEquals("This is a test to see how it works.", message.readString());
// position.
try {
message.readByte();
fail("Should have received MessageEOFException");
} catch (MessageEOFException e) {
}
}
assertNull(consumer.receiveNoWait());
}
use of javax.jms.MessageEOFException in project activemq-artemis by apache.
the class CoreAmqpConverter method convertBody.
private static Section convertBody(ServerJMSMessage message, Map<Symbol, Object> maMap, Properties properties) throws JMSException {
Section body = null;
if (message instanceof ServerJMSBytesMessage) {
Binary payload = getBinaryFromMessageBody((ServerJMSBytesMessage) message);
maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_BYTES_MESSAGE);
if (payload == null) {
payload = EMPTY_BINARY;
} else {
body = new AmqpValue(payload);
}
} else if (message instanceof ServerJMSTextMessage) {
body = new AmqpValue(((TextMessage) message).getText());
maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_TEXT_MESSAGE);
} else if (message instanceof ServerJMSMapMessage) {
body = new AmqpValue(getMapFromMessageBody((ServerJMSMapMessage) message));
maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_MAP_MESSAGE);
} else if (message instanceof ServerJMSStreamMessage) {
maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_STREAM_MESSAGE);
ArrayList<Object> list = new ArrayList<>();
final ServerJMSStreamMessage m = (ServerJMSStreamMessage) message;
try {
while (true) {
list.add(m.readObject());
}
} catch (MessageEOFException e) {
}
body = new AmqpSequence(list);
} else if (message instanceof ServerJMSObjectMessage) {
properties.setContentType(AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE);
maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_OBJECT_MESSAGE);
Binary payload = getBinaryFromMessageBody((ServerJMSObjectMessage) message);
if (payload == null) {
payload = EMPTY_BINARY;
}
body = new Data(payload);
// we are sending it.
if (!message.propertyExists(JMS_AMQP_CONTENT_TYPE)) {
message.setStringProperty(JMS_AMQP_CONTENT_TYPE, SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString());
}
} else if (message instanceof ServerJMSMessage) {
maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_MESSAGE);
// If this is not an AMQP message that was converted then the original encoding
// will be unknown so we check for special cases of messages with special data
// encoded into the server message body.
ICoreMessage internalMessage = message.getInnerMessage();
int readerIndex = internalMessage.getBodyBuffer().readerIndex();
try {
Object s = internalMessage.getBodyBuffer().readNullableSimpleString();
if (s != null) {
body = new AmqpValue(s.toString());
}
} catch (Throwable ignored) {
logger.debug("Exception ignored during conversion", ignored.getMessage(), ignored);
body = new AmqpValue("Conversion to AMQP error!");
} finally {
internalMessage.getBodyBuffer().readerIndex(readerIndex);
}
}
return body;
}
use of javax.jms.MessageEOFException in project activemq-artemis by apache.
the class ServerJMSStreamMessage method readBytes.
@Override
public int readBytes(final byte[] value) throws JMSException {
try {
Pair<Integer, Integer> pairRead = streamReadBytes(getReadBodyBuffer(), len, value);
len = pairRead.getA();
return pairRead.getB();
} catch (IllegalStateException e) {
throw new MessageFormatException(e.getMessage());
} catch (IndexOutOfBoundsException e) {
throw new MessageEOFException("");
}
}
use of javax.jms.MessageEOFException in project activemq-artemis by apache.
the class MessageTest method testStreamMessageReadsNull.
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
/**
* @see https://jira.jboss.org/jira/browse/HORNETQ-242
*/
@Test
public void testStreamMessageReadsNull() throws Exception {
Connection conn = cf.createConnection();
try {
Queue queue = createQueue("testQueue");
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(queue);
MessageConsumer cons = sess.createConsumer(queue);
conn.start();
StreamMessage msg = sess.createStreamMessage();
msg.writeInt(1);
msg.writeInt(2);
msg.writeInt(3);
StreamMessage received = (StreamMessage) sendAndConsumeMessage(msg, prod, cons);
Assert.assertNotNull(received);
assertEquals(1, received.readObject());
assertEquals(2, received.readObject());
assertEquals(3, received.readObject());
try {
received.readObject();
fail("Should throw exception");
} catch (MessageEOFException e) {
// Ok
}
try {
received.readBoolean();
fail("Should throw exception");
} catch (MessageEOFException e) {
// Ok
}
try {
received.readByte();
fail("Should throw exception");
} catch (MessageEOFException e) {
// Ok
}
try {
received.readChar();
fail("Should throw exception");
} catch (MessageEOFException e) {
// Ok
}
try {
received.readDouble();
fail("Should throw exception");
} catch (MessageEOFException e) {
// Ok
}
try {
received.readFloat();
fail("Should throw exception");
} catch (MessageEOFException e) {
// Ok
}
try {
received.readInt();
fail("Should throw exception");
} catch (MessageEOFException e) {
// Ok
}
try {
received.readLong();
fail("Should throw exception");
} catch (MessageEOFException e) {
// Ok
}
try {
received.readShort();
fail("Should throw exception");
} catch (MessageEOFException e) {
// Ok
}
try {
received.readString();
fail("Should throw exception");
} catch (MessageEOFException e) {
// Ok
}
} finally {
conn.close();
}
}
Aggregations