24
24
25
25
package cwms .cda .api .messaging ;
26
26
27
- import cwms .cda .datasource .DelegatingDataSource ;
28
- import oracle .jdbc .driver .OracleConnection ;
29
27
import oracle .jms .AQjmsFactory ;
30
28
import org .apache .activemq .artemis .core .config .impl .ConfigurationImpl ;
31
29
import org .apache .activemq .artemis .core .server .ActiveMQServer ;
41
39
import javax .jms .TopicConnectionFactory ;
42
40
import javax .servlet .ServletContextEvent ;
43
41
import javax .servlet .ServletContextListener ;
44
- import javax .servlet .ServletException ;
42
+ import javax .servlet .annotation . WebListener ;
45
43
import javax .sql .DataSource ;
46
44
import java .net .InetAddress ;
47
- import java .sql .Connection ;
48
- import java .sql .SQLException ;
49
45
46
+ @ WebListener
50
47
public final class CamelServletContextListener implements ServletContextListener {
51
48
52
49
@ Resource (name = "jdbc/CWMS3" )
@@ -58,26 +55,15 @@ public void contextInitialized(ServletContextEvent servletContextEvent) {
58
55
try {
59
56
//wrapped DelegatingDataSource is used because internally AQJMS casts the returned connection
60
57
//as an OracleConnection, but the JNDI pool is returning us a proxy, so unwrap it
61
- CamelContext camelContext = new DefaultCamelContext ();
62
- TopicConnectionFactory connectionFactory = AQjmsFactory .getTopicConnectionFactory (new DelegatingDataSource (cwms )
63
- {
64
- @ Override
65
- public Connection getConnection () throws SQLException {
66
- return super .getConnection ().unwrap (OracleConnection .class );
67
- }
68
-
69
- @ Override
70
- public Connection getConnection (String username , String password ) throws SQLException {
71
- return super .getConnection (username , password ).unwrap (OracleConnection .class );
72
- }
73
- }, true );
58
+ camelContext = new DefaultCamelContext ();
59
+ TopicConnectionFactory connectionFactory = AQjmsFactory .getTopicConnectionFactory (new DataSourceWrapper (cwms ), true );
74
60
camelContext .addComponent ("oracleAQ" , JmsComponent .jmsComponent (connectionFactory ));
75
61
//TODO: determine how the port is configured
76
- String activeMqUrl = "tcp://" + InetAddress .getLocalHost ().getHostName () + ":61616" ;
62
+ String activeMqUrl = "tcp://" + InetAddress .getLocalHost ().getHostName () + ":61616?protocols=STOMP&webSocketEncoderType=text " ;
77
63
ActiveMQServer server = ActiveMQServers .newActiveMQServer (new ConfigurationImpl ()
78
64
.addAcceptorConfiguration ("tcp" , activeMqUrl )
79
- .setPersistenceEnabled (true )
80
- .setJournalDirectory ("build/data/journal" )
65
+ .setPersistenceEnabled (false )
66
+ // .setJournalDirectory("build/data/journal")
81
67
//Need to update to verify roles
82
68
.setSecurityEnabled (false )
83
69
.addAcceptorConfiguration ("invm" , "vm://0" ));
@@ -90,9 +76,10 @@ public void configure() {
90
76
//TODO: determine clientId - should be unique to CDA version?
91
77
from ("oracleAQ:topic:CWMS_20.SWT_TS_STORED?durableSubscriptionName=CDA_SWT_TS_STORED&clientId=CDA" )
92
78
.log ("Received message from ActiveMQ.Queue : ${body}" )
79
+ .process (new MapMessageToJsonProcessor (camelContext ))
93
80
//TODO: define standard naming
94
81
//TODO: register artemis queue names with Swagger UI
95
- .to ("artemis:topic:ActiveMQ.Queue " );
82
+ .to ("artemis:topic:SWT_TS_STORED " );
96
83
}
97
84
});
98
85
server .start ();
0 commit comments