activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1430883 - in /activemq/activemq-apollo/trunk: apollo-selector/src/main/java/org/apache/activemq/apollo/selector/ apollo-selector/src/main/javacc/ apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/ apollo-stomp/src/test/scala/org...
Date Wed, 09 Jan 2013 15:25:03 GMT
Author: chirino
Date: Wed Jan  9 15:25:03 2013
New Revision: 1430883

URL: http://svn.apache.org/viewvc?rev=1430883&view=rev
Log:
Fixes regression in APLO-283: Selectors on message properties with a hyphen in the name don't
work (anymore) with STOMP

Added:
    activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/SelectorParser.java
    activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/HyphenatedParser.jj
      - copied, changed from r1430460, activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj
    activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/StrictParser.jj
      - copied, changed from r1430460, activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj
Removed:
    activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj
Modified:
    activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
    activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompParallelTest.scala

Added: activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/SelectorParser.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/SelectorParser.java?rev=1430883&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/SelectorParser.java
(added)
+++ activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/selector/SelectorParser.java
Wed Jan  9 15:25:03 2013
@@ -0,0 +1,88 @@
+/**
+ * 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.apollo.selector;
+
+import org.apache.activemq.apollo.filter.BooleanExpression;
+import org.apache.activemq.apollo.filter.ComparisonExpression;
+import org.apache.activemq.apollo.filter.FilterException;
+import org.apache.activemq.apollo.selector.hyphenated.HyphenatedParser;
+import org.apache.activemq.apollo.selector.strict.StrictParser;
+
+import java.io.StringReader;
+
+/**
+ */
+public class SelectorParser {
+
+    private static final LRUCache cache = new LRUCache(100);
+    private static final String CONVERT_STRING_EXPRESSIONS_PREFIX = "convert_string_expressions:";
+    private static final String HYPHENATED_PROPS_PREFIX = "hyphenated_props:";
+
+    public static BooleanExpression parse(String sql) throws FilterException {
+        Object result = cache.get(sql);
+        if (result instanceof FilterException) {
+            throw (FilterException) result;
+        } else if (result instanceof BooleanExpression) {
+            return (BooleanExpression) result;
+        } else {
+            String actual = sql;
+            boolean convertStringExpressions = false;
+            boolean hyphenatedProps=false;
+            while(true) {
+              if( actual.startsWith(CONVERT_STRING_EXPRESSIONS_PREFIX)) {
+                  convertStringExpressions = true;
+                  actual = actual.substring(CONVERT_STRING_EXPRESSIONS_PREFIX.length());
+                  continue;
+              }
+              if( actual.startsWith(HYPHENATED_PROPS_PREFIX)) {
+                  hyphenatedProps = true;
+                  actual = actual.substring(HYPHENATED_PROPS_PREFIX.length());
+                  continue;
+              }
+              break;
+            }
+
+            if( convertStringExpressions ) {
+                ComparisonExpression.CONVERT_STRING_EXPRESSIONS.set(true);
+            }
+            try {
+                BooleanExpression e = null;
+                if( hyphenatedProps ) {
+                    HyphenatedParser parser = new HyphenatedParser(new StringReader(actual));
+                    e = parser.JmsSelector();
+                } else {
+                    StrictParser parser = new StrictParser(new StringReader(actual));
+                    e = parser.JmsSelector();
+                }
+                cache.put(sql, e);
+                return e;
+            } catch (Throwable e) {
+                FilterException fe = new FilterException(actual, e);
+                cache.put(sql, fe);
+                throw fe;
+            } finally {
+                if( convertStringExpressions ) {
+                    ComparisonExpression.CONVERT_STRING_EXPRESSIONS.remove();
+                }
+            }
+        }
+    }
+
+    public static void clearCache() {
+        cache.clear();
+    }
+}

