Java Code Examples for javax.jms.Message#clearProperties()

The following examples show how to use javax.jms.Message#clearProperties() . 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: PriorityQueueTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(final Message message)
{
    try
    {
        _latch.countDown();
        long msgNum = _origCount - _latch.getCount();
        LOGGER.info("Received message " + msgNum + " with ID: " + message.getIntProperty("msg"));

        if(_latch.getCount() > 0)
        {
            //reflect the message, updating its ID and using default priority
            message.clearProperties();
            message.setIntProperty("msg", (int) msgNum + 1);
            _producer.setPriority(Message.DEFAULT_PRIORITY);
            _producer.send(message);
            _producerSession.commit();
        }

        //commit the consumer session to consume the message
        _consumerSession.commit();
    }
    catch(Throwable t)
    {
        LOGGER.error(t.getMessage(), t);
        _lastThrown = t;
    }
}
 
Example 2
Source File: MdbInterceptor.java    From tomee with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object mdbInterceptor(final InvocationContext ctx) throws Exception {
    final Object[] objArr = ctx.getParameters();
    final Message msg = (Message) objArr[0];
    msg.clearProperties();
    msg.setBooleanProperty("ClassLevelBusinessMethodInterception", true);
    ctx.setParameters(objArr);
    return ctx.proceed();
}
 
Example 3
Source File: MessageHeaderTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testClearMessage() throws Exception {
   queueProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

   Message message = queueProducerSession.createTextMessage("some message");

   queueProducer.send(message);

   message = queueConsumer.receive(1000);

   ProxyAssertSupport.assertNotNull(message);

   message.clearProperties();

   ProxyAssertSupport.assertNotNull(message.getJMSDestination());

}
 
Example 4
Source File: AmqpAcknowledgementsIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
private void doTestAmqpAcknowledgementTestImpl(int disposition, Matcher<?> descriptorMatcher, boolean clearPropsFirst) throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();

        Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Queue queue = session.createQueue("myQueue");

        int msgCount = 3;
        testPeer.expectReceiverAttach();
        testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, new AmqpValueDescribedType(null), msgCount);
        for (int i = 1; i <= msgCount; i++) {
            testPeer.expectDisposition(true, descriptorMatcher);
        }

        MessageConsumer messageConsumer = session.createConsumer(queue);

        Message lastReceivedMessage = null;
        for (int i = 1; i <= msgCount; i++) {
            lastReceivedMessage = messageConsumer.receive(6000);
            assertNotNull("Message " + i + " was not recieved", lastReceivedMessage);
        }

        if (disposition != SKIP) {
            if (clearPropsFirst) {
                lastReceivedMessage.clearProperties();
            }

            lastReceivedMessage.setIntProperty(JmsMessageSupport.JMS_AMQP_ACK_TYPE, disposition);
        }

        if (disposition == INVALID) {
            try {
                lastReceivedMessage.acknowledge();
                fail("Should throw exception due to invalid ack type");
            } catch (JMSException jmsex) {}

            lastReceivedMessage.setIntProperty(JmsMessageSupport.JMS_AMQP_ACK_TYPE, JmsMessageSupport.ACCEPTED);
            lastReceivedMessage.acknowledge();
        } else {
            lastReceivedMessage.acknowledge();
        }

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(3000);
    }
}
 
Example 5
Source File: SQSMessageTest.java    From amazon-sqs-java-messaging-lib with Apache License 2.0 4 votes vote down vote up
/**
 * Test setting SQSMessage property
 */
