javax.jms.MessageNotWriteableException Java Examples
The following examples show how to use
javax.jms.MessageNotWriteableException.
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: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
@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); }
Example #2
Source File: JmsObjectMessageTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * 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 } }
Example #3
Source File: JmsMessageTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@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()); }
Example #4
Source File: JmsMapMessageTest.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * 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 } }
Example #5
Source File: JmsTextMessageTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@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) { } }
Example #6
Source File: JmsTextMessageTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@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"); } }
Example #7
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setLong(final String name, final long value) throws JMSException { checkName(name); if (bodyReadOnly) { throw new MessageNotWriteableException("Message is ReadOnly !"); } content.put(name, new Long(value)); }
Example #8
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setString(final String name, final String value) throws JMSException { checkName(name); if (bodyReadOnly) { throw new MessageNotWriteableException("Message is ReadOnly !"); } content.put(name, value); }
Example #9
Source File: ActiveMQMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void checkProperty(final String name) throws JMSException { if (propertiesReadOnly) { if (name != null && name.equals(ActiveMQJMSConstants.JMS_ACTIVEMQ_INPUT_STREAM)) { throw new MessageNotWriteableException("You cannot set the Input Stream on received messages. Did you mean " + ActiveMQJMSConstants.JMS_ACTIVEMQ_OUTPUT_STREAM + " or " + ActiveMQJMSConstants.JMS_ACTIVEMQ_SAVE_STREAM + "?"); } else { throw ActiveMQJMSClientBundle.BUNDLE.messageNotWritable(); } } if (name == null) { throw ActiveMQJMSClientBundle.BUNDLE.nullArgumentNotAllowed("property"); } if (name.equals("")) { throw new IllegalArgumentException("The name of a property must not be an empty String."); } if (!isValidJavaIdentifier(name)) { throw ActiveMQJMSClientBundle.BUNDLE.invalidJavaIdentifier(name); } if (ActiveMQMessage.reservedIdentifiers.contains(name)) { throw new JMSRuntimeException("The property name '" + name + "' is reserved due to selector syntax."); } if (name.startsWith("JMS_ACTIVEMQ")) { throw new JMSRuntimeException("The property name '" + name + "' is illegal since it starts with JMS_ACTIVEMQ"); } }
Example #10
Source File: JMS2.java From tomee with Apache License 2.0 | 5 votes |
public static JMSRuntimeException toRuntimeException(final 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); }
Example #11
Source File: SQSBytesMessageTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 5 votes |
/** * Test after reset the message is read only mode */ @Test(expected = MessageNotWriteableException.class) public void testNotWriteable() throws JMSException { SQSBytesMessage msg = new SQSBytesMessage(); byte[] byteArray = new byte[] { 'a', 0, 34, 65 }; msg.writeBytes(byteArray); msg.reset(); assertEquals('a', msg.readByte()); msg.writeInt(10); }
Example #12
Source File: JmsObjectMessageTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testClearBody() throws JMSException { JmsObjectMessage objectMessage = factory.createObjectMessage(); try { objectMessage.setObject("String"); objectMessage.clearBody(); assertFalse(objectMessage.isReadOnlyBody()); assertNull(objectMessage.getObject()); objectMessage.setObject("String"); objectMessage.getObject(); } catch (MessageNotWriteableException mnwe) { fail("should be writeable"); } }
Example #13
Source File: JmsMessageTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testSetReadOnly() throws JMSException { JmsMessage msg = factory.createMessage(); 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); }
Example #14
Source File: JmsBytesMessageTest.java From qpid-jms with Apache License 2.0 | 5 votes |
/** * Test that attempting to write bytes to a received message (without calling {@link BytesMessage#clearBody()} first) * causes a {@link MessageNotWriteableException} to be thrown due to being read-only. * * @throws Exception if an error occurs during the test. */ @Test(expected = MessageNotWriteableException.class) public void testReceivedBytesMessageThrowsMessageNotWriteableExceptionOnWriteBytes() throws Exception { byte[] content = "myBytesData".getBytes(); JmsTestBytesMessageFacade facade = new JmsTestBytesMessageFacade(content); JmsBytesMessage bytesMessage = new JmsBytesMessage(facade); bytesMessage.onDispatch(); bytesMessage.writeBytes(content); }
Example #15
Source File: JmsMessagePropertyIntercepterTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testJMS_AMQP_ACK_TYPEWhenMessagePropertiesAreReadOnly() throws JMSException { JmsSession session = Mockito.mock(JmsSession.class); JmsAcknowledgeCallback callback = new JmsAcknowledgeCallback(session); callback.setAckType(RELEASED); JmsMessage message = Mockito.mock(JmsMapMessage.class); JmsMessageFacade facade = Mockito.mock(JmsMessageFacade.class); Mockito.when(message.getAcknowledgeCallback()).thenReturn(callback); Mockito.when(message.getFacade()).thenReturn(facade); Mockito.doThrow(MessageNotWriteableException.class).when(message).checkReadOnlyProperties(); assertTrue(JmsMessagePropertyIntercepter.propertyExists(message, JMS_AMQP_ACK_TYPE)); JmsMessagePropertyIntercepter.clearProperties(message, true); assertFalse(JmsMessagePropertyIntercepter.propertyExists(message, JMS_AMQP_ACK_TYPE)); }
Example #16
Source File: JmsMessagingTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void convertMessageNotWritableException() throws JMSException { Message<String> message = createTextMessage(); MessageConverter messageConverter = mock(MessageConverter.class); willThrow(MessageNotWriteableException.class).given(messageConverter).toMessage(eq(message), any()); this.messagingTemplate.setJmsMessageConverter(messageConverter); invokeMessageCreator(); this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class); this.messagingTemplate.send("myQueue", message); }
Example #17
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setDouble(final String name, final double value) throws JMSException { checkName(name); if (bodyReadOnly) { throw new MessageNotWriteableException("Message is ReadOnly !"); } content.put(name, new Double(value)); }
Example #18
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setBytes(final String name, final byte[] value) throws JMSException { checkName(name); if (bodyReadOnly) { throw new MessageNotWriteableException("Message is ReadOnly !"); } content.put(name, value.clone()); }
Example #19
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setInt(final String name, final int value) throws JMSException { checkName(name); if (bodyReadOnly) { throw new MessageNotWriteableException("Message is ReadOnly !"); } content.put(name, new Integer(value)); }
Example #20
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setChar(final String name, final char value) throws JMSException { checkName(name); if (bodyReadOnly) { throw new MessageNotWriteableException("Message is ReadOnly !"); } content.put(name, new Character(value)); }
Example #21
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setShort(final String name, final short value) throws JMSException { checkName(name); if (bodyReadOnly) { throw new MessageNotWriteableException("Message is ReadOnly !"); } content.put(name, new Short(value)); }
Example #22
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setByte(final String name, final byte value) throws JMSException { checkName(name); if (bodyReadOnly) { throw new MessageNotWriteableException("Message is ReadOnly !"); } content.put(name, new Byte(value)); }
Example #23
Source File: SimpleJMSMapMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void setBoolean(final String name, final boolean value) throws JMSException { checkName(name); if (bodyReadOnly) { throw new MessageNotWriteableException("Message is ReadOnly !"); } content.put(name, Boolean.valueOf(value)); }
Example #24
Source File: SimpleJMSBytesMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void writeObject(final Object value) throws JMSException { if (!bodyWriteOnly) { throw new MessageNotWriteableException("the message body is read-only"); } try { if (value == null) { throw new NullPointerException("Attempt to write a new value"); } if (value instanceof String) { p.writeUTF((String) value); } else if (value instanceof Boolean) { p.writeBoolean(((Boolean) value).booleanValue()); } else if (value instanceof Byte) { p.writeByte(((Byte) value).byteValue()); } else if (value instanceof Short) { p.writeShort(((Short) value).shortValue()); } else if (value instanceof Integer) { p.writeInt(((Integer) value).intValue()); } else if (value instanceof Long) { p.writeLong(((Long) value).longValue()); } else if (value instanceof Float) { p.writeFloat(((Float) value).floatValue()); } else if (value instanceof Double) { p.writeDouble(((Double) value).doubleValue()); } else if (value instanceof byte[]) { p.write((byte[]) value, 0, ((byte[]) value).length); } else { throw new MessageFormatException("Invalid object for properties"); } } catch (IOException e) { throw new JMSException("IOException"); } }
Example #25
Source File: SimpleJMSBytesMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void writeBytes(final byte[] value, final int offset, final int length) throws JMSException { if (!bodyWriteOnly) { throw new MessageNotWriteableException("the message body is read-only"); } try { p.write(value, offset, length); } catch (IOException e) { throw new JMSException("IOException"); } }
Example #26
Source File: SimpleJMSBytesMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void writeBytes(final byte[] value) throws JMSException { if (!bodyWriteOnly) { throw new MessageNotWriteableException("the message body is read-only"); } try { p.write(value, 0, value.length); } catch (IOException e) { throw new JMSException("IOException"); } }
Example #27
Source File: SimpleJMSBytesMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void writeUTF(final String value) throws JMSException { if (!bodyWriteOnly) { throw new MessageNotWriteableException("the message body is read-only"); } try { p.writeUTF(value); } catch (IOException e) { throw new JMSException("IOException"); } }
Example #28
Source File: SimpleJMSBytesMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void writeDouble(final double value) throws JMSException { if (!bodyWriteOnly) { throw new MessageNotWriteableException("the message body is read-only"); } try { p.writeDouble(value); } catch (IOException e) { throw new JMSException("IOException"); } }
Example #29
Source File: SimpleJMSBytesMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void writeFloat(final float value) throws JMSException { if (!bodyWriteOnly) { throw new MessageNotWriteableException("the message body is read-only"); } try { p.writeFloat(value); } catch (IOException e) { throw new JMSException("IOException"); } }
Example #30
Source File: SimpleJMSBytesMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void writeLong(final long value) throws JMSException { if (!bodyWriteOnly) { throw new MessageNotWriteableException("the message body is read-only"); } try { p.writeLong(value); } catch (IOException e) { throw new JMSException("IOException"); } }