Java 类javax.jms.MessageNotReadableException 实例源码

项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@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("");
   }
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@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("");
   }
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@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("");
   }
}
项目:andes    文件:BytesMessageTest.java   
void send(int count) throws JMSException
{
    // create a publisher
    MessageProducer producer = _session.createProducer(_destination);
    for (int i = 0; i < count; i++)
    {
        BytesMessage msg = _session.createBytesMessage();

        try
        {
            msg.readFloat();
            Assert.fail("Message should not be readable");
        }
        catch (MessageNotReadableException mnwe)
        {
            // normal execution
        }

        byte[] data = ("Message " + i).getBytes();
        msg.writeBytes(data);
        messages.add(data);
        producer.send(msg);
    }
}
项目:andes    文件:BytesMessageTest.java   
/**
 * Tests that on creation a call to getBodyLength() throws an exception
 * if null was passed in during creation
 */
public void testNotReadableOnCreationWithNull() throws Exception
{
    try
    {
        JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
        bm.getBodyLength();
        fail("expected exception did not occur");
    }
    catch (MessageNotReadableException m)
    {
        // ok
    }
    catch (Exception e)
    {
        fail("expected MessageNotReadableException, got " + e);
    }
}
项目:andes    文件:StreamMessageTest.java   
/**
 * Tests that on creation a call to getBodyLength() throws an exception
 * if null was passed in during creation
 */
public void testNotReadableOnCreationWithNull() throws Exception
{
    try
    {
        JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage();
        bm.readByte();
        fail("expected exception did not occur");
    }
    catch (MessageNotReadableException m)
    {
        // ok
    }
    catch (Exception e)
    {
        fail("expected MessageNotReadableException, got " + e);
    }
}
项目:qpid-jms    文件:JmsTextMessageTest.java   
@Test
public void testClearBody() throws JMSException, IOException {
    JmsTextMessage textMessage = factory.createTextMessage();
    textMessage.setText("string");
    textMessage.clearBody();
    assertFalse(textMessage.isReadOnlyBody());
    assertNull(textMessage.getText());
    try {
        textMessage.setText("String");
        textMessage.getText();
    } catch (MessageNotWriteableException mnwe) {
        fail("should be writeable");
    } catch (MessageNotReadableException mnre) {
        fail("should be readable");
    }
}
项目:qpid-jms    文件:JmsTextMessageTest.java   
@Test
public void testReadOnlyBody() throws JMSException {
    JmsTextMessage textMessage = factory.createTextMessage();
    textMessage.setText("test");
    textMessage.setReadOnlyBody(true);
    try {
        textMessage.getText();
    } catch (MessageNotReadableException e) {
        fail("should be readable");
    }
    try {
        textMessage.setText("test");
        fail("should throw exception");
    } catch (MessageNotWriteableException mnwe) {
    }
}
项目:qpid-jms    文件:JmsBytesMessageTest.java   
/**
 * Test that attempting to call {@link BytesMessage#getBodyLength()} on a received message after calling
 * {@link BytesMessage#clearBody()} causes {@link MessageNotReadableException} to be thrown due to being write-only.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testGetBodyLengthOnClearedReceivedMessageThrowsMessageNotReadableException() throws Exception {
    byte[] content = "myBytesData".getBytes();
    JmsTestBytesMessageFacade facade = new JmsTestBytesMessageFacade(content);

    JmsBytesMessage bytesMessage = new JmsBytesMessage(facade);
    bytesMessage.onDispatch();
    assertEquals("Unexpected message length", content.length, bytesMessage.getBodyLength());
    bytesMessage.clearBody();

    try {
        bytesMessage.getBodyLength();
        fail("expected exception to be thrown");
    } catch (MessageNotReadableException mnre) {
        // expected
    }
}
项目:qpid-jms    文件:PriorityMessageQueueTest.java   
@Test
public void testUnreadablePrioirtyIsStillEnqueued() throws JMSException {
    JmsInboundMessageDispatch message = createEnvelopeWithMessageThatCannotReadPriority();
    queue.enqueue(createEnvelope(9));
    queue.enqueue(message);
    queue.enqueue(createEnvelope(1));

    JmsInboundMessageDispatch envelope = queue.peek();
    assertEquals(9, envelope.getMessage().getJMSPriority());
    queue.dequeueNoWait();
    envelope = queue.peek();
    try {
        envelope.getMessage().getJMSPriority();
        fail("Unreadable priority message should sit at default level");
    } catch (MessageNotReadableException mnre) {}
    queue.dequeueNoWait();
    envelope = queue.peek();
    assertEquals(1, envelope.getMessage().getJMSPriority());
    queue.dequeueNoWait();

    assertTrue(queue.isEmpty());
}
项目:hawtjms    文件:JmsTextMessageTest.java   
@Test
public void testClearBody() throws JMSException, IOException {
    JmsTextMessage textMessage = factory.createTextMessage();
    textMessage.setText("string");
    textMessage.clearBody();
    assertFalse(textMessage.isReadOnlyBody());
    assertNull(textMessage.getText());
    try {
        textMessage.setText("String");
        textMessage.getText();
    } catch (MessageNotWriteableException mnwe) {
        fail("should be writeable");
    } catch (MessageNotReadableException mnre) {
        fail("should be readable");
    }
}
项目:hawtjms    文件:JmsTextMessageTest.java   
@Test
public void testReadOnlyBody() throws JMSException {
    JmsTextMessage textMessage = factory.createTextMessage();
    textMessage.setText("test");
    textMessage.setReadOnlyBody(true);
    try {
        textMessage.getText();
    } catch (MessageNotReadableException e) {
        fail("should be readable");
    }
    try {
        textMessage.setText("test");
        fail("should throw exception");
    } catch (MessageNotWriteableException mnwe) {
    }
}
项目:amazon-sqs-java-messaging-lib    文件:SQSBytesMessageTest.java   
/**
 * Test clear body
 */
