mirror of https://github.com/apache/activemq.git
fix and test for: https://issues.apache.org/jira/browse/AMQ-4554
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1486225 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a3060d0c7d
commit
3ff2d9294c
|
@ -22,7 +22,6 @@ import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.jms.DeliveryMode;
|
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
|
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
|
@ -32,8 +31,6 @@ import org.apache.activemq.util.JMSExceptionSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a property expression
|
* Represents a property expression
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PropertyExpression implements Expression {
|
public class PropertyExpression implements Expression {
|
||||||
|
|
||||||
|
@ -46,6 +43,7 @@ public class PropertyExpression implements Expression {
|
||||||
static {
|
static {
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSDestination", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSDestination", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
ActiveMQDestination dest = message.getOriginalDestination();
|
ActiveMQDestination dest = message.getOriginalDestination();
|
||||||
if (dest == null) {
|
if (dest == null) {
|
||||||
|
@ -59,6 +57,7 @@ public class PropertyExpression implements Expression {
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSReplyTo", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSReplyTo", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
if (message.getReplyTo() == null) {
|
if (message.getReplyTo() == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -68,24 +67,28 @@ public class PropertyExpression implements Expression {
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSType", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSType", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return message.getType();
|
return message.getType();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSDeliveryMode", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSDeliveryMode", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return message.isPersistent() ? "PERSISTENT" : "NON_PERSISTENT";
|
return message.isPersistent() ? "PERSISTENT" : "NON_PERSISTENT";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSPriority", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSPriority", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return Integer.valueOf(message.getPriority());
|
return Integer.valueOf(message.getPriority());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSMessageID", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSMessageID", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
if (message.getMessageId() == null) {
|
if (message.getMessageId() == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -95,48 +98,56 @@ public class PropertyExpression implements Expression {
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSTimestamp", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSTimestamp", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return Long.valueOf(message.getTimestamp());
|
return Long.valueOf(message.getTimestamp());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSCorrelationID", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSCorrelationID", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return message.getCorrelationId();
|
return message.getCorrelationId();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSExpiration", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSExpiration", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return Long.valueOf(message.getExpiration());
|
return Long.valueOf(message.getExpiration());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSRedelivered", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSRedelivered", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return Boolean.valueOf(message.isRedelivered());
|
return Boolean.valueOf(message.isRedelivered());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXDeliveryCount", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSXDeliveryCount", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return Integer.valueOf(message.getRedeliveryCounter() + 1);
|
return Integer.valueOf(message.getRedeliveryCounter() + 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupID", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupID", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return message.getGroupID();
|
return message.getGroupID();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupSeq", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupSeq", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return new Integer(message.getGroupSequence());
|
return new Integer(message.getGroupSequence());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSXProducerTXID", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSXProducerTXID", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
TransactionId txId = message.getOriginalTransactionId();
|
TransactionId txId = message.getOriginalTransactionId();
|
||||||
if (txId == null) {
|
if (txId == null) {
|
||||||
|
@ -145,23 +156,26 @@ public class PropertyExpression implements Expression {
|
||||||
if (txId == null) {
|
if (txId == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Integer(txId.toString());
|
return txId.toString();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerInTime", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerInTime", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return Long.valueOf(message.getBrokerInTime());
|
return Long.valueOf(message.getBrokerInTime());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerOutTime", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerOutTime", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return Long.valueOf(message.getBrokerOutTime());
|
return Long.valueOf(message.getBrokerOutTime());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerPath", new SubExpression() {
|
JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerPath", new SubExpression() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(Message message) {
|
public Object evaluate(Message message) {
|
||||||
return Arrays.toString(message.getBrokerPath());
|
return Arrays.toString(message.getBrokerPath());
|
||||||
}
|
}
|
||||||
|
@ -176,6 +190,7 @@ public class PropertyExpression implements Expression {
|
||||||
jmsPropertyExpression = JMS_PROPERTY_EXPRESSIONS.get(name);
|
jmsPropertyExpression = JMS_PROPERTY_EXPRESSIONS.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object evaluate(MessageEvaluationContext message) throws JMSException {
|
public Object evaluate(MessageEvaluationContext message) throws JMSException {
|
||||||
try {
|
try {
|
||||||
if (message.isDropped()) {
|
if (message.isDropped()) {
|
||||||
|
@ -214,6 +229,7 @@ public class PropertyExpression implements Expression {
|
||||||
/**
|
/**
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -221,6 +237,7 @@ public class PropertyExpression implements Expression {
|
||||||
/**
|
/**
|
||||||
* @see java.lang.Object#hashCode()
|
* @see java.lang.Object#hashCode()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return name.hashCode();
|
return name.hashCode();
|
||||||
}
|
}
|
||||||
|
@ -228,13 +245,12 @@ public class PropertyExpression implements Expression {
|
||||||
/**
|
/**
|
||||||
* @see java.lang.Object#equals(java.lang.Object)
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
|
||||||
if (o == null || !this.getClass().equals(o.getClass())) {
|
if (o == null || !this.getClass().equals(o.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return name.equals(((PropertyExpression)o).name);
|
return name.equals(((PropertyExpression) o).name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.activemq.bugs;
|
||||||
|
|
||||||
|
import javax.jms.Connection;
|
||||||
|
import javax.jms.Message;
|
||||||
|
import javax.jms.MessageConsumer;
|
||||||
|
import javax.jms.MessageProducer;
|
||||||
|
import javax.jms.Session;
|
||||||
|
import javax.jms.TextMessage;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for simple App.
|
||||||
|
*/
|
||||||
|
public class AMQ4554Test extends TestCase {
|
||||||
|
|
||||||
|
private final Logger LOG = LoggerFactory.getLogger(AMQ4554Test.class);
|
||||||
|
|
||||||
|
private String connectionURI;
|
||||||
|
private BrokerService broker;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
broker = new BrokerService();
|
||||||
|
connectionURI = broker.addConnector("tcp://0.0.0.0:0?maximumConnections=1").getPublishableConnectString();
|
||||||
|
broker.setPersistent(false);
|
||||||
|
broker.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
broker.stop();
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the test case
|
||||||
|
*
|
||||||
|
* @param testName
|
||||||
|
* name of the test case
|
||||||
|
*/
|
||||||
|
public AMQ4554Test(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the suite of tests being tested
|
||||||
|
*/
|
||||||
|
public static Test suite() {
|
||||||
|
return new TestSuite(AMQ4554Test.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMSXProducerTXID() throws Exception {
|
||||||
|
|
||||||
|
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionURI);
|
||||||
|
Connection connection = factory.createConnection();
|
||||||
|
connection.start();
|
||||||
|
|
||||||
|
Session producerSession = connection.createSession(true, Session.SESSION_TRANSACTED);
|
||||||
|
MessageProducer producer = producerSession.createProducer(producerSession.createQueue("myQueue"));
|
||||||
|
TextMessage producerMessage = producerSession.createTextMessage("Test Message");
|
||||||
|
producer.send(producerMessage);
|
||||||
|
producer.close();
|
||||||
|
producerSession.commit();
|
||||||
|
producerSession.close();
|
||||||
|
|
||||||
|
Session consumerSession = connection.createSession(true, Session.SESSION_TRANSACTED);
|
||||||
|
MessageConsumer consumer = consumerSession.createConsumer(consumerSession.createQueue("myQueue"));
|
||||||
|
Message consumerMessage = consumer.receive(1000);
|
||||||
|
try {
|
||||||
|
String txId = consumerMessage.getStringProperty("JMSXProducerTXID");
|
||||||
|
assertNotNull(txId);
|
||||||
|
} catch(Exception e) {
|
||||||
|
LOG.info("Caught Exception that was not expected:", e);
|
||||||
|
fail("Should not throw");
|
||||||
|
}
|
||||||
|
consumer.close();
|
||||||
|
consumerSession.commit();
|
||||||
|
consumerSession.close();
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue