Java Code Examples for org.apache.qpid.proton.message.impl.MessageImpl#setBody()
The following examples show how to use
org.apache.qpid.proton.message.impl.MessageImpl#setBody() .
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: TestConversions.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSimpleConversionText() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); MessageImpl message = (MessageImpl) Message.Factory.create(); message.setApplicationProperties(properties); String text = "someText"; message.setBody(new AmqpValue(text)); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); ICoreMessage serverMessage = encodedMessage.toCore(); ServerJMSTextMessage textMessage = (ServerJMSTextMessage) ServerJMSMessage.wrapCoreMessage(serverMessage); textMessage.decode(); verifyProperties(textMessage); assertEquals(text, textMessage.getText()); }
Example 2
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSimpleConversionWithExtraProperties() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); String text = "someText"; message.setBody(new AmqpValue(text)); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); TypedProperties extraProperties = createTypedPropertiesMap(); extraProperties.putBytesProperty(new SimpleString("bytesProp"), "value".getBytes()); encodedMessage.setExtraProperties(extraProperties); ICoreMessage serverMessage = encodedMessage.toCore(); ServerJMSTextMessage textMessage = (ServerJMSTextMessage) ServerJMSMessage.wrapCoreMessage(serverMessage); textMessage.decode(); verifyProperties(textMessage); assertEquals("value", new String(((byte[]) textMessage.getObjectProperty("bytesProp")))); assertEquals(text, textMessage.getText()); }
Example 3
Source File: AMQPPersisterTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private MessageImpl createProtonMessage(String address, byte[] content) { MessageImpl message = (MessageImpl) Proton.message(); Header header = new Header(); header.setDurable(true); header.setPriority(UnsignedByte.valueOf((byte) 9)); Properties properties = new Properties(); properties.setCreationTime(new Date(System.currentTimeMillis())); properties.setTo(address); properties.setMessageId(UUID.randomUUID()); MessageAnnotations annotations = new MessageAnnotations(new LinkedHashMap<>()); ApplicationProperties applicationProperties = new ApplicationProperties(new LinkedHashMap<>()); AmqpValue body = new AmqpValue(Arrays.copyOf(content, content.length)); message.setHeader(header); message.setMessageAnnotations(annotations); message.setProperties(properties); message.setApplicationProperties(applicationProperties); message.setBody(body); return message; }
Example 4
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testDeliveryCountSetFromMessageWithNonDefaultValue() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setDeliveryCount(2); message.setBody(new AmqpValue("test")); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass()); assertTrue(jmsMessage.getJMSRedelivered()); assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, jmsMessage.getFacade().getClass()); AmqpJmsTextMessageFacade facade = (AmqpJmsTextMessageFacade) jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertEquals(2, facade.getRedeliveryCount()); assertEquals(2, facade.getAmqpHeader().getDeliveryCount()); assertEquals(UnsignedInteger.valueOf(2), facade.getHeader().getDeliveryCount()); }
Example 5
Source File: JMSTransformationSpeedComparisonTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private MessageImpl createTypicalQpidJMSMessage() { Map<String, Object> applicationProperties = new HashMap<>(); Map<Symbol, Object> messageAnnotations = new HashMap<>(); applicationProperties.put("property-1", "string"); applicationProperties.put("property-2", 512); applicationProperties.put("property-3", true); messageAnnotations.put(Symbol.valueOf("x-opt-jms-msg-type"), 0); messageAnnotations.put(Symbol.valueOf("x-opt-jms-dest"), 0); MessageImpl message = (MessageImpl) Proton.message(); message.setAddress("queue://test-queue"); message.setDeliveryCount(1); message.setApplicationProperties(new ApplicationProperties(applicationProperties)); message.setMessageAnnotations(new MessageAnnotations(messageAnnotations)); message.setCreationTime(System.currentTimeMillis()); message.setContentType("text/plain"); message.setBody(new AmqpValue("String payload for AMQP message conversion performance testing.")); return message; }
Example 6
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void doTransformWithToTypeDestinationTypeAnnotationTestImpl(Object toTypeAnnotationValue, Class<? extends Destination> expectedClass) throws Exception { String toAddress = "toAddress"; MessageImpl message = (MessageImpl) Message.Factory.create(); message.setBody(new AmqpValue("myTextMessageContent")); message.setAddress(toAddress); if (toTypeAnnotationValue != null) { Map<Symbol, Object> map = new HashMap<>(); map.put(Symbol.valueOf("x-opt-to-type"), toTypeAnnotationValue); MessageAnnotations ma = new MessageAnnotations(map); message.setMessageAnnotations(ma); } javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage); }
Example 7
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetSendBufferWithoutDeliveryAnnotations() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); Header header = new Header(); header.setDeliveryCount(new UnsignedInteger(1)); protonMessage.setHeader(header); Properties properties = new Properties(); properties.setTo("someNiceLocal"); protonMessage.setProperties(properties); protonMessage.setBody(new AmqpValue("Sample payload")); DeliveryAnnotations deliveryAnnotations = new DeliveryAnnotations(new HashMap<>()); final String annotationKey = "annotationKey"; final String annotationValue = "annotationValue"; deliveryAnnotations.getValue().put(Symbol.getSymbol(annotationKey), annotationValue); protonMessage.setDeliveryAnnotations(deliveryAnnotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); ReadableBuffer sendBuffer = decoded.getSendBuffer(1); assertEquals(decoded.getEncodeSize(), sendBuffer.capacity()); AMQPStandardMessage msgFromSendBuffer = new AMQPStandardMessage(0, sendBuffer, null, null); assertEquals("someNiceLocal", msgFromSendBuffer.getAddress()); assertNull(msgFromSendBuffer.getDeliveryAnnotations()); // again with higher deliveryCount ReadableBuffer sendBuffer2 = decoded.getSendBuffer(5); assertEquals(decoded.getEncodeSize(), sendBuffer2.capacity()); AMQPStandardMessage msgFromSendBuffer2 = new AMQPStandardMessage(0, sendBuffer2, null, null); assertEquals("someNiceLocal", msgFromSendBuffer2.getAddress()); assertNull(msgFromSendBuffer2.getDeliveryAnnotations()); }
Example 8
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that a data body containing nothing, but with the content type set to * {@value AMQPMessageSupport#OCTET_STREAM_CONTENT_TYPE} results in a BytesMessage when not * otherwise annotated to indicate the type of JMS message it is. * * @throws Exception * if an error occurs during the test. */ @Test public void testCreateBytesMessageFromDataWithEmptyBinaryAndContentType() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); Binary binary = new Binary(new byte[0]); message.setBody(new Data(binary)); message.setContentType(AMQPMessageSupport.OCTET_STREAM_CONTENT_TYPE); AMQPStandardMessage amqp = encodeAndCreateAMQPMessage(message); javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(amqp.toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); }
Example 9
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that a message with an empty data body section, and with the content type set to an * unknown value results in a BytesMessage when not otherwise annotated to indicate the type * of JMS message it is. * * @throws Exception * if an error occurs during the test. */ @Test public void testCreateBytesMessageFromDataWithUnknownContentType() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); Binary binary = new Binary(new byte[0]); message.setBody(new Data(binary)); message.setContentType("unknown-content-type"); javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); }
Example 10
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void doCreateTextMessageFromDataWithContentTypeTestImpl(String contentType, Charset expectedCharset) throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); Binary binary = new Binary(new byte[0]); message.setBody(new Data(binary)); message.setContentType(contentType); javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); if (StandardCharsets.UTF_8.equals(expectedCharset)) { assertEquals("Unexpected message class type", ServerJMSTextMessage.class, jmsMessage.getClass()); } else { assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); } }
Example 11
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that an amqp-value body containing a null results in an TextMessage when not * otherwise annotated to indicate the type of JMS message it is. * * @throws Exception * if an error occurs during the test. */ @Test public void testCreateTextMessageFromAmqpValueWithNull() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setBody(new AmqpValue(null)); javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSTextMessage.class, jmsMessage.getClass()); }
Example 12
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that a message with an AmqpValue section containing a Binary, but with the content * type set to {@value AMQPMessageSupport#SERIALIZED_JAVA_OBJECT_CONTENT_TYPE} results in an * ObjectMessage when not otherwise annotated to indicate the type of JMS message it is. * * @throws Exception * if an error occurs during the test. */ @Test public void testCreateObjectMessageFromAmqpValueWithBinaryAndContentType() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setBody(new AmqpValue(new Binary(new byte[0]))); message.setContentType(AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString()); javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSObjectMessage.class, jmsMessage.getClass()); }
Example 13
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that an amqp-value body containing a map results in an MapMessage when not otherwise * annotated to indicate the type of JMS message it is. * * @throws Exception * if an error occurs during the test. */ @Test public void testCreateAmqpMapMessageFromAmqpValueWithMap() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); Map<String, String> map = new HashMap<>(); message.setBody(new AmqpValue(map)); javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSMapMessage.class, jmsMessage.getClass()); }
Example 14
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that an amqp-value body containing a list results in an StreamMessage when not * otherwise annotated to indicate the type of JMS message it is. * * @throws Exception * if an error occurs during the test. */ @Test public void testCreateAmqpStreamMessageFromAmqpValueWithList() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); List<String> list = new ArrayList<>(); message.setBody(new AmqpValue(list)); javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSStreamMessage.class, jmsMessage.getClass()); }
Example 15
Source File: JMSMappingInboundTransformerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Test that an amqp-sequence body containing a list results in an StreamMessage when not * otherwise annotated to indicate the type of JMS message it is. * * @throws Exception * if an error occurs during the test. */ @Test public void testCreateAmqpStreamMessageFromAmqpSequence() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); List<String> list = new ArrayList<>(); message.setBody(new AmqpSequence(list)); javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSStreamMessage.class, jmsMessage.getClass()); }
Example 16
Source File: AmqpCodecTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testFirstAcquirerSetFromMessageWithNonDefaultValue() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setFirstAcquirer(true); message.setBody(new AmqpValue("test")); JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage(); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass()); assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, jmsMessage.getFacade().getClass()); AmqpJmsTextMessageFacade facade = (AmqpJmsTextMessageFacade) jmsMessage.getFacade(); assertNotNull("Facade should not be null", facade); assertTrue(facade.getAmqpHeader().isFirstAcquirer()); }
Example 17
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Test public void testConvertMessageWithMapInFooter() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); MessageImpl message = (MessageImpl) Message.Factory.create(); message.setApplicationProperties(properties); final String footerName = "test-footer"; final Symbol footerNameSymbol = Symbol.valueOf(footerName); Map<String, String> embeddedMap = new LinkedHashMap<>(); embeddedMap.put("key1", "value1"); embeddedMap.put("key2", "value2"); embeddedMap.put("key3", "value3"); Map<Symbol, Object> footerMap = new LinkedHashMap<>(); footerMap.put(footerNameSymbol, embeddedMap); Footer messageFooter = new Footer(footerMap); byte[] encodedEmbeddedMap = encodeObject(embeddedMap); Map<String, Object> mapValues = new HashMap<>(); mapValues.put("somestr", "value"); mapValues.put("someint", Integer.valueOf(1)); message.setFooter(messageFooter); message.setBody(new AmqpValue(mapValues)); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); ICoreMessage serverMessage = encodedMessage.toCore(); serverMessage.getReadOnlyBodyBuffer(); ServerJMSMapMessage mapMessage = (ServerJMSMapMessage) ServerJMSMessage.wrapCoreMessage(serverMessage); mapMessage.decode(); verifyProperties(mapMessage); assertEquals(1, mapMessage.getInt("someint")); assertEquals("value", mapMessage.getString("somestr")); assertTrue(mapMessage.propertyExists(JMS_AMQP_ENCODED_FOOTER_PREFIX + footerName)); assertArrayEquals(encodedEmbeddedMap, (byte[]) mapMessage.getObjectProperty(JMS_AMQP_ENCODED_FOOTER_PREFIX + footerName)); AMQPMessage newAMQP = CoreAmqpConverter.fromCore(mapMessage.getInnerMessage(), null); assertNotNull(newAMQP.getBody()); assertNotNull(newAMQP.getFooter()); assertNotNull(newAMQP.getFooter().getValue()); assertTrue(newAMQP.getFooter().getValue().containsKey(footerNameSymbol)); Object result = newAMQP.getFooter().getValue().get(footerNameSymbol); assertTrue(result instanceof Map); assertEquals(embeddedMap, (Map<String, String>) result); }
Example 18
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Test public void testConvertMessageWithMapInMessageAnnotations() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); MessageImpl message = (MessageImpl) Message.Factory.create(); message.setApplicationProperties(properties); final String annotationName = "x-opt-test-annotation"; final Symbol annotationNameSymbol = Symbol.valueOf(annotationName); Map<String, String> embeddedMap = new LinkedHashMap<>(); embeddedMap.put("key1", "value1"); embeddedMap.put("key2", "value2"); embeddedMap.put("key3", "value3"); Map<Symbol, Object> annotationsMap = new LinkedHashMap<>(); annotationsMap.put(annotationNameSymbol, embeddedMap); MessageAnnotations messageAnnotations = new MessageAnnotations(annotationsMap); byte[] encodedEmbeddedMap = encodeObject(embeddedMap); Map<String, Object> mapValues = new HashMap<>(); mapValues.put("somestr", "value"); mapValues.put("someint", Integer.valueOf(1)); message.setMessageAnnotations(messageAnnotations); message.setBody(new AmqpValue(mapValues)); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); ICoreMessage serverMessage = encodedMessage.toCore(); serverMessage.getReadOnlyBodyBuffer(); ServerJMSMapMessage mapMessage = (ServerJMSMapMessage) ServerJMSMessage.wrapCoreMessage(serverMessage); mapMessage.decode(); verifyProperties(mapMessage); assertEquals(1, mapMessage.getInt("someint")); assertEquals("value", mapMessage.getString("somestr")); assertTrue(mapMessage.propertyExists(JMS_AMQP_ENCODED_MESSAGE_ANNOTATION_PREFIX + annotationName)); assertArrayEquals(encodedEmbeddedMap, (byte[]) mapMessage.getObjectProperty(JMS_AMQP_ENCODED_MESSAGE_ANNOTATION_PREFIX + annotationName)); AMQPMessage newAMQP = CoreAmqpConverter.fromCore(mapMessage.getInnerMessage(), null); assertNotNull(newAMQP.getBody()); assertNotNull(newAMQP.getMessageAnnotations()); assertNotNull(newAMQP.getMessageAnnotations().getValue()); assertTrue(newAMQP.getMessageAnnotations().getValue().containsKey(annotationNameSymbol)); Object result = newAMQP.getMessageAnnotations().getValue().get(annotationNameSymbol); assertTrue(result instanceof Map); assertEquals(embeddedMap, (Map<String, String>) result); }
Example 19
Source File: MessageTransformationTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testComplexQpidJMSMessageEncodeDecode() throws Exception { Map<String, Object> applicationProperties = new HashMap<>(); Map<Symbol, Object> messageAnnotations = new HashMap<>(); applicationProperties.put("property-1", "string-1"); applicationProperties.put("property-2", 512); applicationProperties.put("property-3", true); applicationProperties.put("property-4", "string-2"); applicationProperties.put("property-5", 512); applicationProperties.put("property-6", true); applicationProperties.put("property-7", "string-3"); applicationProperties.put("property-8", 512); applicationProperties.put("property-9", true); messageAnnotations.put(Symbol.valueOf("x-opt-jms-msg-type"), 0); messageAnnotations.put(Symbol.valueOf("x-opt-jms-dest"), 0); messageAnnotations.put(Symbol.valueOf("x-opt-jms-reply-to"), 0); messageAnnotations.put(Symbol.valueOf("x-opt-delivery-delay"), 2000); MessageImpl message = (MessageImpl) Proton.message(); // Header Values message.setPriority((short) 9); message.setDurable(true); message.setDeliveryCount(2); message.setTtl(5000); // Properties message.setMessageId("ID:SomeQualifier:0:0:1"); message.setGroupId("Group-ID-1"); message.setGroupSequence(15); message.setAddress("queue://test-queue"); message.setReplyTo("queue://reply-queue"); message.setCreationTime(System.currentTimeMillis()); message.setContentType("text/plain"); message.setCorrelationId("ID:SomeQualifier:0:7:9"); message.setUserId("username".getBytes(StandardCharsets.UTF_8)); // Application Properties / Message Annotations / Body message.setApplicationProperties(new ApplicationProperties(applicationProperties)); message.setMessageAnnotations(new MessageAnnotations(messageAnnotations)); message.setBody(new AmqpValue("String payload for AMQP message conversion performance testing.")); ICoreMessage core = encodeAndCreateAMQPMessage(message).toCore(); AMQPMessage outboudMessage = AMQPConverter.getInstance().fromCore(core, null); assertEquals(10, outboudMessage.getApplicationProperties().getValue().size()); assertEquals(4, outboudMessage.getMessageAnnotations().getValue().size()); }
Example 20
Source File: TestConversions.java From activemq-artemis with Apache License 2.0 | 3 votes |
@Test public void testSimpleConversionBytes() throws Exception { Map<String, Object> mapprop = createPropertiesMap(); ApplicationProperties properties = new ApplicationProperties(mapprop); MessageImpl message = (MessageImpl) Message.Factory.create(); message.setApplicationProperties(properties); byte[] bodyBytes = new byte[4]; for (int i = 0; i < bodyBytes.length; i++) { bodyBytes[i] = (byte) 0xff; } message.setBody(new Data(new Binary(bodyBytes))); AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message); ICoreMessage serverMessage = encodedMessage.toCore(); ServerJMSBytesMessage bytesMessage = (ServerJMSBytesMessage) ServerJMSMessage.wrapCoreMessage(serverMessage); verifyProperties(bytesMessage); assertEquals(bodyBytes.length, bytesMessage.getBodyLength()); byte[] newBodyBytes = new byte[4]; bytesMessage.readBytes(newBodyBytes); Assert.assertArrayEquals(bodyBytes, newBodyBytes); }