org.apache.qpid.proton.amqp.UnsignedByte Java Examples

The following examples show how to use org.apache.qpid.proton.amqp.UnsignedByte. 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: FailoverIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
private void doConnectThrowsSecurityViolationOnFailureFromSaslImplicitlyWithoutClientIDTestImpl(UnsignedByte saslFailureCode) throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        testPeer.expectSaslFailingExchange(new Symbol[] {PLAIN, ANONYMOUS}, PLAIN, saslFailureCode);

        ConnectionFactory factory = new JmsConnectionFactory("failover:(amqp://localhost:" + testPeer.getServerPort() + ")");
        Connection connection = factory.createConnection("username", "password");

        try {
            connection.start();
            fail("Excepted exception to be thrown");
        }catch (JMSSecurityException jmsse) {
            LOG.info("Caught expected security exception: {}", jmsse.getMessage());
        }

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #2
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetHeaderWithPriorityHeader() {
    AmqpHeader header = new AmqpHeader();

    Header protonHeader = new Header();
    protonHeader.setPriority(UnsignedByte.valueOf((byte) 9));

    header.setHeader(protonHeader);

    assertFalse(header.isDefault());
    assertFalse(header.nonDefaultDurable());
    assertTrue(header.nonDefaultPriority());
    assertFalse(header.nonDefaultTimeToLive());
    assertFalse(header.nonDefaultFirstAcquirer());
    assertFalse(header.nonDefaultDeliveryCount());

    assertEquals(false, header.isDurable());
    assertEquals(false, header.isFirstAcquirer());
    assertEquals(9, header.getPriority());
    assertEquals(0, header.getTimeToLive());
    assertEquals(0, header.getDeliveryCount());
}
 
Example #3
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateFromAmqpHeader() {
    AmqpHeader amqpHeader = new AmqpHeader();
    amqpHeader.setPriority(UnsignedByte.valueOf((byte) 9));
    amqpHeader.setTimeToLive(UnsignedInteger.valueOf(10));
    amqpHeader.setDeliveryCount(UnsignedInteger.valueOf(11));
    amqpHeader.setDurable(true);
    amqpHeader.setFirstAcquirer(true);

    AmqpHeader header = new AmqpHeader(amqpHeader);

    assertFalse(header.isDefault());
    assertTrue(header.nonDefaultDurable());
    assertTrue(header.nonDefaultPriority());
    assertTrue(header.nonDefaultTimeToLive());
    assertTrue(header.nonDefaultFirstAcquirer());
    assertTrue(header.nonDefaultDeliveryCount());

    assertEquals(true, header.isDurable());
    assertEquals(true, header.isFirstAcquirer());
    assertEquals(9, header.getPriority());
    assertEquals(10, header.getTimeToLive());
    assertEquals(11, header.getDeliveryCount());
}
 
Example #4
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetHeaderWithAmqpHeaderWithAllSet() {
    AmqpHeader header = new AmqpHeader();

    AmqpHeader amqpHeader = new AmqpHeader();
    amqpHeader.setPriority(UnsignedByte.valueOf((byte) 9));
    amqpHeader.setTimeToLive(UnsignedInteger.valueOf(10));
    amqpHeader.setDeliveryCount(UnsignedInteger.valueOf(11));
    amqpHeader.setDurable(true);
    amqpHeader.setFirstAcquirer(true);

    header.setHeader(amqpHeader);

    assertFalse(header.isDefault());
    assertTrue(header.nonDefaultDurable());
    assertTrue(header.nonDefaultPriority());
    assertTrue(header.nonDefaultTimeToLive());
    assertTrue(header.nonDefaultFirstAcquirer());
    assertTrue(header.nonDefaultDeliveryCount());

    assertEquals(true, header.isDurable());
    assertEquals(true, header.isFirstAcquirer());
    assertEquals(9, header.getPriority());
    assertEquals(10, header.getTimeToLive());
    assertEquals(11, header.getDeliveryCount());
}
 
