当前位置: 首页>>代码示例>>Java>>正文


Java MessageNotReadableException类代码示例

本文整理汇总了Java中javax.jms.MessageNotReadableException的典型用法代码示例。如果您正苦于以下问题:Java MessageNotReadableException类的具体用法?Java MessageNotReadableException怎么用?Java MessageNotReadableException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MessageNotReadableException类属于javax.jms包,在下文中一共展示了MessageNotReadableException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readByte

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
@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("");
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:26,代码来源:SimpleJMSStreamMessage.java

示例2: readChar

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
@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("");
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:22,代码来源:SimpleJMSStreamMessage.java

示例3: readFloat

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
@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("");
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:26,代码来源:SimpleJMSStreamMessage.java

示例4: send

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
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);
    }
}
 
开发者ID:wso2,项目名称:andes,代码行数:25,代码来源:BytesMessageTest.java

示例5: testNotReadableOnCreationWithNull

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:wso2,项目名称:andes,代码行数:22,代码来源:BytesMessageTest.java

示例6: testNotReadableOnCreationWithNull

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:wso2,项目名称:andes,代码行数:22,代码来源:StreamMessageTest.java

示例7: testClearBody

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
@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");
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:17,代码来源:JmsTextMessageTest.java

示例8: testReadOnlyBody

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
@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) {
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:17,代码来源:JmsTextMessageTest.java

示例9: testGetBodyLengthOnClearedReceivedMessageThrowsMessageNotReadableException

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
/**
 * 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
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:24,代码来源:JmsBytesMessageTest.java

示例10: testUnreadablePrioirtyIsStillEnqueued

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
@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());
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:23,代码来源:PriorityMessageQueueTest.java

示例11: testClearBody

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:27,代码来源:SQSBytesMessageTest.java

示例12: testClearBody

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
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");
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:16,代码来源:ActiveMQTextMessageTest.java

示例13: testReadOnlyBody

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
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) {
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:16,代码来源:ActiveMQTextMessageTest.java

示例14: readBoolean

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
@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("");
   }

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:28,代码来源:SimpleJMSStreamMessage.java

示例15: readShort

import javax.jms.MessageNotReadableException; //导入依赖的package包/类
@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("");
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:29,代码来源:SimpleJMSStreamMessage.java


注:本文中的javax.jms.MessageNotReadableException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。