org.apache.qpid.proton.amqp.messaging.Footer Java Examples

The following examples show how to use org.apache.qpid.proton.amqp.messaging.Footer. 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: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testGetFooter() {
   MessageImpl protonMessage = createProtonMessage();
   Footer footer = new Footer(new HashMap<>());
   footer.getValue().put(Symbol.valueOf(UUID.randomUUID().toString()), "test-1");
   protonMessage.setFooter(footer);

   AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null);

   Footer decoded = message.getFooter();
   assertNotSame(decoded, protonMessage.getFooter());
   assertFootersEquals(protonMessage.getFooter(), decoded);

   // Update the values
   decoded.getValue().put(Symbol.valueOf(UUID.randomUUID().toString()), "test-2");

   // Check that the message is unaffected.
   assertFootersNotEquals(protonMessage.getFooter(), decoded);
}
 
Example #2
Source File: Message.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static Message create(Header header,
                             DeliveryAnnotations deliveryAnnotations,
                             MessageAnnotations messageAnnotations,
                             Properties properties,
                             ApplicationProperties applicationProperties,
                             Section body,
                             Footer footer) {
    return new MessageImpl(header, deliveryAnnotations,
                           messageAnnotations, properties,
                           applicationProperties, body, footer);
}
 
Example #3
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeliveryAnnotationsReturnedOnNonEmptyFooterMapInMessage() throws Exception {
    AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();

    Map<Symbol, Object> footerMap = new HashMap<>();
    footerMap.put(Symbol.valueOf("test"), "value");
    amqpMessageFacade.setFooter(new Footer(footerMap));

    assertNotNull(amqpMessageFacade.getFooter());
}
 
Example #4
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoFooterReturnedOnEmptyFooterMapInMessage() throws Exception {
    AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();

    Map<Symbol, Object> footerMap = new HashMap<>();
    amqpMessageFacade.setFooter(new Footer(footerMap));

    assertNull(amqpMessageFacade.getFooter());
}
 
Example #5
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private boolean isEquals(Footer left, Footer right) {
   if (left == null && right == null) {
      return true;
   }
   if (!isNullnessEquals(left, right)) {
      return false;
   }

   return isEquals(left.getValue(), right.getValue());
}
 
Example #6
Source File: AmqpCoreConverter.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static ServerJMSMessage processFooter(ServerJMSMessage jms, Footer footer) throws Exception {
   if (footer != null && footer.getValue() != null) {
      for (Map.Entry<Symbol, Object> entry : (Set<Map.Entry<Symbol, Object>>) footer.getValue().entrySet()) {
         String key = entry.getKey().toString();
         try {
            setProperty(jms, JMS_AMQP_FOOTER_PREFIX + key, entry.getValue());
         } catch (ActiveMQPropertyConversionException e) {
            encodeUnsupportedMessagePropertyType(jms, JMS_AMQP_ENCODED_FOOTER_PREFIX + key, entry.getValue());
         }
      }
   }

   return jms;
}
 
Example #7
Source File: FastPathFooterType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Footer val) {
    WritableBuffer buffer = getEncoder().getBuffer();

    buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
    buffer.put(EncodingCodes.SMALLULONG);
    buffer.put(DESCRIPTOR_CODE);

    MapType mapType = (MapType) getEncoder().getType(val.getValue());

    mapType.write(val.getValue());
}
 
Example #8
Source File: Proton.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static Message message(Header header,
                  DeliveryAnnotations deliveryAnnotations, MessageAnnotations messageAnnotations,
                  Properties properties, ApplicationProperties applicationProperties,
                  Section body, Footer footer)
{
    return Message.Factory.create(header, deliveryAnnotations,
                                  messageAnnotations, properties,
                                  applicationProperties, body, footer);
}
 