Copied: activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/HyphenatedParser.jj
(from r1430460, activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj)
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/HyphenatedParser.jj?p2=activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/HyphenatedParser.jj&p1=activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj&r1=1430460&r2=1430883&rev=1430883&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj (original)
+++ activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/HyphenatedParser.jj Wed
Jan  9 15:25:03 2013
@@ -29,7 +29,7 @@ options {
 // PARSER
 // ----------------------------------------------------------------------------
 
-PARSER_BEGIN(SelectorParser)
+PARSER_BEGIN(HyphenatedParser)
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -47,7 +47,7 @@ PARSER_BEGIN(SelectorParser)
  * limitations under the License.
  */
 
-package org.apache.activemq.apollo.selector;
+package org.apache.activemq.apollo.selector.hyphenated;
 
 import java.io.*;
 import java.util.*;
@@ -57,65 +57,9 @@ import org.apache.activemq.apollo.filter
 /** 
  * JMS Selector Parser generated by JavaCC
  * 
- * Do not edit this .java file directly - it is autogenerated from SelectorParser.jj
+ * Do not edit this .java file directly - it is autogenerated from HyphenatedParser.jj
  */
-public class SelectorParser {
-
-    private static final LRUCache cache = new LRUCache(100);
-    private static final String CONVERT_STRING_EXPRESSIONS_PREFIX = "convert_string_expressions:";
-
-    public static BooleanExpression parse(String sql) throws FilterException {
-        Object result = cache.get(sql);
-        if (result instanceof FilterException) {
-            throw (FilterException) result;
-        } else if (result instanceof BooleanExpression) {
-            return (BooleanExpression) result;
-        } else {
-
-            boolean convertStringExpressions = false;
-            if( sql.startsWith(CONVERT_STRING_EXPRESSIONS_PREFIX)) {
-                convertStringExpressions = true;
-                sql = sql.substring(CONVERT_STRING_EXPRESSIONS_PREFIX.length());
-            }
-
-            if( convertStringExpressions ) {
-                ComparisonExpression.CONVERT_STRING_EXPRESSIONS.set(true);
-            }
-            try {
-                BooleanExpression e = new SelectorParser(sql).parse();
-                cache.put(sql, e);
-                return e;
-            } catch (FilterException t) {
-                cache.put(sql, t);
-                throw t;
-            } finally {
-                if( convertStringExpressions ) {
-                    ComparisonExpression.CONVERT_STRING_EXPRESSIONS.remove();
-                }
-            }
-        }
-    }
-
-    public static void clearCache() {
-        cache.clear();
-    }
-
-    private String sql;
-
-    protected SelectorParser(String sql) {
-        this(new StringReader(sql));
-        this.sql = sql;
-    }
-
-    protected BooleanExpression parse() throws FilterException {
-        try {
-            return this.JmsSelector();
-        }
-        catch (Throwable e) {
-            throw new FilterException(sql, e);
-        }
-    }
-
+public class HyphenatedParser {
     private BooleanExpression asBooleanExpression(Expression value) throws ParseException
 {
         if (value instanceof BooleanExpression) {
             return (BooleanExpression) value;
@@ -125,11 +69,9 @@ public class SelectorParser {
         }
         throw new ParseException("Expression will not result in a boolean value: " + value);
     }
-    
-
 }
 
-PARSER_END(SelectorParser)
+PARSER_END(HyphenatedParser)
 
 // ----------------------------------------------------------------------------
 // Tokens
@@ -188,7 +130,7 @@ TOKEN [IGNORE_CASE] :
 
 TOKEN [IGNORE_CASE] :
 {
-    < ID : ["a"-"z", "_", "$"] (["a"-"z","0"-"9","_", "$"])* >
+    < ID : ["a"-"z", "_", "$"] (["a"-"z","0"-"9","_", "$", "-"])* >
 }
 
 // ----------------------------------------------------------------------------
@@ -609,11 +551,11 @@ PropertyExpression variable() :
     PropertyExpression left=null;
 }
 {
-    ( 
-        t = <ID> 
+    (
+        t=<ID>
         {
             left = new PropertyExpression(t.image);
-        }    
+        }
     )
     {
         return left;

Copied: activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/StrictParser.jj (from
r1430460, activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj)
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/StrictParser.jj?p2=activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/StrictParser.jj&p1=activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj&r1=1430460&r2=1430883&rev=1430883&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj (original)
+++ activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/StrictParser.jj Wed Jan
 9 15:25:03 2013
@@ -29,7 +29,7 @@ options {
 // PARSER
 // ----------------------------------------------------------------------------
 
-PARSER_BEGIN(SelectorParser)
+PARSER_BEGIN(StrictParser)
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -47,7 +47,7 @@ PARSER_BEGIN(SelectorParser)
  * limitations under the License.
  */
 
-package org.apache.activemq.apollo.selector;
+package org.apache.activemq.apollo.selector.strict;
 
 import java.io.*;
 import java.util.*;
@@ -57,65 +57,9 @@ import org.apache.activemq.apollo.filter
 /** 
  * JMS Selector Parser generated by JavaCC
  * 
- * Do not edit this .java file directly - it is autogenerated from SelectorParser.jj
+ * Do not edit this .java file directly - it is autogenerated from StrictParser.jj
  */
-public class SelectorParser {
-
-    private static final LRUCache cache = new LRUCache(100);
-    private static final String CONVERT_STRING_EXPRESSIONS_PREFIX = "convert_string_expressions:";
-
-    public static BooleanExpression parse(String sql) throws FilterException {
-        Object result = cache.get(sql);
-        if (result instanceof FilterException) {
-            throw (FilterException) result;
-        } else if (result instanceof BooleanExpression) {
-            return (BooleanExpression) result;
-        } else {
-
-            boolean convertStringExpressions = false;
-            if( sql.startsWith(CONVERT_STRING_EXPRESSIONS_PREFIX)) {
-                convertStringExpressions = true;
-                sql = sql.substring(CONVERT_STRING_EXPRESSIONS_PREFIX.length());
-            }
-
-            if( convertStringExpressions ) {
-                ComparisonExpression.CONVERT_STRING_EXPRESSIONS.set(true);
-            }
-            try {
-                BooleanExpression e = new SelectorParser(sql).parse();
-                cache.put(sql, e);
-                return e;
-            } catch (FilterException t) {
-                cache.put(sql, t);
-                throw t;
-            } finally {
-                if( convertStringExpressions ) {
-                    ComparisonExpression.CONVERT_STRING_EXPRESSIONS.remove();
-                }
-            }
-        }
-    }
-
-    public static void clearCache() {
-        cache.clear();
-    }
-
-    private String sql;
-
-    protected SelectorParser(String sql) {
-        this(new StringReader(sql));
-        this.sql = sql;
-    }
-
-    protected BooleanExpression parse() throws FilterException {
-        try {
-            return this.JmsSelector();
-        }
-        catch (Throwable e) {
-            throw new FilterException(sql, e);
-        }
-    }
-
+public class StrictParser {
     private BooleanExpression asBooleanExpression(Expression value) throws ParseException
 {
         if (value instanceof BooleanExpression) {
             return (BooleanExpression) value;
@@ -125,11 +69,9 @@ public class SelectorParser {
         }
         throw new ParseException("Expression will not result in a boolean value: " + value);
     }
-    
-
 }
 
-PARSER_END(SelectorParser)
+PARSER_END(StrictParser)
 
 // ----------------------------------------------------------------------------
 // Tokens
@@ -609,11 +551,11 @@ PropertyExpression variable() :
     PropertyExpression left=null;
 }
 {
-    ( 
-        t = <ID> 
+    (
+        t=<ID>
         {
             left = new PropertyExpression(t.image);
-        }    
+        }
     )
     {
         return left;

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala?rev=1430883&r1=1430882&r2=1430883&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
Wed Jan  9 15:25:03 2013
@@ -1409,8 +1409,8 @@ class StompProtocolHandler extends Proto
       case None=> null
       case Some(x)=>
         try {
-          val s = decode_header(x)
-          (s, SelectorParser.parse("convert_string_expressions:"+s))
+          val s = "convert_string_expressions:hyphenated_props:"+decode_header(x)
+          (s, SelectorParser.parse(s))
         } catch {
           case e:FilterException =>
             die("Invalid selector expression: "+e.getMessage)

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompParallelTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompParallelTest.scala?rev=1430883&r1=1430882&r2=1430883&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompParallelTest.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompParallelTest.scala
Wed Jan  9 15:25:03 2013
@@ -553,9 +553,10 @@ class StompParallelTest extends StompTes
     }
 
     test_selector("color = 'red'", List("color:blue", "not:set", "color:red"), List(3))
-    test_selector("hyphen-5 = 5", List("hyphen:9", "not:set", "hyphen:10"), List(3))
     test_selector("age >= 21", List("age:3", "not:set", "age:21", "age:30"), List(3, 4))
-
+    test_selector("hyphen - 5 = 5", List("hyphen:9", "not:set", "hyphen:10"), List(3))
+    test_selector("hyphen -5 = 5", List("hyphen:9", "not:set", "hyphen:10"), List(3))
+    test_selector("hyphen-5 = 5", List("hyphen:9", "hyphen-5:5", "not:set", "hyphen:10"),
List(2))
   }
 
   test("Queues load balance across subscribers") {



Mime
View raw message