Using connection factory in Java EE web module
atijms Feb 17, 2011 12:12 PMIf 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.