1
votes

I have working with JMS listeners (for receiving messages) into standard webapps some time ago, normally using JSF (ICEfaces) for the webapp and spring, activemq, etc., for the JMS integration.

Now, I'm trying to do the same into an OpenXava application. So, this is what I have done at the moment:

  • I have created the listeners.xml into the WEB-INF (same place of the web.xml, which I can't modify because OpenXava), with this content (content to be auto added to web.xml by OpenXava):

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<context-param>  
    <param-name>contextConfigLocation</param-name>  
    <param-value>  
        classpath:applicationContext.xml
    </param-value>  
</context-param>

  • I have created the applicationContext.xml (I have tested placing it in the OpenXava application src folder and also into the WEB-INF), with the following content:

    <!-- Create the topic to connect to -->
    <bean id="TTCTopic" class="org.apache.activemq.command.ActiveMQTopic">
        <property name="physicalName" value="com.comp.app.message.tags"/>
    </bean>
    
    <!-- JMS Connection Factory -->
    <bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
        <property name="brokerURL" value="tcp://127.0.0.1:1100"/>
    </bean>
    
    <!-- Spring Helper to listen to a JMS Destination -->
    <bean id="jmsContainer"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="destination" ref="TTCTopic" />
        <property name="messageListener" ref="messageReceiver" />
    </bean>
    

  • Then, I have created my listener class (com.comp.app.listeners.MessageReceiver) which implements the JMS MessageListener interface, and which has the code to process the message received.

  • Also, I did place into the WEB-INF/Lib of my OpenXava application the spring and activemq jars and also I added the references in the project's classpath for each jar.

Finally, I'm not getting any kind of error.

So, after all the problem is: The spring context is not being added to the OpenXava web.xml as is supposed to do... because the spring context is not created, therefore the JMS listener is never created.

So, what I'm missing here? ... is there a better way to do this?

Thanks in advance,

3

3 Answers

0
votes

Try pointing out WEB-INF explicitly:

<context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

Official docs points out adding this directly to web.xml though.

0
votes

My advice is to create a very simple OpenXava project and follow the Spring integration instruction step by step, when it works you can try it against your real project.

However, your option of not using Spring is better.

0
votes

Well, maybe it's not the real answer to my question, but having not found the way to make the spring context to be created for my OpenXava application (needed here for ActiveMQ definition and DI using spring container), I decided to quit the spring dependency and proceed with ActiveMQ as is. Therefore, I proceeded to create a Consumer class that create the connection to the JMS broker and use the certain topic to register and start my listener, which was prepared to receive a xml marshalled message and unmarshall it for main process.

Because the Domain Driven design nature of OpenXava, I tried to no mess the configuration with other stuffs. And seeing that I wasn't able to configure the spring container into my OX app, then this new way worked without much effort. I also created a new "on-start" action into the general (application) controller, that use a singleton pattern to keep the connection's session to the broker and the JMS listener which will be waiting for messages.

Now, I'm looking the way on how to integrate that Listener to refresh some specific transient views into my OpenXava application, which is turning into something tricky. But that will be for a new thread.