@Test
public void testClearBody() throws JMSException, IOException {

    SQSBytesMessage msg = new SQSBytesMessage();

    byte[] byteArray = new byte[] { 1, 0, 'a', 65 };
    msg.writeBytes(byteArray);

    msg.clearBody();

    byte[] readByteArray = new byte[4];

    /*
     * Verify message is in write-only mode
     */
    try {
        msg.readBytes(readByteArray);
    } catch(MessageNotReadableException exception) {
        assertEquals("Message is not readable", exception.getMessage());
    }

    msg.writeBytes(byteArray);
}
项目:activemq-artemis    文件:ActiveMQTextMessageTest.java   
public void testClearBody() throws JMSException, IOException {
   ActiveMQTextMessage textMessage = new ActiveMQTextMessage();
   textMessage.setText("string");
   textMessage.clearBody();
   assertFalse(textMessage.isReadOnlyBody());
   assertNull(textMessage.getText());
   try {
      textMessage.setText("String");
      textMessage.getText();
   } catch (MessageNotWriteableException mnwe) {
      fail("should be writeable");
   } catch (MessageNotReadableException mnre) {
      fail("should be readable");
   }
}
项目:activemq-artemis    文件:ActiveMQTextMessageTest.java   
public void testReadOnlyBody() throws JMSException {
   ActiveMQTextMessage textMessage = new ActiveMQTextMessage();
   textMessage.setText("test");
   textMessage.setReadOnlyBody(true);
   try {
      textMessage.getText();
   } catch (MessageNotReadableException e) {
      fail("should be readable");
   }
   try {
      textMessage.setText("test");
      fail("should throw exception");
   } catch (MessageNotWriteableException mnwe) {
   }
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@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("");
   }

}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@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("");
   }
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@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("");
   }
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@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("");
   }
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@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("");
   }
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@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("");
   }
}
项目:activemq-artemis    文件:SimpleJMSBytesMessage.java   
/**
 * Check the message is readable
 *
 * @throws javax.jms.JMSException when not readable
 */
