1 Reply Latest reply on Feb 17, 2011 5:13 PM by henk de boer

    Using connection factory in Java EE web module

    arjan tijms Novice

      If have an EAR that I deploy to JBoss AS 6. I'm trying to let code in the web module listen to a queue. By default this will result in the dreaded message:

       

      This method is not applicable inside the application server. See the J2EE spec, e.g. J2EE1.4 Section 6.6
      

       

      With JBoss Messaging in JBoss AS 5, the solution was to add your own connection factory with the Strict property set to false. I tried to do the same for HornetQ, but ran into some problems. First I tried the following:

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <connection-factories>
      
          <tx-connection-factory>
              <jndi-name>JmsXAWeb</jndi-name>
              <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>        
              <config-property name="Strict" type="java.lang.Boolean">false</config-property>
              <max-pool-size>20</max-pool-size>
              <security-domain-and-application>JmsXARealm</security-domain-and-application>    
          </tx-connection-factory>
      
      </connection-factories>
      

       

      This however resulted in the following exception when I try to call createSession() on the connection obtained from the factory.

       

      javax.resource.ResourceException: Unable to get managed connection for JmsXAWeb
      

       

      The specific place where it goes wrong is HornetQRACredential#getCredential. The pwdc is always null:

       

       

      PasswordCredential pwdc = GetCredentialAction.getCredential(subject, mcf);
      
               if (pwdc == null)
               {
                  throw new SecurityException("No password credentials found");
               }
      

       

      (when looking into GetCredentialAction#getCredential, I noticed it compared properties by object identity, and the object instances were different, resulting in the null being returned)

       

      I tried overriding the ra.xml properties UserName and Password with the connection factory properties (in the tx-connection-factory given above)

       

      <config-property name="UserName" type="java.lang.String">guest</config-property>
      <config-property name="Password" type="java.lang.String">guest</config-property>
      

       

      But for some reason these don't end up in HornetQRAManagedConnectionFactory.getResourceAdapter().getProperties().

       

      I then tried to create the create the connection with createConnection("guest", "guest"), but this resulted in the same failure.

       

      Finally, I removed the security-domain-and-application from the connection factory definition, which resulted in:

       

      javax.jms.IllegalStateException: This method is not applicable inside the application server. See the J2EE spec, e.g. J2EE1.4 Section 6.6
       at org.hornetq.ra.HornetQRASession.checkStrict(HornetQRASession.java:1403)
       at org.hornetq.ra.HornetQRAMessageConsumer.setMessageListener(HornetQRAMessageConsumer.java:130)
      

       

      So I guess HornetQ either has a different property for "Strict" (couldn't find it in the manual though) or that I'm doing something wrong with specifying the properties.

       

      Help with either the authentication or the Strict setting would be appreciated.

        • 1. Using connection factory in Java EE web module
          henk de boer Master

          arjan tijms wrote:

           

          If have an EAR that I deploy to JBoss AS 6. I'm trying to let code in the web module listen to a queue. By default this will result in the dreaded message:

           

          This method is not applicable inside the application server. See the J2EE spec, e.g. J2EE1.4 Section 6.6
          

           

           

          That's probably for the java:/JmsXA connection factory. I was having the same problem and accidentally discovered that using the java:/ConnectionFactory does work in the web module. Both return completely different factories:

           

          java:/JmsXA -> org.hornetq.ra.HornetQRAConnectionFactoryImpl

           

          java:/ConnectionFactory -> org.hornetq.jms.client.HornetQConnectionFactory

           

          For some reason the RA version has the "J2EE protection", while the non-RA version doesn't.

           

           

          arjan tijms wrote:

           

          I tried overriding the ra.xml properties UserName and Password with the connection factory properties (in the tx-connection-factory given above)

           

          <config-property name="UserName" type="java.lang.String">guest</config-property>
          <config-property name="Password" type="java.lang.String">guest</config-property>
          

           

          But for some reason these don't end up in HornetQRAManagedConnectionFactory.getResourceAdapter().getProperties().

           

          I think that this is by itself correct. Those properties are the actual non-overriden ones straight from the ra.xml. HornetQRAConnectionFactoryImpl has a HornetQRAManagedConnectionFactory (mcf) which has a HornetQResourceAdapter (ra). This last one is what's being returned by getResourceAdapter() and as far as I know is a kind of singleton.

           

          config-properties on a connection-factory can theoretically override those from ra.xml, but to the best of my knowledge nobody can really know upfront which ones are overridable and which aren't. Only careful combing of the source code can reveal this. If I'm wrong I hope someone will correct me