1 Reply Latest reply on May 5, 2013 4:57 PM by wolfch

    Cannot map java:/JmsXA to web app resource as java:comp/env/jms/JmsXA

    chris.wolf Newbie

      Hello,

       

      This is my first post.  I want to use a JMS ConectionFactory via a Resource Adapter, therefore I want the CF bound to "java:JmsXA".  I want to access this from a web application, but it cannot "see" this (returns null upon attempt to lookup).  I don't understand why this is an issue since the web app is in the same VM as the JBoss server.  I wonder if there are other isolation mechanisms to consider for web apps accessing the "java:" namespace?

       

      I know that "JmsXA" can be reconfigured to be in the global namespace, but that will impact other applications on the server that expect it in the "java:" namespace, so that's not an option.

       

      Then I read how these resources can be mapped into a web app's private ENC namespace:

       

      http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/ENC_Usage_Conventions-Resource_Manager_Connection_Factory_References.html

       

      So in my WEB-INF/web.xml, I put:

       

        <resource-ref>

          <res-ref-name>jms/JmsXA</res-ref-name>

          <res-type>javax.jms.ConnectionFactory</res-type>

          <res-auth>Container</res-auth>

        </resource-ref>

       

      ...and in WEB-INF/jboss-web.xml, I put:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <jboss-web xmlns:xs="http://www.jboss.org/j2ee/schema" version="5.1"

           xs:schemaLocation="http://www.jboss.org/j2ee/schema

           http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">

        <resource-ref>

          <res-ref-name>jms/JmsXA</res-ref-name>

          <jndi-name>java:/JmsXA</jndi-name>

        </resource-ref>

      </jboss-web>

       

      Then in the web app code I tried to do a lookup for "java:comp/env/jms/JmsXA" but it returned null.

       

      How can web app code access java:JmsXA??

       

      I already searched this forum and FAQs, e.g.

       

      https://community.jboss.org/message/440879#440879

      https://community.jboss.org/thread/47131?tstart=0

       

      but there's no info on web app code accessing java:JmsXA.

       

      If I re-package my code as a Spring deployment and deploy using "Snowdrop", then the same code works and can access "java:JmsXA", but I'd rather

      depoy as a web app.

       

      http://www.jboss.org/snowdrop

       

      Oh and it's JBoss-6.1.0  due to legacy apps, we have to stick with this old realease for now.

       

      Thanks,

       

      Chris

        • 1. Re: Cannot map java:/JmsXA to web app resource as java:comp/env/jms/JmsXA
          wolfch Newbie

          Ok, I gave up on trying to access "java:/JmsXA" from a web app deployment, however I came up with a solution that works. Just make a copy of the connection-factory configuration for "java:/JmsXA" but map this second one to a JNDI name in the global namespace.

           

          Here is the detailed procedure.

          ===================== deploy/hornetq/jms-ds.xml ============

          Since the JCA RA pooled JMS ConnectionFactory is mapped to "java:/JmsXA" and, for some reason, the "java:" namespace is not accessable from web applications - we  will configure another connection factory and map it in the global namespace.  The raw XAConnectionFactory is mapped to the global name "/ConnectionFactory", but JBoss does not recommend usage by applications since connections and sessions are not pooled, nor automatically cleaned up.

           

          As such, we need to configure an additional JCA RA pooled JMS ConnectionFactory


          Edit $JBOSS_HOME/server/default/deploy/hornetq/jms-ds.xml and add the following entry:

            <tx-connection-factory>
              <jndi-name>JmsXAGlobal</jndi-name>
              <use-java-context>false</use-java-context>
              <xa-transaction/>
              <rar-name>jms-ra.rar</rar-name>
              <connection-definition>org.hornetq.ra.HornetQRAConnectionFactory</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>
              <!-- following configured in conf/login-config.xml -->
              <security-domain-and-application>JmsXAGlobalRealm</security-domain-and-application>
            </tx-connection-factory>
          

           

           

           

          ===================== conf/login-config.xml ============

          Edit $JBOSS_HOME/server/default/conf/login-config.xml add an application login policy for the newly added JMS connection factory.  You're basically just going to  copy/paste the one for "JmsXA", then replace the two occurances of the string "JmsXA" with "JmsXAGlobal"

           

            <application-policy name="JmsXAGlobalRealm">
              <authentication>
                <login-module code="org.jboss.resource.security.ConfiguredIdentityLoginModule"
                  flag="required">
                  <module-option name="principal">guest</module-option>
                  <module-option name="userName">guest</module-option>
                  <module-option name="password">guest</module-option>
                  <module-option name="managedConnectionFactoryName">jboss.jca:service=TxCM,name=JmsXAGlobal</module-option>
                </login-module>
              </authentication>
            </application-policy>  
          

           

          You should now be able to do a JNDI lookup on "/JmsXAGlobal":
          JmsXAGlobal (class: org.hornetq.ra.HornetQRAConnectionFactoryImpl)