Search in sources :

Example 16 with MessageEOFException

use of javax.jms.MessageEOFException in project rabbitmq-jms-client by rabbitmq.

the class RMQBytesMessage method readChar.

/**
 * {@inheritDoc}
 */
@Override
public char readChar() throws JMSException {
    if (!this.reading)
        throw new MessageNotReadableException(NOT_READABLE);
    if (this.pos + Bits.NUM_BYTES_IN_CHAR > this.buf.length)
        throw new MessageEOFException(MSG_EOF);
    char ch = Bits.getChar(this.buf, this.pos);
    this.pos += Bits.NUM_BYTES_IN_CHAR;
    return ch;
}
Also used : MessageEOFException(javax.jms.MessageEOFException) MessageNotReadableException(javax.jms.MessageNotReadableException)

Example 17 with MessageEOFException

use of javax.jms.MessageEOFException in project rabbitmq-jms-client by rabbitmq.

the class RMQBytesMessage method readDouble.

/**
 * {@inheritDoc}
 */
@Override
public double readDouble() throws JMSException {
    if (!this.reading)
        throw new MessageNotReadableException(NOT_READABLE);
    if (this.pos + Bits.NUM_BYTES_IN_DOUBLE > this.buf.length)
        throw new MessageEOFException(MSG_EOF);
    double dbl = Bits.getDouble(this.buf, this.pos);
    this.pos += Bits.NUM_BYTES_IN_DOUBLE;
    return dbl;
}
Also used : MessageEOFException(javax.jms.MessageEOFException) MessageNotReadableException(javax.jms.MessageNotReadableException)

Example 18 with MessageEOFException

use of javax.jms.MessageEOFException in project activemq-artemis by apache.

the class JMSMessageTest method testStreamMessage.

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)

Example 19 with MessageEOFException

use of javax.jms.MessageEOFException in project activemq-artemis by apache.

the class JMSMessageTest method testBytesMessage.

public void testBytesMessage() 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
    {
        BytesMessage message = session.createBytesMessage();
        message.writeBoolean(true);
        producer.send(message);
    }
    // Check the message
    {
        BytesMessage message = (BytesMessage) consumer.receive(1000);
        assertNotNull(message);
        assertTrue(message.readBoolean());
        try {
            message.readByte();
            fail("Expected exception not thrown.");
        } catch (MessageEOFException e) {
        }
    }
    assertNull(consumer.receiveNoWait());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageEOFException(javax.jms.MessageEOFException) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 20 with MessageEOFException

use of javax.jms.MessageEOFException in project activemq-artemis by apache.

the class ActiveMQStreamMessageTest method doReadTypeFromEmptyMessage.

// Private -------------------------------------------------------
private void doReadTypeFromEmptyMessage(final TypeReader reader) throws Exception {
    ActiveMQStreamMessage message = new ActiveMQStreamMessage();
    message.reset();
    try {
        reader.readType(message);
        Assert.fail("MessageEOFException");
    } catch (MessageEOFException e) {
    }
}
Also used : MessageEOFException(javax.jms.MessageEOFException) ActiveMQStreamMessage(org.apache.activemq.artemis.jms.client.ActiveMQStreamMessage)

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