@Test
public void testProperty() throws JMSException {
    when(mockSQSSession.createMessage()).thenReturn(new SQSMessage());
    Message message = mockSQSSession.createMessage();

    message.setBooleanProperty("myTrueBoolean", true);
    message.setBooleanProperty("myFalseBoolean", false);
    message.setIntProperty("myInteger", 100);
    message.setDoubleProperty("myDouble", 2.1768);
    message.setFloatProperty("myFloat", 3.1457f);
    message.setLongProperty("myLong", 1290772974281L);
    message.setShortProperty("myShort", (short) 123);
    message.setByteProperty("myByteProperty", (byte) 'a');
    message.setStringProperty("myString", "StringValue");
    message.setStringProperty("myNumber", "500");

    Assert.assertTrue(message.propertyExists("myTrueBoolean"));
    Assert.assertEquals(message.getObjectProperty("myTrueBoolean"), true);
    Assert.assertEquals(message.getBooleanProperty("myTrueBoolean"), true);
    
    Assert.assertTrue(message.propertyExists("myFalseBoolean"));
    Assert.assertEquals(message.getObjectProperty("myFalseBoolean"), false);
    Assert.assertEquals(message.getBooleanProperty("myFalseBoolean"), false);
    
    Assert.assertTrue(message.propertyExists("myInteger"));
    Assert.assertEquals(message.getObjectProperty("myInteger"), 100);
    Assert.assertEquals(message.getIntProperty("myInteger"), 100);
    
    Assert.assertTrue(message.propertyExists("myDouble"));
    Assert.assertEquals(message.getObjectProperty("myDouble"), 2.1768);
    Assert.assertEquals(message.getDoubleProperty("myDouble"), 2.1768);
    
    Assert.assertTrue(message.propertyExists("myFloat"));
    Assert.assertEquals(message.getObjectProperty("myFloat"), 3.1457f);
    Assert.assertEquals(message.getFloatProperty("myFloat"), 3.1457f);
    
    Assert.assertTrue(message.propertyExists("myLong"));
    Assert.assertEquals(message.getObjectProperty("myLong"), 1290772974281L);
    Assert.assertEquals(message.getLongProperty("myLong"), 1290772974281L);
    
    Assert.assertTrue(message.propertyExists("myShort"));
    Assert.assertEquals(message.getObjectProperty("myShort"), (short) 123);
    Assert.assertEquals(message.getShortProperty("myShort"), (short) 123);
    
    Assert.assertTrue(message.propertyExists("myByteProperty"));
    Assert.assertEquals(message.getObjectProperty("myByteProperty"), (byte) 'a');
    Assert.assertEquals(message.getByteProperty("myByteProperty"), (byte) 'a');
    
    Assert.assertTrue(message.propertyExists("myString"));
    Assert.assertEquals(message.getObjectProperty("myString"), "StringValue");
    Assert.assertEquals(message.getStringProperty("myString"), "StringValue");

    Assert.assertTrue(message.propertyExists("myNumber"));
    Assert.assertEquals(message.getObjectProperty("myNumber"), "500");
    Assert.assertEquals(message.getStringProperty("myNumber"), "500");
    Assert.assertEquals(message.getLongProperty("myNumber"), 500L);
    Assert.assertEquals(message.getFloatProperty("myNumber"), 500f);
    Assert.assertEquals(message.getShortProperty("myNumber"), (short) 500);
    Assert.assertEquals(message.getDoubleProperty("myNumber"), 500d);
    Assert.assertEquals(message.getIntProperty("myNumber"), 500);

    // Validate property names
    Set<String> propertyNamesSet = new HashSet<String>(Arrays.asList(
            "myTrueBoolean",
            "myFalseBoolean",
            "myInteger",
            "myDouble",
            "myFloat",
            "myLong",
            "myShort",
            "myByteProperty",
            "myNumber",
            "myString"));

    Enumeration<String > propertyNames = message.getPropertyNames();
    int counter = 0;
    while (propertyNames.hasMoreElements()) {
        assertTrue(propertyNamesSet.contains(propertyNames.nextElement()));
        counter++;
    }
    assertEquals(propertyNamesSet.size(), counter);
    
    message.clearProperties();
    Assert.assertFalse(message.propertyExists("myTrueBoolean"));
    Assert.assertFalse(message.propertyExists("myInteger"));
    Assert.assertFalse(message.propertyExists("myDouble"));
    Assert.assertFalse(message.propertyExists("myFloat"));
    Assert.assertFalse(message.propertyExists("myLong"));
    Assert.assertFalse(message.propertyExists("myShort"));
    Assert.assertFalse(message.propertyExists("myByteProperty"));
    Assert.assertFalse(message.propertyExists("myString"));
    Assert.assertFalse(message.propertyExists("myNumber"));

    propertyNames = message.getPropertyNames();
    assertFalse(propertyNames.hasMoreElements());
}