类javax.jms.MessageNotReadableException源码实例Demo

下面列出了怎么用javax.jms.MessageNotReadableException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: 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("");
   }
}
 
源代码2 项目: 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("");
   }
}
 
源代码3 项目: 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("");
   }
}
 
源代码4 项目: 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");
    }
}
 
源代码5 项目: 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) {
    }
}
 
源代码6 项目: 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
    }
}
 
源代码7 项目: 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.dequeueNoWait();
    assertEquals(9, envelope.getMessage().getJMSPriority());

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

    assertTrue(queue.isEmpty());
}
 
/**
 * 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);
}
 
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");
   }
}
 
源代码10 项目: 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) {
   }
}
 
源代码11 项目: 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("");
   }

}
 
源代码12 项目: 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("");
   }
}
 
源代码13 项目: 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("");
   }
}
 
源代码14 项目: 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("");
   }
}
 
源代码15 项目: 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("");
   }
}
 
源代码16 项目: 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("");
   }
}
 
源代码17 项目: 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
    }
}
 
源代码18 项目: 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);
}
 
源代码19 项目: 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;
}
 
/**
 * 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();
}
 
源代码21 项目: pooled-jms   文件: MockJMSMessage.java
protected void checkWriteOnlyBody() throws MessageNotReadableException {
    if (!readOnlyBody) {
        throw new MessageNotReadableException("Message body is write-only");
    }
}
 
源代码22 项目: 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("");
   }
}
 
源代码23 项目: 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("");
   }
}
 
源代码24 项目: activemq-artemis   文件: ActiveMQJMSClientBundle.java
@Message(id = 139014, value = "Message is write-only")
MessageNotReadableException messageNotReadable();
 
源代码25 项目: qpid-jms   文件: JmsMessage.java
protected void checkWriteOnlyBody() throws MessageNotReadableException {
    if (!readOnlyBody) {
        throw new MessageNotReadableException("Message body is write-only");
    }
}
 
void checkCanRead() throws JMSException {
    if (bytes == null) {
        throw new MessageNotReadableException("Message is not readable");
    }
}
 
源代码27 项目: qpid-jms   文件: JmsBytesMessageTest.java
/**
 * Test that attempting to call {@link BytesMessage#getBodyLength()} on a new message 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 testGetBodyLengthOnNewMessageThrowsMessageNotReadableException() throws Exception {
    JmsBytesMessage bytesMessage = factory.createBytesMessage();
    bytesMessage.getBodyLength();
}
 
 类所在包
 同包方法