Example #5
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateFromHeader() {
    Header protonHeader = new Header();
    protonHeader.setPriority(UnsignedByte.valueOf((byte) 9));
    protonHeader.setTtl(UnsignedInteger.valueOf(10));
    protonHeader.setDeliveryCount(UnsignedInteger.valueOf(11));
    protonHeader.setDurable(true);
    protonHeader.setFirstAcquirer(true);

    AmqpHeader header = new AmqpHeader(protonHeader);

    assertFalse(header.isDefault());
    assertTrue(header.nonDefaultDurable());
    assertTrue(header.nonDefaultPriority());
    assertTrue(header.nonDefaultTimeToLive());
    assertTrue(header.nonDefaultFirstAcquirer());
    assertTrue(header.nonDefaultDeliveryCount());

    assertEquals(true, header.isDurable());
    assertEquals(true, header.isFirstAcquirer());
    assertEquals(9, header.getPriority());
    assertEquals(10, header.getTimeToLive());
    assertEquals(11, header.getDeliveryCount());
}
 
Example #6
Source File: SaslOutcomeType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public SaslOutcome newInstance(Object described)
{
    List l = (List) described;

    SaslOutcome o = new SaslOutcome();

    if(l.isEmpty())
    {
        throw new DecodeException("The code field cannot be omitted");
    }

    switch(2 - l.size())
    {

        case 0:
            o.setAdditionalData( (Binary) l.get( 1 ) );
        case 1:
            o.setCode(SaslCode.valueOf((UnsignedByte) l.get(0)));
    }


    return o;
}
 
Example #7
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetHeaderWithHeaderWithAllSet() {
    AmqpHeader header = new AmqpHeader();

    Header protonHeader = new Header();
    protonHeader.setPriority(UnsignedByte.valueOf((byte) 9));
    protonHeader.setTtl(UnsignedInteger.valueOf(10));
    protonHeader.setDeliveryCount(UnsignedInteger.valueOf(11));
    protonHeader.setDurable(true);
    protonHeader.setFirstAcquirer(true);

    header.setHeader(protonHeader);

    assertFalse(header.isDefault());
    assertTrue(header.nonDefaultDurable());
    assertTrue(header.nonDefaultPriority());
    assertTrue(header.nonDefaultTimeToLive());
    assertTrue(header.nonDefaultFirstAcquirer());
    assertTrue(header.nonDefaultDeliveryCount());

    assertEquals(true, header.isDurable());
    assertEquals(true, header.isFirstAcquirer());
    assertEquals(9, header.getPriority());
    assertEquals(10, header.getTimeToLive());
    assertEquals(11, header.getDeliveryCount());
}
 
Example #8
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetHeaderWithPriorityAmqpHeader() {
    AmqpHeader header = new AmqpHeader();

    AmqpHeader amqpHeader = new AmqpHeader();
    amqpHeader.setPriority(UnsignedByte.valueOf((byte) 9));

    header.setHeader(amqpHeader);

    assertFalse(header.isDefault());
    assertFalse(header.nonDefaultDurable());
    assertTrue(header.nonDefaultPriority());
    assertFalse(header.nonDefaultTimeToLive());
    assertFalse(header.nonDefaultFirstAcquirer());
    assertFalse(header.nonDefaultDeliveryCount());

    assertEquals(false, header.isDurable());
    assertEquals(false, header.isFirstAcquirer());
    assertEquals(9, header.getPriority());
    assertEquals(0, header.getTimeToLive());
    assertEquals(0, header.getDeliveryCount());
}
 
Example #9
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Receive message which has a header section with a priority value. Ensure the headers
 * underlying field value is cleared when the priority is set to the default priority of 4.
 */