private void checkRead() throws JMSException {
   if (bodyWriteOnly) {
      throw new MessageNotReadableException("readByte while the buffer is writeonly");
   }

   // We have just received/reset() the message, and the client is trying to
   // read it
   if (istream == null || m == null) {
      istream = new ByteArrayInputStream(internalArray);
      m = new DataInputStream(istream);
   }
}
项目:ffmq    文件:StreamMessageImpl.java   
public Object internalReadObject() throws JMSException
{
    if (!bodyIsReadOnly)
        throw new MessageNotReadableException("Message body is write only");

    if (readPos >= body.size())
        throw new MessageEOFException("End of stream reached");

    if (currentByteInputStream != null)
        throw new MessageFormatException("Cannot read another object before the end of the byte array");

    return body.get(readPos++);
}
项目:ffmq    文件:BytesMessageImpl.java   
private DataInputStream getInput() throws JMSException
{
    if (!bodyIsReadOnly)
        throw new MessageNotReadableException("Message body is write-only");

    if (input == null)
    {
        inputBuf = new ByteArrayInputStream(body != null ? body : new byte[0]);
        input = new DataInputStream(inputBuf);
    }

    return input;
}
项目:ffmq    文件:BytesMessageImpl.java   
@Override
public long getBodyLength() throws JMSException
   {
       if (!bodyIsReadOnly)
           throw new MessageNotReadableException("Message body is write-only");

       return body != null ? body.length : 0;
   }
项目:andes    文件:AbstractJMSMessage.java   
protected void checkReadable() throws MessageNotReadableException
{
    if (!_readableMessage)
    {
        throw new MessageNotReadableException("You need to call reset() to make the message readable");
    }
}
项目:andes    文件:AbstractBytesTypedMessage.java   
protected byte readWireType() throws MessageFormatException, MessageEOFException,
        MessageNotReadableException
{
    checkReadable();
    checkAvailable(1);
    return _data.get();
}
项目:qpid-jms    文件:JmsStreamMessageTest.java   
@Test
public void testNewMessageIsWriteOnlyThrowsMNRE() throws Exception {
    JmsStreamMessage streamMessage = factory.createStreamMessage();

    try {
        streamMessage.readBoolean();
        fail("Expected exception to be thrown as message is not readable");
    } catch (MessageNotReadableException mnre) {
        // expected
    }
}
项目:qpid-jms    文件:JmsBytesMessageTest.java   
/**
 * Test that attempting to read bytes from a new message (without calling {@link BytesMessage#reset()} first) causes a
 * {@link MessageNotReadableException} to be thrown due to being write-only.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test(expected = MessageNotReadableException.class)
public void testNewBytesMessageThrowsMessageNotReadableOnReadBytes() throws Exception {
    JmsBytesMessage bytesMessage = factory.createBytesMessage();
    byte[] receivedBytes = new byte[1];
    bytesMessage.readBytes(receivedBytes);
}
项目:qpid-jms    文件:PriorityMessageQueueTest.java   
private JmsInboundMessageDispatch createEnvelopeWithMessageThatCannotReadPriority() throws JMSException {
    JmsInboundMessageDispatch envelope = new JmsInboundMessageDispatch(sequence++);

    JmsMessage message = Mockito.mock(JmsMessage.class);
    Mockito.when(message.getJMSPriority()).thenThrow(new MessageNotReadableException("Message is not readable"));

    envelope.setMessage(message);
    return envelope;
}
项目:hawtjms    文件:JmsStreamMessage.java   
private void initializeReading() throws MessageNotReadableException {
    checkWriteOnlyBody();
    if (stream == null) {
        stream = content;
        index = 0;
        bytes = null;
        remainingBytes = -1;
    }
}
项目:amazon-sqs-java-messaging-lib    文件:SQSBytesMessageTest.java   
/**
 * Test before reset the message is not readable
 */
