[ 
https://issues.apache.org/jira/browse/ARTEMIS-3137?focusedWorklogId=557857&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-557857
 ]

ASF GitHub Bot logged work on ARTEMIS-3137:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 25/Feb/21 11:03
            Start Date: 25/Feb/21 11:03
    Worklog Time Spent: 10m 
      Work Description: gemmellr commented on a change in pull request #3466:
URL: https://github.com/apache/activemq-artemis/pull/3466#discussion_r582717325



##########
File path: 
artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/XPathExpression.java
##########
@@ -79,4 +97,15 @@ public boolean matches(Filterable message) throws 
FilterException {
       return object == Boolean.TRUE;
    }
 
+   protected static void setupFeatures(DocumentBuilderFactory factory) throws 
ParserConfigurationException {
+      Properties properties = System.getProperties();
+      for (Map.Entry<Object, Object> prop : properties.entrySet()) {
+         String key = (String) prop.getKey();
+         if (key.startsWith(DOCUMENT_BUILDER_FACTORY_FEATURE)) {
+            String uri = key.split(DOCUMENT_BUILDER_FACTORY_FEATURE + ":")[1];

Review comment:
       Shouldnt it check if key.startsWith(DOCUMENT_BUILDER_FACTORY_FEATURE + 
":") since thats the documented prefix and what it then splits on? Also, it 
would seem simpler and nicer to just use key.substring(<prefix length>) rather 
than split.

##########
File path: 
artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/JAXPXPathEvaluator.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.artemis.selector.filter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+import java.io.StringReader;
+
+import org.xml.sax.InputSource;
+
+public class JAXPXPathEvaluator implements XPathExpression.XPathEvaluator {
+
+   private static final XPathFactory FACTORY = XPathFactory.newInstance();

Review comment:
       I notice the javadoc for XPathFactory explicitly notes it isnt 
thread-safe and recommends synchronization to protect uses of the factory. It 
seems like instances of this JAXPXPathEvaluator class might get created by 
multiple threads, and if so in turn the factory could be used concurrently.
   
   I dont know what the actual impact would be with just uses of .newXPath(), 
but perhaps worth looking into.

##########
File path: 
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMSXPathSelectorTest.java
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.artemis.tests.integration.amqp;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import java.net.URI;
+
+import org.apache.activemq.artemis.api.core.QueueConfiguration;
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.impl.AddressInfo;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.junit.Test;
+
+public class JMSXPathSelectorTest extends JMSClientTestSupport {
+
+   private static final String NORMAL_QUEUE_NAME = "NORMAL";
+
+   private ConnectionSupplier AMQPConnection = () -> createConnection();
+   private ConnectionSupplier CoreConnection = () -> createCoreConnection();
+   private ConnectionSupplier OpenWireConnection = () -> 
createOpenWireConnection();
+
+   @Override
+   protected String getConfiguredProtocols() {
+      return "AMQP,OPENWIRE,CORE";
+   }
+
+   @Override
+   protected URI getBrokerQpidJMSConnectionURI() {
+      try {
+         return new URI(getBrokerQpidJMSConnectionString() + 
"?jms.validateSelector=false");
+      } catch (Exception e) {
+         throw new RuntimeException();
+      }
+   }
+
+   @Override
+   protected void addConfiguration(ActiveMQServer server) {
+      server.getConfiguration().setPersistenceEnabled(false);
+      server.getAddressSettingsRepository().addMatch(NORMAL_QUEUE_NAME, new 
AddressSettings());
+   }
+
+   @Override
+   protected void createAddressAndQueues(ActiveMQServer server) throws 
Exception {
+      super.createAddressAndQueues(server);
+
+      //Add Standard Queue
+      server.addAddressInfo(new 
AddressInfo(SimpleString.toSimpleString(NORMAL_QUEUE_NAME), 
RoutingType.ANYCAST));
+      server.createQueue(new 
QueueConfiguration(NORMAL_QUEUE_NAME).setRoutingType(RoutingType.ANYCAST));
+   }
+
+   @Test
+   public void testJMSSelectorsAMQPProducerAMQPConsumer() throws Exception {
+      testJMSSelectors(AMQPConnection, AMQPConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsCoreProducerCoreConsumer() throws Exception {

Review comment:
       Isnt this essentially a duplicate, with the test in the ConsumerTest 
class?

##########
File path: 
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMSXPathSelectorTest.java
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.artemis.tests.integration.amqp;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import java.net.URI;
+
+import org.apache.activemq.artemis.api.core.QueueConfiguration;
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.impl.AddressInfo;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.junit.Test;
+
+public class JMSXPathSelectorTest extends JMSClientTestSupport {
+
+   private static final String NORMAL_QUEUE_NAME = "NORMAL";
+
+   private ConnectionSupplier AMQPConnection = () -> createConnection();
+   private ConnectionSupplier CoreConnection = () -> createCoreConnection();
+   private ConnectionSupplier OpenWireConnection = () -> 
createOpenWireConnection();
+
+   @Override
+   protected String getConfiguredProtocols() {
+      return "AMQP,OPENWIRE,CORE";
+   }
+
+   @Override
+   protected URI getBrokerQpidJMSConnectionURI() {
+      try {
+         return new URI(getBrokerQpidJMSConnectionString() + 
"?jms.validateSelector=false");
+      } catch (Exception e) {
+         throw new RuntimeException();
+      }
+   }
+
+   @Override
+   protected void addConfiguration(ActiveMQServer server) {
+      server.getConfiguration().setPersistenceEnabled(false);
+      server.getAddressSettingsRepository().addMatch(NORMAL_QUEUE_NAME, new 
AddressSettings());
+   }
+
+   @Override
+   protected void createAddressAndQueues(ActiveMQServer server) throws 
Exception {
+      super.createAddressAndQueues(server);
+
+      //Add Standard Queue
+      server.addAddressInfo(new 
AddressInfo(SimpleString.toSimpleString(NORMAL_QUEUE_NAME), 
RoutingType.ANYCAST));
+      server.createQueue(new 
QueueConfiguration(NORMAL_QUEUE_NAME).setRoutingType(RoutingType.ANYCAST));
+   }
+
+   @Test
+   public void testJMSSelectorsAMQPProducerAMQPConsumer() throws Exception {
+      testJMSSelectors(AMQPConnection, AMQPConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsCoreProducerCoreConsumer() throws Exception {
+      testJMSSelectors(CoreConnection, CoreConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsCoreProducerAMQPConsumer() throws Exception {
+      testJMSSelectors(CoreConnection, AMQPConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsAMQPProducerCoreConsumer() throws Exception {
+      testJMSSelectors(AMQPConnection, CoreConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsOpenWireProducerOpenWireConsumer() throws 
Exception {
+      testJMSSelectors(OpenWireConnection, OpenWireConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsCoreProducerOpenWireConsumer() throws Exception 
{
+      testJMSSelectors(CoreConnection, OpenWireConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsOpenWireProducerCoreConsumer() throws Exception 
{
+      testJMSSelectors(OpenWireConnection, CoreConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsAMQPProducerOpenWireConsumer() throws Exception 
{
+      testJMSSelectors(AMQPConnection, OpenWireConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsOpenWireProducerAMQPConsumer() throws Exception 
{
+      testJMSSelectors(OpenWireConnection, AMQPConnection);
+   }
+
+   public void testJMSSelectors(ConnectionSupplier producerConnectionSupplier, 
ConnectionSupplier consumerConnectionSupplier) throws Exception {
+      testJMSSelector(producerConnectionSupplier, consumerConnectionSupplier, 
NORMAL_QUEUE_NAME, "<root><a key='first' num='1'/><b key='second' 
num='2'>b</b></root>", "XPATH 'root/a'");
+   }
+
+   public void testJMSSelector(ConnectionSupplier producerConnectionSupplier, 
ConnectionSupplier consumerConnectionSupplier, String queueName, String body, 
String selector) throws Exception {
+      testJMSSelector(producerConnectionSupplier, consumerConnectionSupplier, 
queueName, body, selector, Message.DEFAULT_DELIVERY_MODE, 
Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+   }
+
+   public void testJMSSelector(ConnectionSupplier producerConnectionSupplier, 
ConnectionSupplier consumerConnectionSupplier, String queueName, String body, 
String selector, int deliveryMode, int priority, long timeToLive) throws 
Exception {
+      sendMessage(producerConnectionSupplier, queueName, body, deliveryMode, 
priority, timeToLive);
+      receive(consumerConnectionSupplier, queueName, body, selector);
+   }
+
+   private void receive(ConnectionSupplier consumerConnectionSupplier, String 
queueName, String body, String selector) throws JMSException {
+      try (Connection consumerConnection = 
consumerConnectionSupplier.createConnection()) {
+         Session consumerSession = consumerConnection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+         Queue consumerQueue = consumerSession.createQueue(queueName);
+         MessageConsumer consumer = 
consumerSession.createConsumer(consumerQueue, selector);
+         TextMessage msg = (TextMessage) consumer.receive(1000);
+         assertNotNull(msg);
+         assertEquals(body, msg.getText());
+         assertNull(consumer.receiveNoWait());
+         consumer.close();
+      }
+   }
+
+   private void sendMessage(ConnectionSupplier producerConnectionSupplier, 
String queueName, String body, int deliveryMode, int priority, long timeToLive) 
throws JMSException {
+      try (Connection producerConnection = 
producerConnectionSupplier.createConnection()) {
+         Session producerSession = producerConnection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+         Queue queue1 = producerSession.createQueue(queueName);
+         MessageProducer p = producerSession.createProducer(null);
+
+         TextMessage message1 = producerSession.createTextMessage();
+         message1.setText("hello");

Review comment:
       Might it be a fuller test to also send a 'complex' message that doesnt 
entirely match the filter, but at least begins to...e.g the filter matches on 
element root/a, and the tests send an a message with root/a and root/b...send 
another with e.g just root/z?

##########
File path: 
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMSXPathSelectorTest.java
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.artemis.tests.integration.amqp;

Review comment:
       The crossprotocol package might be better than the amqp one, given what 
all is being tested? Alternatively, even a new specific package might be best 
since its more of an internal feature-specific test rather than to do with any 
given protocol.

##########
File path: 
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMSXPathSelectorTest.java
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.artemis.tests.integration.amqp;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import java.net.URI;
+
+import org.apache.activemq.artemis.api.core.QueueConfiguration;
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.impl.AddressInfo;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.junit.Test;
+
+public class JMSXPathSelectorTest extends JMSClientTestSupport {
+
+   private static final String NORMAL_QUEUE_NAME = "NORMAL";
+
+   private ConnectionSupplier AMQPConnection = () -> createConnection();
+   private ConnectionSupplier CoreConnection = () -> createCoreConnection();
+   private ConnectionSupplier OpenWireConnection = () -> 
createOpenWireConnection();
+
+   @Override
+   protected String getConfiguredProtocols() {
+      return "AMQP,OPENWIRE,CORE";
+   }
+
+   @Override
+   protected URI getBrokerQpidJMSConnectionURI() {
+      try {
+         return new URI(getBrokerQpidJMSConnectionString() + 
"?jms.validateSelector=false");
+      } catch (Exception e) {
+         throw new RuntimeException();
+      }
+   }
+
+   @Override
+   protected void addConfiguration(ActiveMQServer server) {
+      server.getConfiguration().setPersistenceEnabled(false);
+      server.getAddressSettingsRepository().addMatch(NORMAL_QUEUE_NAME, new 
AddressSettings());
+   }
+
+   @Override
+   protected void createAddressAndQueues(ActiveMQServer server) throws 
Exception {
+      super.createAddressAndQueues(server);
+
+      //Add Standard Queue
+      server.addAddressInfo(new 
AddressInfo(SimpleString.toSimpleString(NORMAL_QUEUE_NAME), 
RoutingType.ANYCAST));
+      server.createQueue(new 
QueueConfiguration(NORMAL_QUEUE_NAME).setRoutingType(RoutingType.ANYCAST));
+   }
+
+   @Test
+   public void testJMSSelectorsAMQPProducerAMQPConsumer() throws Exception {
+      testJMSSelectors(AMQPConnection, AMQPConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsCoreProducerCoreConsumer() throws Exception {
+      testJMSSelectors(CoreConnection, CoreConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsCoreProducerAMQPConsumer() throws Exception {
+      testJMSSelectors(CoreConnection, AMQPConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsAMQPProducerCoreConsumer() throws Exception {
+      testJMSSelectors(AMQPConnection, CoreConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsOpenWireProducerOpenWireConsumer() throws 
Exception {
+      testJMSSelectors(OpenWireConnection, OpenWireConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsCoreProducerOpenWireConsumer() throws Exception 
{
+      testJMSSelectors(CoreConnection, OpenWireConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsOpenWireProducerCoreConsumer() throws Exception 
{
+      testJMSSelectors(OpenWireConnection, CoreConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsAMQPProducerOpenWireConsumer() throws Exception 
{
+      testJMSSelectors(AMQPConnection, OpenWireConnection);
+   }
+
+   @Test
+   public void testJMSSelectorsOpenWireProducerAMQPConsumer() throws Exception 
{
+      testJMSSelectors(OpenWireConnection, AMQPConnection);
+   }
+
+   public void testJMSSelectors(ConnectionSupplier producerConnectionSupplier, 
ConnectionSupplier consumerConnectionSupplier) throws Exception {
+      testJMSSelector(producerConnectionSupplier, consumerConnectionSupplier, 
NORMAL_QUEUE_NAME, "<root><a key='first' num='1'/><b key='second' 
num='2'>b</b></root>", "XPATH 'root/a'");
+   }
+
+   public void testJMSSelector(ConnectionSupplier producerConnectionSupplier, 
ConnectionSupplier consumerConnectionSupplier, String queueName, String body, 
String selector) throws Exception {
+      testJMSSelector(producerConnectionSupplier, consumerConnectionSupplier, 
queueName, body, selector, Message.DEFAULT_DELIVERY_MODE, 
Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+   }
+
+   public void testJMSSelector(ConnectionSupplier producerConnectionSupplier, 
ConnectionSupplier consumerConnectionSupplier, String queueName, String body, 
String selector, int deliveryMode, int priority, long timeToLive) throws 
Exception {
+      sendMessage(producerConnectionSupplier, queueName, body, deliveryMode, 
priority, timeToLive);
+      receive(consumerConnectionSupplier, queueName, body, selector);
+   }
+
+   private void receive(ConnectionSupplier consumerConnectionSupplier, String 
queueName, String body, String selector) throws JMSException {
+      try (Connection consumerConnection = 
consumerConnectionSupplier.createConnection()) {
+         Session consumerSession = consumerConnection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+         Queue consumerQueue = consumerSession.createQueue(queueName);
+         MessageConsumer consumer = 
consumerSession.createConsumer(consumerQueue, selector);
+         TextMessage msg = (TextMessage) consumer.receive(1000);
+         assertNotNull(msg);
+         assertEquals(body, msg.getText());
+         assertNull(consumer.receiveNoWait());
+         consumer.close();
+      }
+   }
+
+   private void sendMessage(ConnectionSupplier producerConnectionSupplier, 
String queueName, String body, int deliveryMode, int priority, long timeToLive) 
throws JMSException {
+      try (Connection producerConnection = 
producerConnectionSupplier.createConnection()) {
+         Session producerSession = producerConnection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+         Queue queue1 = producerSession.createQueue(queueName);
+         MessageProducer p = producerSession.createProducer(null);
+
+         TextMessage message1 = producerSession.createTextMessage();
+         message1.setText("hello");
+         p.send(queue1, message1);
+
+         TextMessage message2 = producerSession.createTextMessage();
+         if (body != null) {

Review comment:
       Is this needed? Setting null text is allowed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 557857)
    Time Spent: 2h  (was: 1h 50m)

> Support XPath filters
> ---------------------
>
>                 Key: ARTEMIS-3137
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-3137
>             Project: ActiveMQ Artemis
>          Issue Type: New Feature
>            Reporter: Justin Bertram
>            Assignee: Justin Bertram
>            Priority: Major
>          Time Spent: 2h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to