@Test
public void testSetPriorityToDefaultOnReceivedMessageWithPriorityClearsPriorityField() {
    byte priority = 11;

    Message message = Proton.message();
    Header header = new Header();
    message.setHeader(header);
    header.setPriority(UnsignedByte.valueOf(priority));

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);
    amqpMessageFacade.setPriority(Message.DEFAULT_PRIORITY);

    //check the expected value is still returned
    assertEquals("expected priority value not returned", Message.DEFAULT_PRIORITY, amqpMessageFacade.getPriority());

    //check the underlying header field was actually cleared rather than set to Message.DEFAULT_PRIORITY
    assertNull("underlying header priority field was not cleared", amqpMessageFacade.getHeader());
}
 
Example #10
Source File: FailoverIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
private void doConnectThrowsSecurityViolationOnFailureFromSaslWithOrExplicitlyWithoutClientIDTestImpl(boolean clientID, UnsignedByte saslFailureCode) throws Exception {
    String optionString;
    if (clientID) {
        optionString = "?jms.clientID=myClientID";
    } else {
        optionString = "?jms.awaitClientID=false";
    }

    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {

        testPeer.expectSaslFailingExchange(new Symbol[] {PLAIN, ANONYMOUS}, PLAIN, saslFailureCode);

        ConnectionFactory factory = new JmsConnectionFactory("failover:(amqp://localhost:" + testPeer.getServerPort() + ")" + optionString);

        try {
            factory.createConnection("username", "password");
            fail("Excepted exception to be thrown");
        }catch (JMSSecurityException jmsse) {
            LOG.info("Caught expected security exception: {}", jmsse.getMessage());
        }

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #11
Source File: HeaderType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public Header newInstance(Object described)
{
    List l = (List) described;

    Header o = new Header();


    switch(5 - l.size())
    {

        case 0:
            o.setDeliveryCount( (UnsignedInteger) l.get( 4 ) );
        case 1:
            o.setFirstAcquirer( (Boolean) l.get( 3 ) );
        case 2:
            o.setTtl( (UnsignedInteger) l.get( 2 ) );
        case 3:
            o.setPriority( (UnsignedByte) l.get( 1 ) );
        case 4:
            o.setDurable( (Boolean) l.get( 0 ) );
    }


    return o;
}
 
Example #12
Source File: SaslIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
private void doSaslFailureCodesTestImpl(UnsignedByte saslFailureCode) throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {

        testPeer.expectSaslFailingExchange(new Symbol[] {PLAIN, ANONYMOUS}, PLAIN, saslFailureCode);

        ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + testPeer.getServerPort() + "?jms.clientID=myClientID");

        try {
            factory.createConnection("username", "password");
            fail("Excepted exception to be thrown");
        }catch (JMSSecurityException jmsse) {
            LOG.info("Caught expected security exception: {}", jmsse.getMessage());
        }

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #13
Source File: AMQPPersisterTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
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 #14
Source File: Benchmark.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private void benchmarkMessageAnnotations() throws IOException {
    MessageAnnotations annotations = new MessageAnnotations(new HashMap<Symbol, Object>());
    annotations.getValue().put(Symbol.valueOf("test1"), UnsignedByte.valueOf((byte) 128));
    annotations.getValue().put(Symbol.valueOf("test2"), UnsignedShort.valueOf((short) 128));
    annotations.getValue().put(Symbol.valueOf("test3"), UnsignedInteger.valueOf((byte) 128));

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        outputBuf.byteBuffer().clear();
        encoder.writeObject(annotations);
    }
    resultSet.encodesComplete();

    CompositeReadableBuffer inputBuf = convertToComposite(outputBuf);
    decoder.setBuffer(inputBuf);

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        decoder.readObject();
        inputBuf.flip();
    }
    resultSet.decodesComplete();

    time("MessageAnnotations", resultSet);
}
 
