Skip to content

Commit 36d29c1

Browse files
committed
temp
1 parent ceaa881 commit 36d29c1

2 files changed

Lines changed: 69 additions & 14 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.jupiter.api.Assertions.assertNotNull;
2121
import static org.junit.jupiter.api.Assertions.assertNull;
2222

23+
import javax.jms.BytesMessage;
2324
import javax.jms.Connection;
2425
import javax.jms.JMSException;
2526
import javax.jms.Message;
@@ -28,6 +29,12 @@
2829
import javax.jms.Queue;
2930
import javax.jms.Session;
3031
import javax.jms.TextMessage;
32+
import javax.xml.parsers.DocumentBuilder;
33+
import javax.xml.xpath.XPath;
34+
import javax.xml.xpath.XPathConstants;
35+
import javax.xml.xpath.XPathFactory;
36+
import java.io.ByteArrayInputStream;
37+
import java.io.StringReader;
3138
import java.net.URI;
3239

3340
import org.apache.activemq.artemis.api.core.QueueConfiguration;
@@ -36,7 +43,10 @@
3643
import org.apache.activemq.artemis.core.server.ActiveMQServer;
3744
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
3845
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
46+
import org.apache.activemq.filter.XPathExpression;
3947
import org.junit.jupiter.api.Test;
48+
import org.w3c.dom.Document;
49+
import org.xml.sax.InputSource;
4050

4151
public class JMSXPathSelectorTest extends MultiprotocolJMSClientTestSupport {
4252

@@ -55,6 +65,9 @@ protected URI getBrokerQpidJMSConnectionURI() {
5565
protected void addConfiguration(ActiveMQServer server) {
5666
server.getConfiguration().setPersistenceEnabled(false);
5767
server.getAddressSettingsRepository().addMatch(NORMAL_QUEUE_NAME, new AddressSettings());
68+
69+
//<!-- need this for org.apache.activemq.filter.JAXPXPathEvaluator for Xpath selectors with OpenWire JMS clients-->
70+
System.setProperty("org.apache.activemq.XPathEvaluatorClassName", "org.apache.activemq.artemis.tests.integration.jms.multiprotocol.JMSXPathSelectorTest$JAXPXPathEvaluator");
5871
}
5972

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

0 commit comments

Comments
 (0)