11 Replies Latest reply on Aug 25, 2005 9:55 AM by shaun barker

    Configuring JNDI ConnectionFactory

    shaun barker Newbie

      Hi

      I am a JBoss newbie and am struggling finding out where and how to configure a ConnectionFactory. I need to create one with a name and then be able to refer to it to create a session and so forth. I have a jndi.properties file that looks like this:
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.provider.url=localhost:1099
      java.naming.factory.url.pkgs=org.jboss.naming

      and in the web.xml it says this:

      <resource-ref>
      Default QueueFactory
      <res-ref-name>jms/QueueFactory</res-ref-name>
      <res-type>javax.jms.QueueConnectionFactory</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      but I get an error that says:

      org.jboss.deployment.DeploymentException: Error during deploy; - nested throwable: (javax.naming.NamingException: resource-ref: jms/QueueFactory has no valid JNDI binding. Check the jboss-web/resource-ref.)

      But I have no real idea what this means or how to create the correct JNDI binding?

      Please help before I go mad (well more mad that is!)???

      regards

      Shaun

        • 1. Re: Configuring JNDI ConnectionFactory
          Evan Nail Newbie

          I'm new to jboss too so forgive if I ask stuff you already tried.

          Have you created a xxxx-ds.xml file in your deploy directory that binds to this jndi name?

          • 2. Re: Configuring JNDI ConnectionFactory
            shaun barker Newbie

            Yes I tried that too - although I called it -ds.xml (as I didn't know to give it a prefix) and this only caused errors since it said the name was not bound to JNDI - which only served to confuse me more?

            What exactly should go in the xxx-ds.xml file (assuming that xxx means any name I give to it) - are there any reference docs for this? Sorry to be asking probably very simple questions - but I have no previous experience with JBOss. The annoying thing is that I got my code running in SunApp server immediately as they have a UI for configuring ConnectionFactory etc.


            Well thanking you in advance....

            regards

            Shaun

            • 3. Re: Configuring JNDI ConnectionFactory
              shaun barker Newbie

              My file looked something like this (I since deleted it as it wasn't working!)
              <tx-connection-factory>
              <jndi-name>QueueFactory</jndi-name>
              <xa-transaction/>
              <rar-name>jms-ra.rar</rar-name>
              <adapter-display-name>JMS Adapter</adapter-display-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>
              <security-domain-and-application>JmsXARealm</security-domain-and-application>
              </tx-connection-factory>

              I got this from another posting on the forums you see.. but have no real idea of what should go in it?

              Thanks again

              Shaun

              • 4. Re: Configuring JNDI ConnectionFactory
                Darran Lofthouse Master

                Forget the -ds.xml, that is not what you are trying to achieve at all.

                In your web application in the web.xml you have specified a resource reference, the error is saying that you need a jboss-web.xml deployment descriptor to be packaged in your war that also contains a resource-ref with the JBoss specific settings.

                The jboss-web.xml should be something similar to: -

                <!DOCTYPE jboss-web PUBLIC
                 "-//JBoss//DTD Web Application 2.4//EN"
                 "http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">
                
                <jboss-web>
                 <resource-ref>
                 <res-ref-name>jms/QueueFactory</res-ref-name>
                 <jndi-name>ConnectionFactory</jndi-name>
                 </resource-ref>
                </jboss-web>
                


                • 5. Re: Configuring JNDI ConnectionFactory
                  shaun barker Newbie

                  Oh ok - in my jboss-web.xml I alread have this - is it wrong?


                  <jboss-web>
                  <security-domain>java:/jaas/HibernatePOC</security-domain>
                  <resource-ref>
                  Default QueueFactory
                  <res-ref-name>jms/QueueFactory</res-ref-name>
                  <res-type>javax.jms.QueueConnectionFactory</res-type>
                  <jndi-name>java:comp/env/jms/QueueFactory</jndi-name>
                  </resource-ref>

                  </jboss-web>

                  Will 'borrow' your version and have a looksee.... thankyou!

                  • 6. Re: Configuring JNDI ConnectionFactory
                    Darran Lofthouse Master

                    The jndi-name element should contain the jndi name of the item you are linking to not the jndi name you want it to be bound to.

                    In this case the connection factory is bound to JNDI as ConnectionFactory so that is the name to enter in the jndi-name element.

                    From the jboss-web.dtd: -

                    <!ELEMENT resource-ref (res-ref-name , (jndi-name | res-url))>


                    For your example the resource ref element should just contain a res-ref-name element and a jndi-name element.



                    • 7. Re: Configuring JNDI ConnectionFactory
                      shaun barker Newbie

                      Thanks for that - am trying it out right now. Will post to let you know how it goes. However - how do you know that it is being bound to jndi using the name 'ConnectionFactory' and not an-other name??

                      Cheers

                      Shaun

                      • 8. Re: Configuring JNDI ConnectionFactory
                        Darran Lofthouse Master

                        If you navigate to http://localhost:8080/jmx-console and select the JNDIView MBean there is a list method that you can invoke. If you invoke that method it shows you what is bound to JNDI.

                        • 9. Re: Configuring JNDI ConnectionFactory
                          shaun barker Newbie

                          A brill - this is what it says:

                          ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)


                          However I get a cast exception trying to cast that to a ConnectionFactory for some weird reason - I think there are duplicate classes for Connectionfactory on the classpath .. am checking it out right now!

                          Thanks again! Have a beer for me tomorrow on POETS day!

                          Shaun

                          • 10. Re: Configuring JNDI ConnectionFactory
                            shaun barker Newbie

                            OK - firstly may I thank those that helped (particularly darranl!) it is all working thank fek!

                            In essence the NameNotFoundException was entirely a result of me asking for the wrong name from JNDI - so thanks for the reference to the MBean stuff. The second problem was the ClassCastException and that was due to more than one jar on my classpath containing an implementation of the QueueConnectionFactory class and both were loaded by the app server. I got around that one by altering the ant script to specifically include only the files I knew I needed and discarding all others at build time.

                            Thanks again!

                            Shaun

                            • 11. Re: Configuring JNDI ConnectionFactory
                              shaun barker Newbie

                              No idea what has happened - I posted to say thankyou but the post has dissapeared - lets hope I didn't do it on the wrong subject??!

                              Anyway - thankyou - all sorted now. Yes there was more than one implementation of the QueueConnectionFactory on my classpath - once rmeoved it all worked out fine!

                              Thanks for your help - really appreciate it!

                              Shaun