Example #15
Source File: Benchmark.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private void benchmarkApplicationProperties() throws IOException {
    ApplicationProperties properties = new ApplicationProperties(new HashMap<String, Object>());
    properties.getValue().put("test1", UnsignedByte.valueOf((byte) 128));
    properties.getValue().put("test2", UnsignedShort.valueOf((short) 128));
    properties.getValue().put("test3", UnsignedInteger.valueOf((byte) 128));

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        outputBuf.byteBuffer().clear();
        encoder.writeObject(properties);
    }
    resultSet.encodesComplete();

    CompositeReadableBuffer inputBuf = convertToComposite(outputBuf);
    decoder.setBuffer(inputBuf);

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        decoder.readObject();
        inputBuf.flip();
    }
    resultSet.decodesComplete();

    time("ApplicationProperties", resultSet);
}
 
Example #16
Source File: ServerJMSMapMessage.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void setObject(final String name, final Object value) throws JMSException {
   try {
      // primitives and String
      Object val = value;
      if (value instanceof UnsignedInteger) {
         val = ((UnsignedInteger) value).intValue();
      } else if (value instanceof UnsignedShort) {
         val = ((UnsignedShort) value).shortValue();
      } else if (value instanceof UnsignedByte) {
         val = ((UnsignedByte) value).byteValue();
      } else if (value instanceof UnsignedLong) {
         val = ((UnsignedLong) value).longValue();
      }
      TypedProperties.setObjectProperty(new SimpleString(name), val, map);
   } catch (ActiveMQPropertyConversionException e) {
      throw new MessageFormatException(e.getMessage());
   }
}
 
Example #17
Source File: AmqpManagementTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Some clients use Unsigned types from org.apache.qpid.proton.amqp
 * @throws Exception
 */
@Test(timeout = 60000)
public void testUnsignedValues() throws Exception {
   int sequence = 42;
   LinkedHashMap<String, Object> map = new LinkedHashMap<>();
   map.put("sequence", new UnsignedInteger(sequence));
   ServerJMSMapMessage msg = createMapMessage(1, map, null);
   assertEquals(msg.getInt("sequence"), sequence);

   map.clear();
   map.put("sequence", new UnsignedLong(sequence));
   msg = createMapMessage(1, map, null);
   assertEquals(msg.getLong("sequence"), sequence);

   map.clear();
   map.put("sequence", new UnsignedShort((short)sequence));
   msg = createMapMessage(1, map, null);
   assertEquals(msg.getShort("sequence"), sequence);

   map.clear();
   map.put("sequence", new UnsignedByte((byte) sequence));
   msg = createMapMessage(1, map, null);
   assertEquals(msg.getByte("sequence"), sequence);
}
 
Example #18
Source File: HeaderTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testCopy() {
    Header original = new Header();

    original.setDeliveryCount(UnsignedInteger.valueOf(1));
    original.setDurable(true);
    original.setFirstAcquirer(true);
    original.setPriority(UnsignedByte.valueOf((byte) 7));
    original.setTtl(UnsignedInteger.valueOf(100));

    Header copy = new Header(original);

    assertEquals(original.getDeliveryCount(), copy.getDeliveryCount());
    assertEquals(original.getDurable(), copy.getDurable());
    assertEquals(original.getFirstAcquirer(), copy.getFirstAcquirer());
    assertEquals(original.getPriority(), copy.getPriority());
    assertEquals(original.getTtl(), copy.getTtl());
}
 
Example #19
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Test that setting the Priority to a non-default value results in the underlying
 * message field being populated appropriately, and the value being returned from the Getter.
 */
@Test
public void testSetGetNonDefaultPriorityForNewMessage() {
    byte priority = 6;

    AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
    amqpMessageFacade.setPriority(priority);

    assertEquals("expected priority value not found", priority, amqpMessageFacade.getPriority());
    assertEquals("expected priority value not found", UnsignedByte.valueOf(priority), amqpMessageFacade.getHeader().getPriority());
}
 
Example #20
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * When messages have a header section, which has a priority value above the
 * JMS range of 0-9 and also outside the signed byte range (given AMQP
 * allowing ubyte priority), ensure it is constrained to 9.
 */
