Skip to content

Commit 789de05

Browse files
committed
temp
1 parent ceaa881 commit 789de05

2 files changed

Lines changed: 69 additions & 22 deletions

File tree

tests/integration-tests/pom.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -369,20 +369,6 @@
369369
<scope>test</scope>
370370
</dependency>
371371

372-
<!-- need this for org.apache.activemq.filter.JAXPXPathEvaluator for Xpath selectors with OpenWire JMS clients-->
373-
<dependency>
374-
<groupId>org.apache.activemq</groupId>
375-
<artifactId>activemq-broker</artifactId>
376-
<version>${activemq5-version}</version>
377-
<scope>test</scope>
378-
<exclusions>
379-
<exclusion>
380-
<groupId>com.fasterxml.jackson.core</groupId>
381-
<artifactId>jackson-databind</artifactId>
382-
</exclusion>
383-
</exclusions>
384-
</dependency>
385-
386372
<dependency>
387373
<groupId>org.codehaus.woodstox</groupId>
388374
<artifactId>woodstox-core-asl</artifactId>

tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSXPathSelectorTest.java

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
import static org.junit.jupiter.api.Assertions.assertNotNull;
2121
import static org.junit.jupiter.api.Assertions.assertNull;
2222

23-
import javax.jms.Connection;
24-
import javax.jms.JMSException;
25-
import javax.jms.Message;
26-
import javax.jms.MessageConsumer;
27-
import javax.jms.MessageProducer;
28-
import javax.jms.Queue;
29-
import javax.jms.Session;
30-
import javax.jms.TextMessage;
23+
import javax.jms.*;
24+
import javax.xml.parsers.DocumentBuilder;
25+
import javax.xml.xpath.XPath;
26+
import javax.xml.xpath.XPathConstants;
27+
import javax.xml.xpath.XPathFactory;
28+
import java.io.ByteArrayInputStream;
29+
import java.io.StringReader;
3130
import java.net.URI;
3231

3332
import org.apache.activemq.artemis.api.core.QueueConfiguration;
@@ -36,7 +35,10 @@
3635
import org.apache.activemq.artemis.core.server.ActiveMQServer;
3736
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
3837
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
38+
import org.apache.activemq.filter.XPathExpression;
3939
import org.junit.jupiter.api.Test;
40+
import org.w3c.dom.Document;
41+
import org.xml.sax.InputSource;
4042

4143
public class JMSXPathSelectorTest extends MultiprotocolJMSClientTestSupport {
4244

@@ -55,6 +57,9 @@ protected URI getBrokerQpidJMSConnectionURI() {
5557
protected void addConfiguration(ActiveMQServer server) {
5658
server.getConfiguration().setPersistenceEnabled(false);
5759
server.getAddressSettingsRepository().addMatch(NORMAL_QUEUE_NAME, new AddressSettings());
60+
61+
//<!-- need this for org.apache.activemq.filter.JAXPXPathEvaluator for Xpath selectors with OpenWire JMS clients-->
62+
System.setProperty("org.apache.activemq.XPathEvaluatorClassName", "org.apache.activemq.artemis.tests.integration.jms.multiprotocol.JMSXPathSelectorTest$JAXPXPathEvaluator");
5863
}
5964

6065
@Override
@@ -154,4 +159,60 @@ private void sendMessage(ConnectionSupplier producerConnectionSupplier, String q
154159
p.send(queue1, message2, deliveryMode, priority, timeToLive);
155160
}
156161
}
162+
163+
public static class JAXPXPathEvaluator implements XPathExpression.XPathEvaluator {
164+
165+
private static final XPathFactory FACTORY = XPathFactory.newInstance();
166+
private final String xpathExpression;
167+
private final DocumentBuilder builder;
168+
private final XPath xpath = FACTORY.newXPath();
169+
170+
public JAXPXPathEvaluator(String xpathExpression, DocumentBuilder builder) throws Exception {
171+
this.xpathExpression = xpathExpression;
172+
if (builder != null) {
173+
this.builder = builder;
174+
} else {
175+
throw new RuntimeException("No document builder available");
176+
}
177+
}
178+
179+
@Override
180+
public boolean evaluate(org.apache.activemq.command.Message message) throws JMSException {
181+
if (message instanceof TextMessage) {
182+
String text = ((TextMessage)message).getText();
183+
return evaluate(text);
184+
} else if (message instanceof BytesMessage) {
185+
BytesMessage bm = (BytesMessage)message;
186+
byte data[] = new byte[(int)bm.getBodyLength()];
187+
bm.readBytes(data);
188+
return evaluate(data);
189+
}
190+
return false;
191+
}
192+
193+
private boolean evaluate(byte[] data) {
194+
try {
195+
InputSource inputSource = new InputSource(new ByteArrayInputStream(data));
196+
Document inputDocument = builder.parse(inputSource);
197+
return (Boolean) xpath.evaluate(xpathExpression, inputDocument, XPathConstants.BOOLEAN);
198+
} catch (Exception e) {
199+
return false;
200+
}
201+
}
202+
203+
private boolean evaluate(String text) {
204+
try {
205+
InputSource inputSource = new InputSource(new StringReader(text));
206+
Document inputDocument = builder.parse(inputSource);
207+
return (Boolean) xpath.evaluate(xpathExpression, inputDocument, XPathConstants.BOOLEAN);
208+
} catch (Exception e) {
209+
return false;
210+
}
211+
}
212+
213+
@Override
214+
public String toString() {
215+
return xpathExpression;
216+
}
217+
}
157218
}

0 commit comments

Comments
 (0)