Example #9
Source File: TestConversions.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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 #10
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test
public void testBasicMessageCopy() throws JMSException {
    AmqpJmsMessageFacade source = createNewMessageFacade();

    Map<Symbol, Object> deliveryAnnotationsMap = new HashMap<>();
    deliveryAnnotationsMap.put(Symbol.valueOf("test-annotation"), "value");
    source.setDeliveryAnnotations(new DeliveryAnnotations(deliveryAnnotationsMap));

    Map<Symbol, Object> footerMap = new HashMap<>();
    footerMap.put(Symbol.valueOf("test-footer"), "value");
    source.setFooter(new Footer(footerMap));

    JmsQueue aQueue = new JmsQueue("Test-Queue");
    JmsTemporaryQueue tempQueue = new JmsTemporaryQueue("Test-Temp-Queue");

    source.setDestination(aQueue);
    source.setReplyTo(tempQueue);

    source.setContentType(Symbol.valueOf("Test-ContentType"));
    source.setCorrelationId("MY-APP-ID");
    source.setExpiration(42L);
    source.setGroupId("TEST-GROUP");
    source.setGroupSequence(23);
    source.setMessageId("ID:TEST-MESSAGEID");
    source.setPriority((byte) 1);
    source.setPersistent(false);
    source.setRedeliveryCount(12);
    source.setTimestamp(150L);
    source.setUserId("Cookie-Monster");
    source.setDeliveryTime(123456, false);

    source.setProperty("APP-Prop-1", "APP-Prop-1-Value");
    source.setProperty("APP-Prop-2", "APP-Prop-2-Value");

    source.setTracingContext("Tracing-Key", "Tracing-Detail");

    // ------------------------------------

    AmqpJmsMessageFacade copy = source.copy();

    assertSame(source.getConnection(), copy.getConnection());
    assertEquals(source.hasBody(), copy.hasBody());

    assertEquals(source.getDestination(), copy.getDestination());
    assertEquals(source.getReplyTo(), copy.getReplyTo());

    assertEquals(source.getContentType(), copy.getContentType());
    assertEquals(source.getCorrelationId(), copy.getCorrelationId());
    assertEquals(source.getExpiration(), copy.getExpiration());
    assertEquals(source.getGroupId(), copy.getGroupId());
    assertEquals(source.getGroupSequence(), copy.getGroupSequence());
    assertEquals(source.getMessageId(), copy.getMessageId());
    assertEquals(source.getPriority(), copy.getPriority());
    assertEquals(source.isPersistent(), copy.isPersistent());
    assertEquals(source.getRedeliveryCount(), copy.getRedeliveryCount());
    assertEquals(source.getTimestamp(), copy.getTimestamp());
    assertEquals(source.getUserId(), copy.getUserId());
    assertEquals(source.getDeliveryTime(), copy.getDeliveryTime());

    // There should be two since none of the extended options were set
    assertEquals(2, copy.getPropertyNames().size());

    assertNotNull(copy.getProperty("APP-Prop-1"));
    assertNotNull(copy.getProperty("APP-Prop-2"));

    assertEquals("APP-Prop-1-Value", copy.getProperty("APP-Prop-1"));
    assertEquals("APP-Prop-2-Value", copy.getProperty("APP-Prop-2"));

    assertEquals("Tracing-Detail", copy.getTracingContext("Tracing-Key"));

    Footer copiedFooter = copy.getFooter();
    DeliveryAnnotations copiedDeliveryAnnotations = copy.getDeliveryAnnotations();

    assertNotNull(copiedFooter);
    assertNotNull(copiedDeliveryAnnotations);

    assertNotNull(copiedFooter.getValue());
    assertNotNull(copiedDeliveryAnnotations.getValue());

    assertFalse(copiedFooter.getValue().isEmpty());
    assertFalse(copiedDeliveryAnnotations.getValue().isEmpty());

    assertTrue(copiedFooter.getValue().containsKey(Symbol.valueOf("test-footer")));
    assertTrue(copiedDeliveryAnnotations.getValue().containsKey(Symbol.valueOf("test-annotation")));
}
 
Example #11
Source File: AmqpMessageTest.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
@Test
public void testMessageAttributes() {
    Map<String, Object> props = new LinkedHashMap<>();
    props.put("hello", "world");
    props.put("some", "content");
    Message message = message();
    message.setTtl(1);
    message.setDurable(true);
    message.setReplyTo("reply");
    ApplicationProperties apps = new ApplicationProperties(props);
    message.setApplicationProperties(apps);
    message.setContentType("text/plain");
    message.setCorrelationId("1234");
    message.setDeliveryCount(2);
    message.setExpiryTime(10000);
    message.setFooter(new Footer(props));
    message.setGroupId("some-group");
    message.setAddress("address");
    message.setCreationTime(System.currentTimeMillis());
    message.setSubject("subject");
    message.setUserId("username".getBytes());
    message.setPriority((short) 2);
    message.setBody(new AmqpValue("hello"));
    message.setMessageId("4321");

    AmqpMessage<?> msg = new AmqpMessage<>(new AmqpMessageImpl(message), null, null);
    assertThat(msg.getAddress()).isEqualTo("address");
    assertThat(msg.getApplicationProperties()).contains(entry("hello", "world"), entry("some", "content"));
    assertThat(msg.getContentType()).isEqualTo("text/plain");
    assertThat(msg.getCreationTime()).isNotZero();
    assertThat(msg.getDeliveryCount()).isEqualTo(2);
    assertThat(msg.getExpiryTime()).isEqualTo(10000);
    assertThat(msg.getGroupId()).isEqualTo("some-group");
    assertThat(msg.getTtl()).isEqualTo(1);
    assertThat(msg.getSubject()).isEqualTo("subject");
    assertThat(msg.getPriority()).isEqualTo((short) 2);
    assertThat(((AmqpValue) msg.getBody()).getValue()).isEqualTo("hello");
    assertThat(msg.getCorrelationId()).isEqualTo("1234");
    assertThat(msg.getMessageId()).isEqualTo("4321");
    assertThat(msg.getHeader()).isNotNull();
    assertThat(msg.isDurable()).isTrue();
    assertThat(msg.getError().name()).isEqualTo("OK");
    assertThat(msg.getGroupSequence()).isZero();

}
 