@Test
public void testGetPriorityForReceivedMessageWithPriorityAboveSignedByteRange() {
    String priorityString = String.valueOf(255);

    Message message = Proton.message();
    Header header = new Header();
    message.setHeader(header);
    header.setPriority(UnsignedByte.valueOf(priorityString));

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("expected priority value not found", 9, amqpMessageFacade.getPriority());
}
 
Example #21
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Test that setting the Priority below the JMS range of 0-9 resuls in the underlying
 * message field being populated with the value 0.
 */
@Test
public void testSetPriorityBelowJmsRangeForNewMessage() {
    AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
    amqpMessageFacade.setPriority(-1);

    assertEquals("expected priority value not found", 0, amqpMessageFacade.getPriority());
    assertEquals("expected priority value not found", UnsignedByte.valueOf((byte) 0), amqpMessageFacade.getHeader().getPriority());
}
 
Example #22
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private MessageImpl createProtonMessage() {
   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(TEST_TO_ADDRESS);
   properties.setMessageId(UUID.randomUUID());

   MessageAnnotations annotations = new MessageAnnotations(new LinkedHashMap<>());
   annotations.getValue().put(Symbol.valueOf(TEST_MESSAGE_ANNOTATION_KEY), TEST_MESSAGE_ANNOTATION_VALUE);

   ApplicationProperties applicationProperties = new ApplicationProperties(new LinkedHashMap<>());
   applicationProperties.getValue().put(TEST_APPLICATION_PROPERTY_KEY, TEST_APPLICATION_PROPERTY_VALUE);

   AmqpValue body = new AmqpValue(TEST_STRING_BODY);

   message.setHeader(header);
   message.setMessageAnnotations(annotations);
   message.setProperties(properties);
   message.setApplicationProperties(applicationProperties);
   message.setBody(body);

   return message;
}
 
