Java 类javax.jms.MessageNotWriteableException 实例源码

项目:activemq-artemis    文件:SimpleJMSMapMessage.java   
@Override
public void setBytes(final String name, final byte[] value, final int offset, final int length) throws JMSException {
   checkName(name);
   if (bodyReadOnly) {
      throw new MessageNotWriteableException("Message is ReadOnly !");
   }

   if (offset + length > value.length) {
      throw new JMSException("Array is too small");
   }
   byte[] temp = new byte[length];
   System.arraycopy(value, offset, temp, 0, length);

   content.put(name, temp);

}
项目:ffmq    文件:ObjectMessageImpl.java   
@Override
public void setObject(Serializable object) throws JMSException
   {
    if (bodyIsReadOnly)
        throw new MessageNotWriteableException("Message body is read-only");

    assertDeserializationLevel(MessageSerializationLevel.FULL);

       if (object == null)
       {
           body = null;
           return;
       }

       try
       {
        body = SerializationTools.toByteArray(object);
       }
       catch (Exception e)
       {
        throw new FFMQException("Cannot serialize object message body","MESSAGE_ERROR",e);
       }
   }
项目:andes    文件:BytesMessageTest.java   
public void testResetMakesReadble() throws Exception
{
    try
    {
        JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
        bm.writeInt(10);
        bm.reset();
        bm.writeInt(12);
        fail("expected exception did not occur");
    }
    catch (MessageNotWriteableException m)
    {
        // ok
    }
    catch (Exception e)
    {
        fail("expected MessageNotWriteableException, got " + e);
    }
}
项目:andes    文件:StreamMessageTest.java   
public void testResetMakesReadble() throws Exception
{
    try
    {
        JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage();
        bm.writeInt(10);
        bm.reset();
        bm.writeInt(12);
        fail("expected exception did not occur");
    }
    catch (MessageNotWriteableException m)
    {
        // ok
    }
    catch (Exception e)
    {
        fail("expected MessageNotWriteableException, 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    文件:JmsMapMessageTest.java   
/**
 * Test that we are not able to write to a received message without calling
 * {@link JmsMapMessage#clearBody()}
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testReceivedMessageIsReadOnlyAndThrowsMNWE() throws Exception {
    JmsMapMessageFacade facade = new JmsTestMapMessageFacade();
    String myKey1 = "key1";
    facade.put(myKey1, "value1");
    JmsMapMessage mapMessage = new JmsMapMessage(facade);
    mapMessage.onDispatch();

    try {
        mapMessage.setObject("name", "value");
        fail("expected exception to be thrown");
    } catch (MessageNotWriteableException mnwe) {
        // expected
    }
}
项目:qpid-jms    文件:JmsMessageTest.java   
@Test
public void testClearPropertiesClearsReadOnly() throws Exception {
    JmsMessage msg = factory.createMessage();
    msg.onDispatch();

    try {
        msg.setObjectProperty("test", "value");
        fail("should throw exception");
    } catch (MessageNotWriteableException e) {
        // Expected
    }

    assertTrue(msg.isReadOnlyProperties());

    msg.clearProperties();

    msg.setObjectProperty("test", "value");

    assertFalse(msg.isReadOnlyProperties());
}
项目:qpid-jms    文件:JmsObjectMessageTest.java   
/**
 * Test that attempting to write bytes to a received message (without calling {@link ObjectMessage#clearBody()} first)
 * causes a {@link MessageNotWriteableException} to be thrown due to being read-only.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testReceivedObjectMessageThrowsMessageNotWriteableExceptionOnSetObject() throws Exception {
    String content = "myStringContent";
    JmsObjectMessageFacade facade = new JmsTestObjectMessageFacade();
    facade.setObject(content);
    JmsObjectMessage objectMessage = new JmsObjectMessage(facade);
    objectMessage.onDispatch();

    try {
        objectMessage.setObject("newObject");
        fail("Expected exception to be thrown");
    } catch (MessageNotWriteableException mnwe) {
        // expected
    }
}
项目: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) {
    }
}
项目:org.ops4j.pax.transx    文件:Utils.java   
public static JMSRuntimeException convertToRuntimeException(JMSException e) {
    if (e instanceof javax.jms.IllegalStateException) {
        return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidClientIDException) {
        return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidDestinationException) {
        return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidSelectorException) {
        return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof JMSSecurityException) {
        return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof MessageFormatException) {
        return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof MessageNotWriteableException) {
        return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof ResourceAllocationException) {
        return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof TransactionInProgressException) {
        return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof TransactionRolledBackException) {
        return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
项目:spring4-understanding    文件:JmsMessagingTemplateTests.java   
@Test
public void convertMessageNotWritableException() throws JMSException {
    Message<String> message = createTextMessage();
    MessageConverter messageConverter = mock(MessageConverter.class);
    willThrow(MessageNotWriteableException.class).given(messageConverter).toMessage(eq(message), anyObject());
    messagingTemplate.setJmsMessageConverter(messageConverter);
    invokeMessageCreator("myQueue");

    thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
    messagingTemplate.send("myQueue", message);
}
项目:daq-eclipse    文件:ActiveMQStreamMessage.java   
private void initializeWriting() throws MessageNotWriteableException {
    checkReadOnlyBody();
    if (this.dataOut == null) {
        this.bytesOut = new ByteArrayOutputStream();
        OutputStream os = bytesOut;
        ActiveMQConnection connection = getConnection();
        if (connection != null && connection.isUseCompression()) {
            compressed = true;
            os = new DeflaterOutputStream(os);
        }
        this.dataOut = new DataOutputStream(os);
    }
}
项目:activemq-artemis    文件:BrokerNetworkWithStuckMessagesTest.java   
protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination) {
   ActiveMQTextMessage message = new ActiveMQTextMessage();
   message.setMessageId(new MessageId(producerInfo, ++msgIdGenerator));
   message.setDestination(destination);
   message.setPersistent(false);
   try {
      message.setText("Test Message Payload.");
   } catch (MessageNotWriteableException e) {
   }
   return message;
}
项目:activemq-artemis    文件:BrokerTestSupport.java   
protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination) {
   ActiveMQTextMessage message = new ActiveMQTextMessage();
   message.setMessageId(new MessageId(producerInfo, ++msgIdGenerator));
   message.setDestination(destination);
   message.setPersistent(false);
   try {
      message.setText("Test Message Payload.");
   } catch (MessageNotWriteableException e) {
   }
   return message;
}
项目:activemq-artemis    文件:UdpTestSupport.java   
protected void assertSendTextMessage(ActiveMQDestination destination,
                                     String text) throws MessageNotWriteableException {
   large = true;

   ActiveMQTextMessage expected = new ActiveMQTextMessage();

   expected.setText(text);
   expected.setDestination(destination);

   try {
      LOG.info("About to send message of type: " + expected.getClass());
      producer.oneway(expected);

      // lets send a dummy command to ensure things don't block if we
      // discard the last one
      // keepalive does not have a commandId...
      // producer.oneway(new KeepAliveInfo());
      producer.oneway(new ProducerInfo());
      producer.oneway(new ProducerInfo());

      Command received = assertCommandReceived();
      assertTrue("Should have received an ActiveMQTextMessage but was: " + received, received instanceof ActiveMQTextMessage);
      ActiveMQTextMessage actual = (ActiveMQTextMessage) received;

      assertEquals("getDestination", expected.getDestination(), actual.getDestination());
      assertEquals("getText", expected.getText(), actual.getText());

      LOG.info("Received text message with: " + actual.getText().length() + " character(s)");
   } catch (Exception e) {
      LOG.info("Caught: " + e);
      e.printStackTrace();
      fail("Failed to send to transport: " + e);
   }
}
项目:activemq-artemis    文件:FanoutTransportBrokerTest.java   
protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination) {
   ActiveMQTextMessage message = new ActiveMQTextMessage();
   message.setMessageId(new MessageId(producerInfo, ++msgIdGenerator));
   message.setDestination(destination);
   message.setPersistent(false);
   try {
      message.setText("Test Message Payload.");
   } catch (MessageNotWriteableException e) {
   }
   return message;
}
项目:activemq-artemis    文件:FailoverTransportBrokerTest.java   
protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination) {
   ActiveMQTextMessage message = new ActiveMQTextMessage();
   message.setMessageId(new MessageId(producerInfo, ++msgIdGenerator));
   message.setDestination(destination);
   message.setPersistent(false);
   try {
      message.setText("Test Message Payload.");
   } catch (MessageNotWriteableException e) {
   }
   return message;
}
项目: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    文件:ActiveMQObjectMessageTest.java   
public void testClearBody() throws JMSException {
   ActiveMQObjectMessage objectMessage = new ActiveMQObjectMessage();
   try {
      objectMessage.setObject("String");
      objectMessage.clearBody();
      assertFalse(objectMessage.isReadOnlyBody());
      assertNull(objectMessage.getObject());
      objectMessage.setObject("String");
      objectMessage.getObject();
   } catch (MessageNotWriteableException mnwe) {
      fail("should be writeable");
   }
}
项目:activemq-artemis    文件:ActiveMQMessageTest.java   
public void testSetReadOnly() {
   ActiveMQMessage msg = new ActiveMQMessage();
   msg.setReadOnlyProperties(true);
   boolean test = false;
   try {
      msg.setIntProperty("test", 1);
   } catch (MessageNotWriteableException me) {
      test = true;
   } catch (JMSException e) {
      e.printStackTrace(System.err);
      test = false;
   }
   assertTrue(test);
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeBoolean(final boolean value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }
   content.add(new Boolean(value));
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeByte(final byte value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }
   content.add(new Byte(value));
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeShort(final short value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }
   content.add(new Short(value));
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeChar(final char value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }
   content.add(new Character(value));
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeInt(final int value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }
   content.add(new Integer(value));
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeLong(final long value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }
   content.add(new Long(value));
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeFloat(final float value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }
   content.add(new Float(value));
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeDouble(final double value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }
   content.add(new Double(value));
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeString(final String value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }
   if (value == null) {
      content.add(null);
   } else {
      content.add(value);
   }
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeBytes(final byte[] value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }
   content.add(value.clone());
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeBytes(final byte[] value, final int offset, final int length) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }

   if (offset + length > value.length) {
      throw new JMSException("Array is too small");
   }
   byte[] temp = new byte[length];
   System.arraycopy(value, offset, temp, 0, length);

   content.add(temp);
}
项目:activemq-artemis    文件:SimpleJMSStreamMessage.java   
@Override
public void writeObject(final Object value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("The message body is readonly");
   }
   if (value == null) {
      content.add(null);
   } else if (value instanceof Boolean) {
      content.add(value);
   } else if (value instanceof Byte) {
      content.add(value);
   } else if (value instanceof Short) {
      content.add(value);
   } else if (value instanceof Character) {
      content.add(value);
   } else if (value instanceof Integer) {
      content.add(value);
   } else if (value instanceof Long) {
      content.add(value);
   } else if (value instanceof Float) {
      content.add(value);
   } else if (value instanceof Double) {
      content.add(value);
   } else if (value instanceof String) {
      content.add(value);
   } else if (value instanceof byte[]) {
      content.add(((byte[]) value).clone());
   } else {
      throw new MessageFormatException("Invalid object type");
   }
}
项目:activemq-artemis    文件:SimpleJMSBytesMessage.java   
@Override
public void writeBoolean(final boolean value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("the message body is read-only");
   }
   try {
      p.writeBoolean(value);
   } catch (IOException e) {
      throw new JMSException("IOException");
   }
}
项目:activemq-artemis    文件:SimpleJMSBytesMessage.java   
@Override
public void writeByte(final byte value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("the message body is read-only");
   }
   try {
      p.writeByte(value);
   } catch (IOException e) {
      throw new JMSException("IOException");
   }
}
项目:activemq-artemis    文件:SimpleJMSBytesMessage.java   
@Override
public void writeShort(final short value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("the message body is read-only");
   }
   try {
      p.writeShort(value);
   } catch (IOException e) {
      throw new JMSException("IOException");
   }
}
项目:activemq-artemis    文件:SimpleJMSBytesMessage.java   
@Override
public void writeChar(final char value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("the message body is read-only");
   }
   try {
      p.writeChar(value);
   } catch (IOException e) {
      throw new JMSException("IOException");
   }
}
项目:activemq-artemis    文件:SimpleJMSBytesMessage.java   
@Override
public void writeInt(final int value) throws JMSException {
   if (!bodyWriteOnly) {
      throw new MessageNotWriteableException("the message body is read-only");
   }
   try {
      p.writeInt(value);
   } catch (IOException e) {
      throw new JMSException("IOException");
   }
}