9 Replies Latest reply on Jul 28, 2010 8:18 AM by deesha

    Problem Configuring JMS with Seam

    dhook.donald.hook.gmail.com
      I am developing an application which will use a couple of queues.  I have been having a problem trying to get JMS configured properly with the application.  Any help would be greatly appreciated!!  Following is what I have configured and the exception I am getting.

      ddh-service.xml (In Jboss directory)
      ====================================
      <server>
              <mbean code="org.jboss.mq.server.jmx.Queue"
                      name="jboss.mq.destination:service=Queue,name=QuoteQueue">
                      <attribute name="JNDIName">queue/QuoteQueue</attribute>
                      <use-java-context>false</use-java-context>
                      <depends optional-attribute-name="DestinationManager">
                              jboss.mq:service=DestinationManager
                      </depends>
              </mbean>
              <mbean code="org.jboss.mq.server.jmx.Queue"
                      name="jboss.mq.destination:service=Queue,name=BacktestQueue">
                      <attribute name="JNDIName">queue/BacktestQueue</attribute>
                      <use-java-context>false</use-java-context>
                      <depends optional-attribute-name="DestinationManager">
                              jboss.mq:service=DestinationManager
                      </depends>
              </mbean>
              <mbean code="org.jboss.mq.server.jmx.Queue"
                      name="jboss.mq.destination:service=Queue,name=MailQueue">
                      <attribute name="JNDIName">queue/MailQueue</attribute>
                      <use-java-context>false</use-java-context>
                      <depends optional-attribute-name="DestinationManager">
                              jboss.mq:service=DestinationManager
                      </depends>
              </mbean>
      </server>


      components.xml
      ==============
      <jms:managed-queue-sender name="quoteQueueSender" auto-create="true" queue-jndi-name="queue/QuoteQueue"/>
      <jms:queue-connection queue-connection-factory-jndi-name="java:/JmsXA" />



      jms-ds.xml
      ==========
      <connection-factories>

        <!-- ==================================================================== -->
        <!-- JMS Stuff                                                            -->
        <!-- ==================================================================== -->

         <!--
             The JMS provider loader. Currently pointing to a non-clustered ConnectionFactory. Need to
             be replaced with a clustered non-load-balanced ConnectionFactory when it becomes available.
             See http://jira.jboss.org/jira/browse/JBMESSAGING-843.
         -->
         <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
                name="jboss.messaging:service=JMSProviderLoader,name=JMSProvider">
            <attribute name="ProviderName">DefaultJMSProvider</attribute>
            <attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
            <attribute name="FactoryRef">java:/XAConnectionFactory</attribute>
            <attribute name="QueueFactoryRef">java:/XAConnectionFactory</attribute>
            <attribute name="TopicFactoryRef">java:/XAConnectionFactory</attribute>
         </mbean>

         <!-- JMS XA Resource adapter, use this to get transacted JMS in beans -->
         <tx-connection-factory>
            <jndi-name>JmsXA</jndi-name>
            <xa-transaction/>
            <rar-name>jms-ra.rar</rar-name>
            <connection-definition>org.jboss.resource.adapter.jms.JmsConnectionFactory</connection-definition>
            <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property>
            <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/DefaultJMSProvider</config-property>
            <max-pool-size>20</max-pool-size>
            <security-domain-and-application>JmsXARealm</security-domain-and-application>
            <depends>jboss.messaging:service=ServerPeer</depends>
         </tx-connection-factory>

      </connection-factories>

      Java Code
      ==========
      @In
      QueueSender quoteQueueSender;

      @In
      QueueSession queueSession;
             
             

      StackTrace
      ==========================
      07:00:58,656 ERROR [AsynchronousExceptionHandler] Exeception thrown whilst executing asynchronous call
      org.jboss.seam.InstantiationException: Could not instantiate Seam component: quoteQueueSender
              at org.jboss.seam.Component.newInstance(Component.java:2106)
              at org.jboss.seam.Component.getInstance(Component.java:1988)
              at org.jboss.seam.Component.getInstance(Component.java:1950)
              at org.jboss.seam.Component.getInstance(Component.java:1944)
              at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2311)
              at org.jboss.seam.Component.getValueToInject(Component.java:2263)
              at org.jboss.seam.Component.injectAttributes(Component.java:1703)
              at org.jboss.seam.Component.inject(Component.java:1521)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:52)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
              at com.ddh.process.QuoteUpdateProcess_$$_javassist_1.process(QuoteUpdateProcess_$$_javassist_1.java)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              at org.jboss.seam.async.AsynchronousInvocation$1.process(AsynchronousInvocation.java:62)
              at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:80)
              at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44)
              at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:243)
              at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
              at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
      Caused by: org.jboss.seam.InstantiationException: Could not instantiate Seam component: org.jboss.seam.jms.queueSession
              at org.jboss.seam.Component.newInstance(Component.java:2106)
              at org.jboss.seam.Component.getInstance(Component.java:1988)
              at org.jboss.seam.Component.getInstance(Component.java:1950)
              at org.jboss.seam.Component.getInstance(Component.java:1944)
              at org.jboss.seam.Component.getInstance(Component.java:1924)
              at org.jboss.seam.Component.getInstance(Component.java:1919)
              at org.jboss.seam.jms.QueueSession.instance(QueueSession.java:55)
              at org.jboss.seam.jms.ManagedQueueSender.create(ManagedQueueSender.java:51)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
              at org.jboss.seam.Component.callCreateMethod(Component.java:2134)
              at org.jboss.seam.Component.newInstance(Component.java:2094)
              ... 29 more
      Caused by: org.jboss.seam.InstantiationException: Could not instantiate Seam component: org.jboss.seam.jms.queueConnection
              at org.jboss.seam.Component.newInstance(Component.java:2106)
              at org.jboss.seam.Component.getInstance(Component.java:1988)
              at org.jboss.seam.Component.getInstance(Component.java:1950)
              at org.jboss.seam.Component.getInstance(Component.java:1944)
              at org.jboss.seam.Component.getInstance(Component.java:1924)
              at org.jboss.seam.Component.getInstance(Component.java:1919)
              at org.jboss.seam.jms.QueueConnection.instance(QueueConnection.java:75)
              at org.jboss.seam.jms.QueueSession.create(QueueSession.java:38)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
              at org.jboss.seam.Component.callCreateMethod(Component.java:2134)
              at org.jboss.seam.Component.newInstance(Component.java:2094)
              ... 45 more
      Caused by: java.lang.ClassCastException: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl cannot be cast to javax.jms.QueueConnectionFactory
              at org.jboss.seam.jms.QueueConnection.getQueueConnectionFactory(QueueConnection.java:64)
              at org.jboss.seam.jms.QueueConnection.init(QueueConnection.java:51)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
              at org.jboss.seam.Component.callCreateMethod(Component.java:2134)
              at org.jboss.seam.Component.newInstance(Component.java:2094)
              ... 61 more
        • 1. Re: Problem Configuring JMS with Seam
          lvdberg

          An example of how it works in my application:


          in components.xml




          <jms:managed-topic-publisher name="testTopic" auto-create="true" topic-jndi-name="topic/messageTopic"/>
               <jms:queue-connection  queue-connection-factory-jndi-name="java:/JmsXA" />
          
          


          Example of a bean using the topic publisher.


          import javax.jms.JMSException;
          import javax.jms.TextMessage;
          import javax.jms.TopicPublisher;
          import javax.jms.TopicSession;
          
          
          @In(create=true) TopicSession topicSession;
          @In TopicPublisher testTopic;
               
          ...
          TextMessage tm;
          try {
               tm = topicSession.createTextMessage();
               tm.setText("TestMessage");
               testTopic.publish(tm);
               } catch (JMSException e) {
               e.printStackTrace();
               }
                    
          ....
          
          



          Have you looked at the imports, maybe you're importing the wrong session. Should be the javax.jms one.

          • 2. Re: Problem Configuring JMS with Seam
            dhook.donald.hook.gmail.com

            Thanks, I will take a look at that....  From what I saw in the docs - seemed easy just like you have mentioned, but I must be doing something wrong.

            • 3. Re: Problem Configuring JMS with Seam
              dhook.donald.hook.gmail.com

              I recall adding the jms.jar in order to compile, as well as adding the definitions of the queues in the ddh-services.xml.  The clascastexception is in regards to the use of the jboss connection factory vs. the jms one - which you have eluded to.  Did you make any mods to your service.xml or have to import jms.jar?

              • 4. Re: Problem Configuring JMS with Seam
                lvdberg

                Hi Donald,


                I always use the geronimo j2ee jars for all (Maven/Eclipse-based) development, but the implementation jars are included in the JBoss distribution so I don't include anything in the war or ear. If you've included the jms.jar in your application, that will be the one the application will use and not the one as provided by you app server. So possibly the error results from a conflict there.


                If that doesn't solve the problem, strip all unnecessary jars from your build and check versions numbers of all others. A lot of the apache commons can conflict too, if you include older or newer vesrions (this was exactly the reason why I switched to Maven).


                The only thing I additionally did was defining Queues and Topics in the definition files and sometimes change stuff to enable JMS-access over HTTP, nothing strange. I am using JBoss 5 which has another JMS-directory structure as the 4.X series, but basically the approach is the same.


                I just filed a JIRA to improve JMS support in Seam, its already great, but async support needs some extra goodies.


                Success,


                Leo







                • 5. Re: Problem Configuring JMS with Seam
                  dhook.donald.hook.gmail.com
                  Leo -

                  Thank you - I will take a look & let you know what I come up with. 

                  I appreciate your time & interest in helping.

                  THANKS!!
                  • 6. Re: Problem Configuring JMS with Seam
                    dhook.donald.hook.gmail.com

                    Leo - I needed to include the jms.jar into the project to compile the class.. I will try removing to see if I can compile ...

                    • 7. Re: Problem Configuring JMS with Seam
                      lvdberg

                      Donald, 


                      you need the jar to compile, but you must NOT include it in your build.


                      If you have a exploded view (dir under deploy-directory) check in /web-inf/lib if you have the JMS.jar


                      If you have a war-file use an unzipper (7-Zip works great) to se if it is the lib-dir.


                      Leo

                      • 8. Re: Problem Configuring JMS with Seam
                        dhook.donald.hook.gmail.com

                        Leo -


                        I removed jms.jar from the deployed-jars-ear.list file so that the jms.jar was not deployed and it worked like a champ.


                        Thank you for your help, you saved a great deal of frustration.


                        THANKS!!!!

                        • 9. Re: Problem Configuring JMS with Seam
                          deesha

                          Hi, Im having the same issue you had. I don't understand what you did to fix it though, could you explain in a bit more detail please?


                          Thank you.