Search in sources :

Example 26 with MessageEOFException

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("");
    }
}
Also used : MessageEOFException(javax.jms.MessageEOFException) MessageNotReadableException(javax.jms.MessageNotReadableException)

Example 27 with 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());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageEOFException(javax.jms.MessageEOFException) StreamMessage(javax.jms.StreamMessage) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) Test(org.junit.Test)

Example 28 with MessageEOFException

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;
}
Also used : MessageEOFException(javax.jms.MessageEOFException) ArrayList(java.util.ArrayList) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) Data(org.apache.qpid.proton.amqp.messaging.Data) Section(org.apache.qpid.proton.amqp.messaging.Section) AmqpSequence(org.apache.qpid.proton.amqp.messaging.AmqpSequence) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) Binary(org.apache.qpid.proton.amqp.Binary) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage)

Example 29 with MessageEOFException

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("");
    }
}
Also used : StreamMessageUtil.streamReadInteger(org.apache.activemq.artemis.reader.StreamMessageUtil.streamReadInteger) MessageFormatException(javax.jms.MessageFormatException) MessageEOFException(javax.jms.MessageEOFException)

Example 30 with 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();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageEOFException(javax.jms.MessageEOFException) Connection(javax.jms.Connection) StreamMessage(javax.jms.StreamMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

MessageEOFException (javax.jms.MessageEOFException)35 MessageNotReadableException (javax.jms.MessageNotReadableException)21 MessageFormatException (javax.jms.MessageFormatException)16 MessageConsumer (javax.jms.MessageConsumer)7 MessageProducer (javax.jms.MessageProducer)7 Session (javax.jms.Session)6 StreamMessage (javax.jms.StreamMessage)6 Test (org.junit.Test)6 BytesMessage (javax.jms.BytesMessage)5 JMSException (javax.jms.JMSException)4 MessageNotWriteableException (javax.jms.MessageNotWriteableException)4 ArrayList (java.util.ArrayList)3 RMQJMSException (com.rabbitmq.jms.util.RMQJMSException)2 EOFException (java.io.EOFException)2 HashMap (java.util.HashMap)2 Connection (javax.jms.Connection)2 MapMessage (javax.jms.MapMessage)2 Message (javax.jms.Message)2 Queue (javax.jms.Queue)2 StreamMessageUtil.streamReadInteger (org.apache.activemq.artemis.reader.StreamMessageUtil.streamReadInteger)2