@Test(expected = MessageNotReadableException.class)
public void testReadable() throws JMSException {
    when(mockSQSSession.createBytesMessage()).thenReturn(new SQSBytesMessage());
    SQSBytesMessage msg = (SQSBytesMessage) mockSQSSession.createBytesMessage(); 

    byte[] byteArray = new byte[] { 'a', 0, 34, 65 };
    msg.writeBytes(byteArray);

    msg.readInt();
}
项目:pooled-jms    文件:MockJMSMessage.java   
protected void checkWriteOnlyBody() throws MessageNotReadableException {
    if (!readOnlyBody) {
        throw new MessageNotReadableException("Message body is write-only");
    }
}
项目:daq-eclipse    文件:ActiveMQStreamMessage.java   
protected void checkWriteOnlyBody() throws MessageNotReadableException {
    if (!readOnlyBody) {
        throw new MessageNotReadableException("Message body is write-only");
    }
}
项目:daq-eclipse    文件:ActiveMQBytesMessage.java   
protected void checkWriteOnlyBody() throws MessageNotReadableException {
    if (!readOnlyBody) {
        throw new MessageNotReadableException("Message body is write-only");
    }
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public String readString() throws JMSException {
   if (bodyWriteOnly) {
      throw new MessageNotReadableException("The message body is writeonly");
   }
   try {
      Object value = content.get(position);
      offset = 0;

      if (value == null) {
         position++;
         return null;
      } else if (value instanceof Boolean) {
         position++;
         return ((Boolean) value).toString();
      } else if (value instanceof Byte) {
         position++;
         return ((Byte) value).toString();
      } else if (value instanceof Short) {
         position++;
         return ((Short) value).toString();
      } else if (value instanceof Character) {
         position++;
         return ((Character) value).toString();
      } else if (value instanceof Integer) {
         position++;
         return ((Integer) value).toString();
      } else if (value instanceof Long) {
         position++;
         return ((Long) value).toString();
      } else if (value instanceof Float) {
         position++;
         return ((Float) value).toString();
      } else if (value instanceof Double) {
         position++;
         return ((Double) value).toString();
      } else if (value instanceof String) {
         position++;
         return (String) value;
      } else {
         throw new MessageFormatException("Invalid conversion");
      }
   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public int readBytes(final byte[] value) throws JMSException {
   if (bodyWriteOnly) {
      throw new MessageNotReadableException("The message body is writeonly");
   }
   try {
      Object myObj = content.get(position);
      if (myObj == null) {
         throw new NullPointerException("Value is null");
      } else if (!(myObj instanceof byte[])) {
         throw new MessageFormatException("Invalid conversion");
      }
      byte[] obj = (byte[]) myObj;

      if (obj.length == 0) {
         position++;
         offset = 0;
         return 0;
      }

      if (offset >= obj.length) {
         position++;
         offset = 0;
         return -1;
      }

      if (obj.length - offset < value.length) {
         System.arraycopy(obj, offset, value, 0, obj.length);

         position++;
         offset = 0;

         return obj.length - offset;
      } else {
         System.arraycopy(obj, offset, value, 0, value.length);
         offset += value.length;

         return value.length;
      }

   } catch (IndexOutOfBoundsException e) {
      throw new MessageEOFException("");
   }
}
项目:activemq-artemis    文件:ActiveMQJMSClientBundle.java   
@Message(id = 129014, value = "Message is write-only")
MessageNotReadableException messageNotReadable();
项目:qpid-jms    文件:JmsMessage.java   
protected void checkWriteOnlyBody() throws MessageNotReadableException {
    if (!readOnlyBody) {
        throw new MessageNotReadableException("Message body is write-only");
    }
}
项目:hawtjms    文件:JmsStreamMessage.java   
protected void checkWriteOnlyBody() throws MessageNotReadableException {
    if (!readOnlyBody) {
        throw new MessageNotReadableException("Message body is write-only");
    }
}