javax.jms.MessageEOFException Java Examples

The following examples show how to use javax.jms.MessageEOFException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmqpJmsStreamMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testPopFullyReadListThrowsMEOFE() throws Exception {
    Message message = Message.Factory.create();
    List<Object> list = new ArrayList<Object>();
    list.add(Boolean.FALSE);
    message.setBody(new AmqpSequence(list));

    AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createReceivedStreamMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();

    try {
        amqpStreamMessageFacade.pop();
        fail("expected exception to be thrown");
    } catch (MessageEOFException meofe) {
        // expected
    }
}
 
Example #2
Source File: JmsStreamMessageTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testClearBodyOnNewMessageRemovesExistingValues() throws Exception {
    JmsStreamMessage streamMessage = factory.createStreamMessage();
    streamMessage.writeBoolean(true);

    streamMessage.clearBody();

    streamMessage.writeBoolean(false);
    streamMessage.reset();

    // check we get only the value added after the clear
    assertFalse("expected value added after the clear", streamMessage.readBoolean());

    try {
        streamMessage.readBoolean();
        fail("Expected exception to be thrown");
    } catch (MessageEOFException meofe) {
        // expected
    }
}
 
Example #3
Source File: SimpleJMSStreamMessage.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public float readFloat() throws JMSException {
   if (bodyWriteOnly) {
      throw new MessageNotReadableException("The message body is writeonly");
   }
   try {
      Object value = content.get(position);
      offset = 0;

      if (value == null) {
         throw new NullPointerException("Value is null");
      } else if (value instanceof Float) {
         position++;
         return ((Float) value).floatValue();
      } else if (value instanceof String) {
         float result = Float.parseFloat((String) value);
         position++;
         return result;
      } else {
         throw new MessageFormatException("Invalid conversion");
      }
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #4
Source File: SimpleJMSStreamMessage.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public char readChar() throws JMSException {
   if (bodyWriteOnly) {
      throw new MessageNotReadableException("The message body is writeonly");
   }
   try {
      Object value = content.get(position);
      offset = 0;

      if (value == null) {
         throw new NullPointerException("Value is null");
      } else if (value instanceof Character) {
         position++;
         return ((Character) value).charValue();
      } else {
         throw new MessageFormatException("Invalid conversion");
      }
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #5
Source File: SimpleJMSStreamMessage.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public byte readByte() throws JMSException {
   if (bodyWriteOnly) {
      throw new MessageNotReadableException("The message body is writeonly");
   }

   try {
      Object value = content.get(position);
      offset = 0;
      if (value == null) {
         throw new NullPointerException("Value is null");
      } else if (value instanceof Byte) {
         position++;
         return ((Byte) value).byteValue();
      } else if (value instanceof String) {
         byte result = Byte.parseByte((String) value);
         position++;
         return result;
      } else {
         throw new MessageFormatException("Invalid conversion");
      }
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #6
Source File: AmqpJmsStreamMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearBody() throws Exception {
    AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createNewStreamMessageFacade();

    // add some stuff
    amqpStreamMessageFacade.put(Boolean.TRUE);
    amqpStreamMessageFacade.put(Boolean.FALSE);

    // retrieve only some of it, leaving some unread
    assertEquals("unexpected value", Boolean.TRUE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();

    // clear
    amqpStreamMessageFacade.clearBody();

    // add something else
    amqpStreamMessageFacade.put(Character.valueOf('c'));

    // check we can get it alone before another IOOBE (i.e position was reset, other contents cleared)
    assertEquals("unexpected value", Character.valueOf('c'), amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();

    try {
        amqpStreamMessageFacade.peek();
        fail("expected exception to be thrown");
    } catch (MessageEOFException meofe) {
        // expected
    }
}
 
Example #7
Source File: AmqpJmsStreamMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testResetPositionAfterPeekThrowsMEOFE() throws Exception {
    Message message = Message.Factory.create();
    List<Object> list = new ArrayList<Object>();
    list.add(Boolean.FALSE);
    list.add(Boolean.TRUE);
    message.setBody(new AmqpSequence(list));

    AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createReceivedStreamMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();
    assertEquals("Unexpected value retrieved", Boolean.TRUE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();

    try {
        amqpStreamMessageFacade.peek();
        fail("expected exception to be thrown");
    } catch (MessageEOFException meofe) {
        // expected
    }

    amqpStreamMessageFacade.reset();

    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();
    assertEquals("Unexpected value retrieved", Boolean.TRUE, amqpStreamMessageFacade.peek());
}
 
Example #8
Source File: JmsTestStreamMessageFacade.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
public void pop() throws MessageEOFException {
    if (stream.isEmpty() || index + 1 >= stream.size()) {
        throw new MessageEOFException("Attempted to read past the end of the stream");
    }

    index++;
}
 
Example #9
Source File: JmsTestStreamMessageFacade.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
public Object peek() throws MessageEOFException {
    if (stream.isEmpty() || index + 1 >= stream.size()) {
        throw new MessageEOFException("Attempted to read past the end of the stream");
    }

    return stream.get(index + 1);
}
 
Example #10
Source File: SimpleJMSStreamMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public boolean readBoolean() throws JMSException {
   if (bodyWriteOnly) {
      throw new MessageNotReadableException("The message body is writeonly");
   }

   try {
      Object value = content.get(position);
      offset = 0;

      if (value == null) {
         throw new NullPointerException("Value is null");
      } else if (value instanceof Boolean) {
         position++;
         return ((Boolean) value).booleanValue();
      } else if (value instanceof String) {
         boolean result = Boolean.valueOf((String) value).booleanValue();
         position++;
         return result;
      } else {
         throw new MessageFormatException("Invalid conversion");
      }
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }

}
 
Example #11
Source File: JmsStreamMessageTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadWithEmptyStreamThrowsMEOFE() throws Exception {
    JmsStreamMessage streamMessage = factory.createStreamMessage();
    streamMessage.reset();

    try {
        streamMessage.readBoolean();
        fail("Expected exception to be thrown as message has no content");
    } catch (MessageEOFException meofe) {
        // expected
    }
}
 
Example #12
Source File: JmsMessageTransformationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void tesAbnormalForeignStreamMessageTransformCreateNewMessage() throws JMSException {
    ForeignJmsStreamMessage foreignMessage = new ForeignJmsStreamMessage();
    foreignMessage.writeObject(true);
    foreignMessage.reset();
    foreignMessage = Mockito.spy(foreignMessage);

    // Test for an odd StreamMessage that return null instead of throwing a MessageEOFException
    Mockito.when(foreignMessage.readObject()).thenReturn(true).
                                              thenReturn(false).
                                              thenReturn(true).
                                              thenReturn(null);

    JmsMessage transformed = JmsMessageTransformation.transformMessage(createMockJmsConnection(), foreignMessage);
    assertNotSame(foreignMessage, transformed);
    assertFalse(transformed.equals(foreignMessage));

    assertTrue(transformed instanceof JmsStreamMessage);
    JmsStreamMessage message = (JmsStreamMessage) transformed;
    message.reset();

    assertTrue(message.readBoolean());
    assertFalse(message.readBoolean());
    assertTrue(message.readBoolean());
    try {
        message.readBoolean();
    } catch (MessageEOFException ex) {}
}
 
Example #13
Source File: JmsMessageTransformationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyForeignStreamMessageTransformCreateNewMessage() throws JMSException {
    ForeignJmsStreamMessage foreignMessage = new ForeignJmsStreamMessage();

    JmsMessage transformed = JmsMessageTransformation.transformMessage(createMockJmsConnection(), foreignMessage);
    assertNotSame(foreignMessage, transformed);
    assertFalse(transformed.equals(foreignMessage));

    assertTrue(transformed instanceof JmsStreamMessage);
    JmsStreamMessage message = (JmsStreamMessage) transformed;
    message.reset();
    try {
        message.readBoolean();
    } catch (MessageEOFException ex) {}
}
 
Example #14
Source File: AmqpJmsStreamMessageFacade.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
public void pop() throws MessageEOFException {
    if (list.isEmpty() || position >= list.size()) {
        throw new MessageEOFException("Attempt to read past end of stream");
    }

    position++;
}
 
Example #15
Source File: AmqpJmsStreamMessageFacade.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
public Object peek() throws MessageEOFException {
    if (list.isEmpty() || position >= list.size()) {
        throw new MessageEOFException("Attempt to read past end of stream");
    }

    Object object = list.get(position);
    if (object instanceof Binary) {
        // Copy to a byte[], ensure we copy only the required portion.
        Binary bin = ((Binary) object);
        object = Arrays.copyOfRange(bin.getArray(), bin.getArrayOffset(), bin.getLength());
    }

    return object;
}
 
Example #16
Source File: ActiveMQBytesMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public double readDouble() throws JMSException {
   checkRead();
   try {
      return bytesReadDouble(message.getBodyBuffer());
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #17
Source File: ActiveMQBytesMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public float readFloat() throws JMSException {
   checkRead();
   try {
      return bytesReadFloat(message.getBodyBuffer());
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #18
Source File: ActiveMQBytesMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public long readLong() throws JMSException {
   checkRead();
   try {
      return bytesReadLong(message.getBodyBuffer());
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #19
Source File: ActiveMQBytesMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public int readInt() throws JMSException {
   checkRead();
   try {
      return bytesReadInt(message.getBodyBuffer());
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #20
Source File: ActiveMQBytesMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public int readUnsignedShort() throws JMSException {
   checkRead();
   try {
      return bytesReadUnsignedShort(message.getBodyBuffer());
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #21
Source File: SimpleJMSStreamMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public short readShort() throws JMSException {
   if (bodyWriteOnly) {
      throw new MessageNotReadableException("The message body is writeonly");
   }
   try {
      Object value = content.get(position);
      offset = 0;

      if (value == null) {
         throw new NullPointerException("Value is null");
      } else if (value instanceof Byte) {
         position++;
         return ((Byte) value).shortValue();
      } else if (value instanceof Short) {
         position++;
         return ((Short) value).shortValue();
      } else if (value instanceof String) {
         short result = Short.parseShort((String) value);
         position++;
         return result;
      } else {
         throw new MessageFormatException("Invalid conversion");
      }
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #22
Source File: SimpleJMSStreamMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public int readInt() throws JMSException {
   if (bodyWriteOnly) {
      throw new MessageNotReadableException("The message body is writeonly");
   }
   try {
      Object value = content.get(position);
      offset = 0;

      if (value == null) {
         throw new NullPointerException("Value is null");
      } else if (value instanceof Byte) {
         position++;
         return ((Byte) value).intValue();
      } else if (value instanceof Short) {
         position++;
         return ((Short) value).intValue();
      } else if (value instanceof Integer) {
         position++;
         return ((Integer) value).intValue();
      } else if (value instanceof String) {
         int result = Integer.parseInt((String) value);
         position++;
         return result;
      } else {
         throw new MessageFormatException("Invalid conversion");
      }
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #23
Source File: SimpleJMSStreamMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public long readLong() throws JMSException {
   if (bodyWriteOnly) {
      throw new MessageNotReadableException("The message body is writeonly");
   }
   try {
      Object value = content.get(position);
      offset = 0;

      if (value == null) {
         throw new NullPointerException("Value is null");
      } else if (value instanceof Byte) {
         position++;
         return ((Byte) value).longValue();
      } else if (value instanceof Short) {
         position++;
         return ((Short) value).longValue();
      } else if (value instanceof Integer) {
         position++;
         return ((Integer) value).longValue();
      } else if (value instanceof Long) {
         position++;
         return ((Long) value).longValue();
      } else if (value instanceof String) {
         long result = Long.parseLong((String) value);
         position++;
         return result;
      } else {
         throw new MessageFormatException("Invalid conversion");
      }
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #24
Source File: SimpleJMSStreamMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public double readDouble() throws JMSException {
   if (bodyWriteOnly) {
      throw new MessageNotReadableException("The message body is writeonly");
   }
   try {
      Object value = content.get(position);
      offset = 0;

      if (value == null) {
         throw new NullPointerException("Value is null");
      } else if (value instanceof Float) {
         position++;
         return ((Float) value).doubleValue();
      } else if (value instanceof Double) {
         position++;
         return ((Double) value).doubleValue();
      } else if (value instanceof String) {
         double result = Double.parseDouble((String) value);
         position++;
         return result;
      } else {
         throw new MessageFormatException("Invalid conversion");
      }
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #25
Source File: SimpleJMSStreamMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@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("");
   }
}
 
Example #26
Source File: ActiveMQStreamMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void doReadTypeFromEmptyMessage(final TypeReader reader) throws Exception {
   ActiveMQStreamMessage message = new ActiveMQStreamMessage();
   message.reset();

   try {
      reader.readType(message);
      Assert.fail("MessageEOFException");
   } catch (MessageEOFException e) {
   }
}
 
Example #27
Source File: ActiveMQStreamMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public ActiveMQStreamMessage(final StreamMessage foreign, final ClientSession session) throws JMSException {
   super(foreign, ActiveMQStreamMessage.TYPE, session);

   foreign.reset();

   try {
      while (true) {
         Object obj = foreign.readObject();
         writeObject(obj);
      }
   } catch (MessageEOFException e) {
      // Ignore
   }
}
 
Example #28
Source File: ActiveMQBytesMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public boolean readBoolean() throws JMSException {
   checkRead();
   try {
      return bytesReadBoolean(message.getBodyBuffer());
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #29
Source File: ActiveMQBytesMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public byte readByte() throws JMSException {
   checkRead();
   try {
      return bytesReadByte(message.getBodyBuffer());
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
 
Example #30
Source File: ActiveMQBytesMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public int readUnsignedByte() throws JMSException {
   checkRead();
   try {
      return bytesReadUnsignedByte(message.getBodyBuffer());
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}