You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2011/08/14 00:28:42 UTC
svn commit: r1157433 - in /activemq/trunk/activemq-core/src:
main/java/org/apache/activemq/filter/ComparisonExpression.java
test/java/org/apache/activemq/transport/stomp/StompTest.java
Author: tabish
Date: Sat Aug 13 22:28:42 2011
New Revision: 1157433
URL: http://svn.apache.org/viewvc?rev=1157433&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQ-1942
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/ComparisonExpression.java
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/ComparisonExpression.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/ComparisonExpression.java?rev=1157433&r1=1157432&r2=1157433&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/ComparisonExpression.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/ComparisonExpression.java Sat Aug 13 22:28:42 2011
@@ -25,8 +25,8 @@ import javax.jms.JMSException;
/**
* A filter performing a comparison of two objects
- *
- *
+ *
+ *
*/
public abstract class ComparisonExpression extends BinaryExpression implements BooleanExpression {
@@ -160,6 +160,7 @@ public abstract class ComparisonExpressi
return UnaryExpression.createNOT(createLike(left, right, escape));
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public static BooleanExpression createInFilter(Expression left, List elements) {
if (!(left instanceof PropertyExpression)) {
@@ -169,6 +170,7 @@ public abstract class ComparisonExpressi
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public static BooleanExpression createNotInFilter(Expression left, List elements) {
if (!(left instanceof PropertyExpression)) {
@@ -197,6 +199,7 @@ public abstract class ComparisonExpressi
return doCreateEqual(left, right);
}
+ @SuppressWarnings({ "rawtypes" })
private static BooleanExpression doCreateEqual(Expression left, Expression right) {
return new ComparisonExpression(left, right) {
@@ -204,7 +207,7 @@ public abstract class ComparisonExpressi
Object lv = left.evaluate(message);
Object rv = right.evaluate(message);
- // Iff one of the values is null
+ // If one of the values is null
if (lv == null ^ rv == null) {
return Boolean.FALSE;
}
@@ -288,7 +291,7 @@ public abstract class ComparisonExpressi
/**
* Only Numeric expressions can be used in >, >=, < or <= expressions.s
- *
+ *
* @param expr
*/
public static void checkLessThanOperand(Expression expr) {
@@ -309,7 +312,7 @@ public abstract class ComparisonExpressi
/**
* Validates that the expression can be used in == or <> expression. Cannot
* not be NULL TRUE or FALSE litterals.
- *
+ *
* @param expr
*/
public static void checkEqualOperand(Expression expr) {
@@ -333,6 +336,7 @@ public abstract class ComparisonExpressi
}
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public Object evaluate(MessageEvaluationContext message) throws JMSException {
Comparable<Comparable> lv = (Comparable)left.evaluate(message);
if (lv == null) {
@@ -345,79 +349,120 @@ public abstract class ComparisonExpressi
return compare(lv, rv);
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
protected Boolean compare(Comparable lv, Comparable rv) {
Class<? extends Comparable> lc = lv.getClass();
Class<? extends Comparable> rc = rv.getClass();
// If the the objects are not of the same type,
// try to convert up to allow the comparison.
if (lc != rc) {
- if (lc == Byte.class) {
- if (rc == Short.class) {
- lv = Short.valueOf(((Number)lv).shortValue());
- } else if (rc == Integer.class) {
- lv = Integer.valueOf(((Number)lv).intValue());
- } else if (rc == Long.class) {
- lv = Long.valueOf(((Number)lv).longValue());
- } else if (rc == Float.class) {
- lv = new Float(((Number)lv).floatValue());
- } else if (rc == Double.class) {
- lv = new Double(((Number)lv).doubleValue());
- } else {
- return Boolean.FALSE;
- }
- } else if (lc == Short.class) {
- if (rc == Integer.class) {
- lv = Integer.valueOf(((Number)lv).intValue());
- } else if (rc == Long.class) {
- lv = Long.valueOf(((Number)lv).longValue());
- } else if (rc == Float.class) {
- lv = new Float(((Number)lv).floatValue());
- } else if (rc == Double.class) {
- lv = new Double(((Number)lv).doubleValue());
- } else {
- return Boolean.FALSE;
- }
- } else if (lc == Integer.class) {
- if (rc == Long.class) {
- lv = Long.valueOf(((Number)lv).longValue());
- } else if (rc == Float.class) {
- lv = new Float(((Number)lv).floatValue());
- } else if (rc == Double.class) {
- lv = new Double(((Number)lv).doubleValue());
- } else {
- return Boolean.FALSE;
- }
- } else if (lc == Long.class) {
- if (rc == Integer.class) {
- rv = Long.valueOf(((Number)rv).longValue());
- } else if (rc == Float.class) {
- lv = new Float(((Number)lv).floatValue());
- } else if (rc == Double.class) {
- lv = new Double(((Number)lv).doubleValue());
- } else {
- return Boolean.FALSE;
- }
- } else if (lc == Float.class) {
- if (rc == Integer.class) {
- rv = new Float(((Number)rv).floatValue());
- } else if (rc == Long.class) {
- rv = new Float(((Number)rv).floatValue());
- } else if (rc == Double.class) {
- lv = new Double(((Number)lv).doubleValue());
- } else {
- return Boolean.FALSE;
- }
- } else if (lc == Double.class) {
- if (rc == Integer.class) {
- rv = new Double(((Number)rv).doubleValue());
- } else if (rc == Long.class) {
- rv = new Double(((Number)rv).doubleValue());
- } else if (rc == Float.class) {
- rv = new Float(((Number)rv).doubleValue());
+ try {
+ if (lc == Boolean.class) {
+ if (rc == String.class) {
+ lv = Boolean.valueOf((String)lv).booleanValue();
+ } else {
+ return Boolean.FALSE;
+ }
+ } else if (lc == Byte.class) {
+ if (rc == Short.class) {
+ lv = Short.valueOf(((Number)lv).shortValue());
+ } else if (rc == Integer.class) {
+ lv = Integer.valueOf(((Number)lv).intValue());
+ } else if (rc == Long.class) {
+ lv = Long.valueOf(((Number)lv).longValue());
+ } else if (rc == Float.class) {
+ lv = new Float(((Number)lv).floatValue());
+ } else if (rc == Double.class) {
+ lv = new Double(((Number)lv).doubleValue());
+ } else if (rc == String.class) {
+ rv = Byte.valueOf((String)rv);
+ } else {
+ return Boolean.FALSE;
+ }
+ } else if (lc == Short.class) {
+ if (rc == Integer.class) {
+ lv = Integer.valueOf(((Number)lv).intValue());
+ } else if (rc == Long.class) {
+ lv = Long.valueOf(((Number)lv).longValue());
+ } else if (rc == Float.class) {
+ lv = new Float(((Number)lv).floatValue());
+ } else if (rc == Double.class) {
+ lv = new Double(((Number)lv).doubleValue());
+ } else if (rc == String.class) {
+ rv = Short.valueOf((String)rv);
+ } else {
+ return Boolean.FALSE;
+ }
+ } else if (lc == Integer.class) {
+ if (rc == Long.class) {
+ lv = Long.valueOf(((Number)lv).longValue());
+ } else if (rc == Float.class) {
+ lv = new Float(((Number)lv).floatValue());
+ } else if (rc == Double.class) {
+ lv = new Double(((Number)lv).doubleValue());
+ } else if (rc == String.class) {
+ rv = Integer.valueOf((String)rv);
+ } else {
+ return Boolean.FALSE;
+ }
+ } else if (lc == Long.class) {
+ if (rc == Integer.class) {
+ rv = Long.valueOf(((Number)rv).longValue());
+ } else if (rc == Float.class) {
+ lv = new Float(((Number)lv).floatValue());
+ } else if (rc == Double.class) {
+ lv = new Double(((Number)lv).doubleValue());
+ } else if (rc == String.class) {
+ rv = Long.valueOf((String)rv);
+ } else {
+ return Boolean.FALSE;
+ }
+ } else if (lc == Float.class) {
+ if (rc == Integer.class) {
+ rv = new Float(((Number)rv).floatValue());
+ } else if (rc == Long.class) {
+ rv = new Float(((Number)rv).floatValue());
+ } else if (rc == Double.class) {
+ lv = new Double(((Number)lv).doubleValue());
+ } else if (rc == String.class) {
+ rv = Float.valueOf((String)rv);
+ } else {
+ return Boolean.FALSE;
+ }
+ } else if (lc == Double.class) {
+ if (rc == Integer.class) {
+ rv = new Double(((Number)rv).doubleValue());
+ } else if (rc == Long.class) {
+ rv = new Double(((Number)rv).doubleValue());
+ } else if (rc == Float.class) {
+ rv = new Float(((Number)rv).doubleValue());
+ } else if (rc == String.class) {
+ rv = Double.valueOf((String)rv);
+ } else {
+ return Boolean.FALSE;
+ }
+ } else if (lc == String.class) {
+ if (rc == Boolean.class) {
+ lv = Boolean.valueOf((String)lv);
+ } else if (rc == Byte.class) {
+ lv = Byte.valueOf((String)lv);
+ } else if (rc == Short.class) {
+ lv = Short.valueOf((String)lv);
+ } else if (rc == Integer.class) {
+ lv = Integer.valueOf((String)lv);
+ } else if (rc == Long.class) {
+ lv = Long.valueOf((String)lv);
+ } else if (rc == Float.class) {
+ lv = Float.valueOf((String)lv);
+ } else if (rc == Double.class) {
+ lv = Double.valueOf((String)lv);
+ } else {
+ return Boolean.FALSE;
+ }
} else {
return Boolean.FALSE;
}
- } else {
+ } catch(NumberFormatException e) {
return Boolean.FALSE;
}
}
Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java?rev=1157433&r1=1157432&r2=1157433&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java Sat Aug 13 22:28:42 2011
@@ -574,6 +574,87 @@ public class StompTest extends Combinati
stompConnection.sendFrame(frame);
}
+ public void testSubscribeWithAutoAckAndNumericSelector() throws Exception {
+
+ String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ frame = stompConnection.receiveFrame();
+ assertTrue(frame.startsWith("CONNECTED"));
+
+ frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "selector: foo = 42\n" + "ack:auto\n\n" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ // Ignored
+ frame = "SEND\n" + "foo:abc\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Ignored Message" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ // Matches
+ frame = "SEND\n" + "foo:42\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Real Message" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ frame = stompConnection.receiveFrame();
+ assertTrue(frame.startsWith("MESSAGE"));
+ assertTrue("Should have received the real message but got: " + frame, frame.indexOf("Real Message") > 0);
+
+ frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+ }
+
+ public void testSubscribeWithAutoAckAndBooleanSelector() throws Exception {
+
+ String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ frame = stompConnection.receiveFrame();
+ assertTrue(frame.startsWith("CONNECTED"));
+
+ frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "selector: foo = true\n" + "ack:auto\n\n" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ // Ignored
+ frame = "SEND\n" + "foo:false\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Ignored Message" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ // Matches
+ frame = "SEND\n" + "foo:true\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Real Message" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ frame = stompConnection.receiveFrame();
+ assertTrue(frame.startsWith("MESSAGE"));
+ assertTrue("Should have received the real message but got: " + frame, frame.indexOf("Real Message") > 0);
+
+ frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+ }
+
+ public void testSubscribeWithAutoAckAnFloatSelector() throws Exception {
+
+ String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ frame = stompConnection.receiveFrame();
+ assertTrue(frame.startsWith("CONNECTED"));
+
+ frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "selector: foo = 3.14159\n" + "ack:auto\n\n" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ // Ignored
+ frame = "SEND\n" + "foo:6.578\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Ignored Message" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ // Matches
+ frame = "SEND\n" + "foo:3.14159\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Real Message" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ frame = stompConnection.receiveFrame();
+ assertTrue(frame.startsWith("MESSAGE"));
+ assertTrue("Should have received the real message but got: " + frame, frame.indexOf("Real Message") > 0);
+
+ frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+ }
+
public void testSubscribeWithClientAck() throws Exception {
String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;