Skip to content

Commit 2da9087

Browse files
committed
update to use a broker.xml configuration
1 parent d8dbc40 commit 2da9087

File tree

3 files changed

+59
-10
lines changed

3 files changed

+59
-10
lines changed

cwms-data-api/src/main/java/cwms/cda/api/messaging/CamelServletContextListener.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@
2424

2525
package cwms.cda.api.messaging;
2626

27+
import hec.io.FilePath;
28+
import hec.io.HecFileImpl;
29+
import hec.util.XMLUtilities;
2730
import oracle.jms.AQjmsFactory;
2831
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
32+
import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
2933
import org.apache.activemq.artemis.core.server.ActiveMQServer;
3034
import org.apache.activemq.artemis.core.server.ActiveMQServers;
3135
import org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory;
3236
import org.apache.camel.CamelContext;
3337
import org.apache.camel.builder.RouteBuilder;
3438
import org.apache.camel.component.jms.JmsComponent;
3539
import org.apache.camel.impl.DefaultCamelContext;
40+
import org.w3c.dom.Document;
41+
import org.w3c.dom.Element;
3642

3743
import javax.annotation.Resource;
3844
import javax.jms.ConnectionFactory;
@@ -41,6 +47,9 @@
4147
import javax.servlet.ServletContextListener;
4248
import javax.servlet.annotation.WebListener;
4349
import javax.sql.DataSource;
50+
import javax.xml.parsers.DocumentBuilder;
51+
import javax.xml.parsers.DocumentBuilderFactory;
52+
import java.io.File;
4453
import java.net.InetAddress;
4554

4655
@WebListener
@@ -58,15 +67,16 @@ public void contextInitialized(ServletContextEvent servletContextEvent) {
5867
camelContext = new DefaultCamelContext();
5968
TopicConnectionFactory connectionFactory = AQjmsFactory.getTopicConnectionFactory(new DataSourceWrapper(cwms), true);
6069
camelContext.addComponent("oracleAQ", JmsComponent.jmsComponent(connectionFactory));
61-
//TODO: determine how the port is configured
62-
String activeMqUrl = "tcp://" + InetAddress.getLocalHost().getHostName() + ":61616?protocols=STOMP&webSocketEncoderType=text";
63-
ActiveMQServer server = ActiveMQServers.newActiveMQServer(new ConfigurationImpl()
64-
.addAcceptorConfiguration("tcp", activeMqUrl)
65-
.setPersistenceEnabled(false)
66-
// .setJournalDirectory("build/data/journal")
67-
//Need to update to verify roles
68-
.setSecurityEnabled(false)
69-
.addAcceptorConfiguration("invm", "vm://0"));
70+
File brokerXmlFile = new File("src/test/resources/tomcat/conf/broker.xml").getAbsoluteFile();
71+
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
72+
dbFactory.setNamespaceAware(true);
73+
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
74+
Document doc = dBuilder.parse(brokerXmlFile);
75+
doc.getDocumentElement().normalize();
76+
Element rootElement = doc.getDocumentElement();
77+
FileConfiguration configuration = new FileConfiguration();
78+
configuration.parse(rootElement, brokerXmlFile.toURI().toURL());
79+
ActiveMQServer server = ActiveMQServers.newActiveMQServer(configuration);
7080
ConnectionFactory artemisConnectionFactory = new ActiveMQJMSConnectionFactory("vm://0");
7181
camelContext.addComponent("artemis", JmsComponent.jmsComponent(artemisConnectionFactory));
7282
camelContext.addRoutes(new RouteBuilder() {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version='1.0'?>
2+
3+
<!--
4+
~ MIT License
5+
~
6+
~ Copyright (c) 2024 Hydrologic Engineering Center
7+
~
8+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
9+
~ of this software and associated documentation files (the "Software"), to deal
10+
~ in the Software without restriction, including without limitation the rights
11+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
~ copies of the Software, and to permit persons to whom the Software is
13+
~ furnished to do so, subject to the following conditions:
14+
~
15+
~ The above copyright notice and this permission notice shall be included in all
16+
~ copies or substantial portions of the Software.
17+
~
18+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
~ SOFTWARE.
25+
-->
26+
27+
<configuration xmlns="urn:activemq"
28+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
29+
xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd">
30+
<core xmlns="urn:activemq:core">
31+
<name>ActiveMQServer</name>
32+
<persistence-enabled>false</persistence-enabled>
33+
<security-enabled>false</security-enabled>
34+
<acceptors>
35+
<acceptor name="artemis">tcp://localhost:61616?httpEnabled=true</acceptor>
36+
<acceptor name="invm">vm://0</acceptor>
37+
</acceptors>
38+
</core>
39+
</configuration>

websocket-testing/src/main/javascript/stomp-ws-testing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {WebSocket} from 'ws';
2929
Object.assign(global, {WebSocket});
3030
const client = new Client({
3131
logRawCommunication: true,
32-
brokerURL: 'ws://tacocat:61616/topic', connectionTimeout: 1000, onConnect: () => {
32+
brokerURL: 'ws://localhost:61616/topic', connectionTimeout: 1000, onConnect: () => {
3333
console.log("Connected")
3434
client.subscribe('SWT_TS_STORED', message => {
3535
console.log(`Received: ${message.body}`);

0 commit comments

Comments
 (0)