Example #23
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testPartialDecodeIgnoresBodyByDefault() {
   Header header = new Header();
   header.setDurable(true);
   header.setPriority(UnsignedByte.valueOf((byte) 6));

   ByteBuf encodedBytes = Unpooled.buffer(1024);
   NettyWritable writable = new NettyWritable(encodedBytes);

   EncoderImpl encoder = TLSEncode.getEncoder();
   encoder.setByteBuffer(writable);
   encoder.writeObject(header);

   // Signal body of AmqpValue but write corrupt underlying type info
   encodedBytes.writeByte(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
   encodedBytes.writeByte(EncodingCodes.SMALLULONG);
   encodedBytes.writeByte(AMQPVALUE_DESCRIPTOR.byteValue());
   // Use bad encoding code on underlying type
   encodedBytes.writeByte(255);

   ReadableBuffer readable = new NettyReadable(encodedBytes);

   AMQPStandardMessage message = null;
   try {
      message = new AMQPStandardMessage(0, readable, null, null);
   } catch (Exception decodeError) {
      fail("Should not have encountered an exception on partial decode: " + decodeError.getMessage());
   }

   assertTrue(message.isDurable());

   try {
      // This will decode the body section if present in order to present it as a Proton Message object
      message.getBody();
      fail("Should have thrown an error when attempting to decode the body which is malformed.");
   } catch (Exception ex) {
      // Expected decode to fail when building full message.
   }
}
 
Example #24
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testPartialDecodeIgnoresDeliveryAnnotationsByDefault() {
   Header header = new Header();
   header.setDurable(true);
   header.setPriority(UnsignedByte.valueOf((byte) 6));

   ByteBuf encodedBytes = Unpooled.buffer(1024);
   NettyWritable writable = new NettyWritable(encodedBytes);

   EncoderImpl encoder = TLSEncode.getEncoder();
   encoder.setByteBuffer(writable);
   encoder.writeObject(header);

   // Signal body of AmqpValue but write corrupt underlying type info
   encodedBytes.writeByte(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
   encodedBytes.writeByte(EncodingCodes.SMALLULONG);
   encodedBytes.writeByte(DELIVERY_ANNOTATIONS_DESCRIPTOR.byteValue());
   encodedBytes.writeByte(EncodingCodes.MAP8);
   encodedBytes.writeByte(2);  // Size
   encodedBytes.writeByte(2);  // Elements
   // Use bad encoding code on underlying type of map key which will fail the decode if run
   encodedBytes.writeByte(255);

   ReadableBuffer readable = new NettyReadable(encodedBytes);

   AMQPStandardMessage message = null;
   try {
      message = new AMQPStandardMessage(0, readable, null, null);
   } catch (Exception decodeError) {
      fail("Should not have encountered an exception on partial decode: " + decodeError.getMessage());
   }

   try {
      // This should perform the lazy decode of the DeliveryAnnotations portion of the message
      message.getDeliveryAnnotations();
      fail("Should have thrown an error when attempting to decode the ApplicationProperties which are malformed.");
   } catch (Exception ex) {
      // Expected decode to fail when building full message.
   }
}
 
Example #25
Source File: AMQPMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public final Object getObjectProperty(String key) {
   if (key.equals(MessageUtil.TYPE_HEADER_NAME.toString())) {
      if (properties != null) {
         return properties.getSubject();
      }
   } else if (key.equals(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString())) {
      return getConnectionID();
   } else if (key.equals(MessageUtil.JMSXGROUPID)) {
      return getGroupID();
   } else if (key.equals(MessageUtil.JMSXGROUPSEQ)) {
      return getGroupSequence();
   } else if (key.equals(MessageUtil.JMSXUSERID)) {
      return getAMQPUserID();
   } else if (key.equals(MessageUtil.CORRELATIONID_HEADER_NAME.toString())) {
      if (properties != null && properties.getCorrelationId() != null) {
         return AMQPMessageIdHelper.INSTANCE.toCorrelationIdString(properties.getCorrelationId());
      }
   } else {
      Object value = getApplicationPropertiesMap(false).get(key);
      if (value instanceof UnsignedInteger ||
          value instanceof UnsignedByte ||
          value instanceof UnsignedLong ||
          value instanceof UnsignedShort) {
         return ((Number)value).longValue();
      } else {
         return value;
      }
   }

   return null;
}
 
Example #26
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetPriorityFromNull() {
    AmqpHeader header = new AmqpHeader();

    header.setPriority((UnsignedByte) null);

    assertEquals(4, header.getPriority());
    assertFalse(header.nonDefaultPriority());

    assertTrue(header.isDefault());
}
 
Example #27
Source File: MessageAnnotationsBenchmark.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private void initMessageAnnotations()
{
    annotations = new MessageAnnotations(new HashMap<Symbol, Object>());
    annotations.getValue().put(Symbol.valueOf("test1"), UnsignedByte.valueOf((byte) 128));
    annotations.getValue().put(Symbol.valueOf("test2"), UnsignedShort.valueOf((short) 128));
    annotations.getValue().put(Symbol.valueOf("test3"), UnsignedInteger.valueOf((byte) 128));
}
 
Example #28
Source File: ApplicationPropertiesBenchmark.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private void initApplicationProperties()
{
    properties = new ApplicationProperties(new HashMap<String, Object>());
    properties.getValue().put("test1", UnsignedByte.valueOf((byte) 128));
    properties.getValue().put("test2", UnsignedShort.valueOf((short) 128));
    properties.getValue().put("test3", UnsignedInteger.valueOf((byte) 128));
}
 
Example #29
Source File: MessageImpl.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void setPriority(short priority)
{

    if (_header == null)
    {
        if (priority == DEFAULT_PRIORITY)
        {
            return;
        }
        _header = new Header();
    }
    _header.setPriority(UnsignedByte.valueOf((byte) priority));
}
 
Example #30
Source File: AmqpHeader.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public void setPriority(UnsignedByte value) {
    if (value == null || value.intValue() == DEFAULT_PRIORITY) {
        modified &= ~PRIORITY;
        priority = null;
    } else {
        modified |= PRIORITY;
        priority = value;
    }
}