10 Replies Latest reply on Mar 14, 2007 12:35 PM by Martin Henderson

    seam, spring activemq

    Martin Henderson Newbie

      Hi folks,

      I'm attempting to use seam for a webapp, the implementation of which is fine.
      However, there can be a back end feed that comes in via jms and its kinda been mandated that I use activemq for this.

      So I've configured the various activemq bits and bobs via spring. However... I need to persist some of the data that comes in, into the db. So I did this:

       <!-- Use this to wire into the active mq beans -->
       <bean id="springHook" class="org.banana.utils.SpringHook">
       <property name="session"><ref local="hibernateSession"/></property>
       </bean>
      
       <seam:instance name="svDatabase" id="hibernateSession" proxy="true"/>
      


      to get hold of the seam managed hibernate session.

      However... when I put that spring hook bean into a message listener and have it attempt to log out the hibernate session I get:

      svi ERROR [Thread-5] UpdateListener.onMessage(74) | jms exception=No application
      context active
      java.lang.IllegalStateException: No application context active
       at org.jboss.seam.Component.forName(Component.java:1545)
       at org.jboss.seam.Component.getInstance(Component.java:1595)
       at org.jboss.seam.Component.getInstance(Component.java:1578)
       at org.jboss.seam.Component.getInstance(Component.java:1572)
      


      but when I nav to the first page of the app and have a test just to log out the session... it works. It appears that referencing a seam managed hibernate session isn't working for me.

      Although this might be the way its supposed to work... i was wondering if there were another way of getting hold of a hibernate session from seam?

      Hope you can help.

        • 1. Re: seam, spring activemq
          Gavin King Master

          In JBoss 4.0.x there is a bug which means that interceptors don't get fired for MDBs. You can either:

          (a) call from the MDB to a session bean to do the work OR
          (b) wait for JBoss 4.2


          By the way, the architecturally correct way to use JMS from an appserver / in an EJB3 environment is to install it via JCA, not Spring.

          • 2. Re: seam, spring activemq
            Martin Henderson Newbie

            i'm actually kinda running the app on tomcat Gavin.
            Also the active mq broker is embedded and wired up via jencks to do message driven pojo's.....

            dunno if that helps any?

            • 3. Re: seam, spring activemq
              Martin Henderson Newbie

              ok... got it sorted.

              if anyones interested.....

              I just need to call Lifecycle.begnnCall() and end it, using the session inbetween.

              • 4. Re: seam, spring activemq
                youngm Novice

                One other thing to try. What happens if you make your springHook a seam component by nesting <seam:component/> in the bean entry? Does that negate the need to call Lifecycle.beginCall()?

                • 5. Re: seam, spring activemq
                  youngm Novice

                  Actually you will have to do <seam:component intercept="ALWAYS" />

                  • 6. Re: seam, spring activemq
                    Martin Henderson Newbie

                    hiya,

                    I previously had the SpringHook class setup like this:

                    @Name("springHook")
                    @Scope(APPLICATION)
                    @Intercept(ALWAYS)
                    @Startup
                    public class SpringHook {
                     private static Log log = LogFactory.getLog(SpringHook.class);
                    
                     @In(create=true)
                     private Session svDatabase;
                    
                     public Session getSession(){return this.svDatabase;}
                     public void setSession(Session s){this.svDatabase = s;}
                    }
                    
                    


                    but that didn't work.

                    tried like so:


                     <bean id="springHook" class="org.banana.utils.SpringHook" lazy-init="true">
                     <property name="session"><ref local="hibernateSession"/></property>
                     <seam:component intercept="ALWAYS" />
                     </bean>
                    
                     <seam:instance name="svDatabase" id="hibernateSession" proxy="true"/>
                    


                    but same error.


                    exception is java.lang.IllegalStateException: No application context active
                    caused by: java.lang.IllegalStateException: No application context active
                     at org.jboss.seam.Component.forName(Component.java:1545)
                     at org.jboss.seam.Component.getInstance(Component.java:1595)
                     at org.jboss.seam.Component.getInstance(Component.java:1590)
                     at org.jboss.seam.Component.getInstance(Component.java:1584)




                    • 7. Re: seam, spring activemq
                      youngm Novice

                      hmm.....you're first attempt should have worked if you did the following:

                      1. Remove your spring bean reference.
                      2. Do <seam:instance id="springHook" name="springHook" proxy="true"/>
                      3. You probably will want to change the scope of your SpringHook Seam component to METHOD since I believe you may run into concurrency issues using APPLICATION scope with @In unless you make your method calls @Synchronized.

                      That's strange that <seam:component intercept="ALWAYS"/> Didn't work. I'll have to look at that one.

                      Let me know how the above turns out.

                      Mike

                      • 8. Re: seam, spring activemq
                        Martin Henderson Newbie

                        no luck .

                        changed it as you said:

                        
                         <bean id="listenerService"
                         class="org.banana.services.UpdateListener"
                         depends-on="broker1" lazy-init="true">
                         <property name="brokerService"><ref local="broker1"/></property>
                         <property name="springHook"><ref local="springHook"/></property>
                         </bean>
                        
                         <seam:instance id="springHook" name="springHook" proxy="true" />
                        
                        @Name("springHook")
                        @Scope(METHOD)
                        @Intercept(ALWAYS)
                        @Startup
                        public class SpringHook {
                         private static Log log = LogFactory.getLog(SpringHook.class);
                        
                         @In(create=true)
                         private Session svDatabase;
                        
                         public void test(){
                         log.info("hib session=" + this.svDatabase);
                         }
                        
                         public Session getSession(){return this.svDatabase;}
                         public void setSession(Session s){this.svDatabase = s;}
                        }
                        
                        
                        


                        but its barfing on startup now with error that seams needs to be configured before spring.

                        not to worry... I have the workaround anyhoo.
                        thanks for the help!

                        • 9. Re: seam, spring activemq
                          youngm Novice

                          You're not bugging me. Something not working the way I expect it to work bugging me. :)


                          but its barfing on startup now with error that seams needs to be configured before spring.


                          This is probably the heart of the problem. The Spring ContextLoaderListener needs to be loaded after the SeamListener. It may be a matter of simply changing the order in your web.xml. In the next release you will be able to use seam:context-loader to load the spring application context as a seam component. Anyway, give it a try if you want.

                          Mike

                          • 10. Re: seam, spring activemq
                            Martin Henderson Newbie

                            i'll give it a lash tomorrow and change the order of stuff.... that was why i'd added the lazy-init stuff to the updateListener bean to try and make sure it it got created after seam got started.

                            ta for the help, and good work on the ioc library for seam too.