Example #12
Source File: AmqpCodec.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
/**
 * Given a Message instance, encode the Message to the wire level representation
 * of that Message.
 *
 * @param message
 *      the Message that is to be encoded into the wire level representation.
 *
 * @return a buffer containing the wire level representation of the input Message.
 */
public static ByteBuf encodeMessage(AmqpJmsMessageFacade message) {
    EncoderDecoderContext context = TLS_CODEC.get();

    AmqpWritableBuffer buffer = new AmqpWritableBuffer();

    EncoderImpl encoder = context.encoder;
    encoder.setByteBuffer(buffer);

    Header header = message.getHeader();
    DeliveryAnnotations deliveryAnnotations = message.getDeliveryAnnotations();
    MessageAnnotations messageAnnotations = message.getMessageAnnotations();
    Properties properties = message.getProperties();
    ApplicationProperties applicationProperties = message.getApplicationProperties();
    Section body = message.getBody();
    Footer footer = message.getFooter();

    if (header != null) {
        encoder.writeObject(header);
    }
    if (deliveryAnnotations != null) {
        encoder.writeObject(deliveryAnnotations);
    }
    if (messageAnnotations != null) {
        // Ensure annotations contain required message type and destination type data
        AmqpDestinationHelper.setReplyToAnnotationFromDestination(message.getReplyTo(), messageAnnotations);
        AmqpDestinationHelper.setToAnnotationFromDestination(message.getDestination(), messageAnnotations);
        messageAnnotations.getValue().put(AmqpMessageSupport.JMS_MSG_TYPE, message.getJmsMsgType());
        encoder.writeObject(messageAnnotations);
    } else {
        buffer.put(getCachedMessageAnnotationsBuffer(message, context));
    }
    if (properties != null) {
        encoder.writeObject(properties);
    }
    if (applicationProperties != null) {
        encoder.writeObject(applicationProperties);
    }
    if (body != null) {
        encoder.writeObject(body);
    }
    if (footer != null) {
        encoder.writeObject(footer);
    }

    encoder.setByteBuffer((WritableBuffer) null);

    return buffer.getBuffer();
}
 
Example #13
Source File: AmqpJmsMessageFacade.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
void setFooter(Footer footer) {
    if (footer != null) {
        this.footerMap = footer.getValue();
    }
}
 
Example #14
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private void assertFootersNotEquals(Footer left, Footer right) {
   if (isEquals(left, right)) {
      fail("Footer values should not be equal: left{" + left + "} right{" + right + "}");
   }
}
 
Example #15
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private void assertFootersEquals(Footer left, Footer right) {
   if (!isEquals(left, right)) {
      fail("Footer values should be equal: left{" + left + "} right{" + right + "}");
   }
}
 
Example #16
Source File: FooterType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public Class<Footer> getTypeClass()
{
    return Footer.class;
}
 
Example #17
Source File: FooterType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
protected Map wrap(Footer val)
{
    return val.getValue();
}
 
Example #18
Source File: FooterType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public Footer newInstance(Object described)
{
    return new Footer( (Map) described );
}
 
Example #19
Source File: FastPathFooterType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public Footer readValue() {
    return new Footer(getDecoder().readMap());
}
 
Example #20
Source File: FastPathFooterType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<? extends TypeEncoding<Footer>> getAllEncodings() {
    return footerType.getAllEncodings();
}
 
Example #21
Source File: FastPathFooterType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public TypeEncoding<Footer> getCanonicalEncoding() {
    return footerType.getCanonicalEncoding();
}
 
Example #22
Source File: FastPathFooterType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public TypeEncoding<Footer> getEncoding(Footer val) {
    return footerType.getEncoding(val);
}
 
Example #23
Source File: FastPathFooterType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public Class<Footer> getTypeClass() {
    return Footer.class;
}
 
Example #24
Source File: AMQPMessage.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieves the AMQP Footer encoded in the data of this message by decoding a
 * fresh copy from the encoded message data.  Changes to the returned value are not
 * reflected in the value encoded in the original message.
 *
 * @return the Footer that was encoded into this AMQP Message.
 */
public final Footer getFooter() {
   ensureScanning();
   return scanForMessageSection(Math.max(0, remainingBodyPosition), Footer.class);
}
 
Example #25
Source File: Message.java    From qpid-proton-j with Apache License 2.0 votes vote down vote up
void setFooter(Footer footer); 
Example #26
Source File: Message.java    From qpid-proton-j with Apache License 2.0 votes vote down vote up
Footer getFooter();