7 Replies Latest reply on Nov 18, 2011 5:20 AM by Leonardo Silva

    JMS problem on JBoss 7.0.1 Final with JNDI context

    Hauke Gulich Newbie

      Hi,

       

      I got this error:

       

       

      {color:#f00}javax.naming.NamingException: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.ear-1.0.0.ear.client-1.0.0.war:main" from Service Module Loader{color}

       

      and after changing

       

       

       

      {code}Properties props = new Properties();

       

      props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");

       

      props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");

      props.setProperty("java.naming.provider.url", ipaddress);

       

      Context context = new InitialContext(props);{code}

       

       

      to

       

       

      {code}

      Properties props = new Properties();

       

      props.setProperty("java.naming.factory.initial", "org.jboss.as.naming.InitialContextFactory");

       

      props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");

      props.setProperty("java.naming.provider.url", ipaddress);

       

      Context context = new InitialContext(props);

      {code}

       

       

      this error is gone.

       

       

       

      Now I get this error

       

       

      {color:#f00}javax.naming.NameNotFoundException: Name 'ConnectionFactory' not found in context ''{color}

       

       

      so I looked at the jmx console

       

       

      jndi.PNG

       

      So I changed the lookup to

       

       

      {code}

      QueueConnectionFactory tcf = (QueueConnectionFactory) context.lookup("java:jboss/UserTransaction");

      {code}

       

      And then I get this message:

       

       

       

      {color:#f00}java.lang.ClassCastException: com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple cannot be cast to javax.jms.QueueConnectionFactory{color}

       

       

       

      Here is my whole class. Its a singleton pattern on client side (sorry for german comments inside the program)

       

       

       

      {code}

      package de.hauke.client.jms;

       

      import java.util.Properties;

       

      import javax.jms.Queue;

      import javax.jms.QueueConnection;

      import javax.jms.QueueConnectionFactory;

      import javax.jms.QueueSender;

      import javax.jms.QueueSession;

      import javax.jms.TextMessage;

      import javax.naming.Context;

      import javax.naming.InitialContext;

       

      import org.apache.log4j.Logger;

       

       

       

      import de.hauke.client.helper.InterfaceHelper;

      import de.hauke.server.configuration.ConfigurationHelper;

       

       

       

      public class JMSSender {

          private static final Logger logger = Logger.getLogger(JMSSender.class);

       

          private static String ipaddress = null;

          private static String queueName = null;

       

          private static QueueConnection conn = null;

          private static QueueSession session = null;

          private static Queue queue = null;

       

          private static JMSSender instance = null;

       

          private JMSSender(){

       

          }

       

          /**

           * Dieses Objekt soll nur ueber ein Singleton Pattern geladen werden.

           *

           * @return

           */

          public static JMSSender getInstance() {

              System.out.println("getting jmssender");

              if(instance == null) {

       

                  // Wenn das Objekt noch nicht geladen wurde, muessen Einstellungen

                  // aus der Datenbank geladen werden.

                  queueName = InterfaceHelper.getConfigurationHelper().getValue(ConfigurationHelper.CONFIGKEY_JMS_QUEUE_TOSERVER);

                  ipaddress = InterfaceHelper.getConfigurationHelper().getValue(ConfigurationHelper.CONFIGKEY_IPADDRESS_JBOSS);

       

                  System.out.println("Queuename : " + queueName);

                  System.out.println("IPAddress : " + ipaddress);

       

                  instance = new JMSSender();

                  instance.init();

              }

              return instance;

          }

       

       

          public static void reset() {

              instance = null;

          }

       

          private void init() {

              System.out.println("init jms sender");

                  try {

                      Properties props = new Properties();

       

                      // java.naming.factory.initial=org.jboss.as.naming.InitialContextFactory

                      // props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");

                      props.setProperty("java.naming.factory.initial", "org.jboss.as.naming.InitialContextFactory");

       

                      props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");

                      props.setProperty("java.naming.provider.url", ipaddress);

       

                      Context context = new InitialContext(props);

       

       

       

                      QueueConnectionFactory tcf = (QueueConnectionFactory) context.lookup("java:jboss/UserTransaction");

                      conn = tcf.createQueueConnection();

                      queue = (Queue) context.lookup(queueName);

       

                      System.out.println("conn ist " + conn != null ? " nicht null " : "null");

                      System.out.println("queue ist " + queue != null ? " nicht null " : "null");

       

                      session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

                      conn.start();

       

                      System.out.println("session ist " + session != null ? " nicht null " : "null");

       

       

                      instance = new JMSSender();

                  } catch (Exception ex) {

                      System.out.println("Fehler beim erzeugen des JMS Sender : " + ex);

                  }

          }

       

          public void send(String text) {

              try {

                  QueueSender send = session.createSender(queue);

                  TextMessage tm = session.createTextMessage(text);

                  send.send(tm);

                  send.close();

       

       

                  logger.info("Diese Nachricht wird an die JMS Queue geschickt : " + text);

       

              } catch (Exception ex) {

                  System.out.println("Fehler beim verschicken einer Nachricht : [" + text + "]" + ex);

              }

          }

       

      }

      {code}

       

       

       

      Here is the JMS part of the standalone-xts.xml

       

      I added the queue queue/toServer

       

      I also tried as context lookup value java:/JmsXA and java:/ConnectionFactory without luck

       

      {code:xml}

        <!--JMS Stuff-->

                 <jms-connection-factories>

                    <connection-factory name="InVmConnectionFactory">

                       <connectors>

                          <connector-ref connector-name="in-vm"/>

                       </connectors>

                       <entries>

                          <entry name="java:/ConnectionFactory"/>

                       </entries>

                    </connection-factory>

                    <connection-factory name="RemoteConnectionFactory">

                       <connectors>

                          <connector-ref connector-name="netty"/>

                       </connectors>

                       <entries>

                          <entry name="RemoteConnectionFactory"/>

                       </entries>

                    </connection-factory>

                    <pooled-connection-factory name="hornetq-ra">

                       <transaction mode="xa"/>

                       <connectors>

                          <connector-ref connector-name="in-vm"/>

                       </connectors>

                       <entries>

                          <entry name="java:/JmsXA"/>

                       </entries>

                    </pooled-connection-factory>

                 </jms-connection-factories>

       

                 <jms-destinations>

                    <jms-queue name="testQueue">

                       <entry name="queue/test"/>

                    </jms-queue>

                    <jms-queue name="queue/toServer">

                       <entry name="queue/toServer"/>

                    </jms-queue>             

                    <jms-topic name="testTopic">

                       <entry name="topic/test"/>

                    </jms-topic>

                 </jms-destinations>

      {code}

       

       

       

      Can somebody give me a hint for that?

       

       

      Do I have to deploy any additional jars for that?

       

       

      Thanks a lot

      Hauke

        • 1. Re: JMS problem on JBoss 7.0.1 Final with JNDI context
          Fabrizio Benedetti Novice

          Try creating context without environment and with the right jndi name:

           

          Context context = new InitialContext();

          QueueConnectionFactory tcf = (QueueConnectionFactory) context.lookup("java:/ConnectionFactory");

          • 2. Re: JMS problem on JBoss 7.0.1 Final with JNDI context
            Hauke Gulich Newbie

            Fabrizio Benedetti schrieb:

             

            Try creating context without environment and with the right jndi name:

             

            Context context = new InitialContext();

            QueueConnectionFactory tcf = (QueueConnectionFactory) context.lookup("java:/ConnectionFactory");

             

            Hi,

             

            sorry still the same error

             

             

            {color:#f00}javax.naming.NameNotFoundException: Name 'ConnectionFactory' not found in context ''{code}

             

             

             

            Thanks anyway,

            Hauke

            • 3. Re: JMS problem on JBoss 7.0.1 Final with JNDI context
              Fabrizio Benedetti Novice

              The same works fine on my environment.

               

              Can you post your standalone.xml?

              • 4. Re: JMS problem on JBoss 7.0.1 Final with JNDI context
                Hauke Gulich Newbie

                Sure

                 

                 

                {code:xml}

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

                 

                <server name="HaukePC" xmlns="urn:jboss:domain:1.0">

                    <extensions>

                        <extension module="org.jboss.as.clustering.infinispan"/>

                        <extension module="org.jboss.as.connector"/>

                        <extension module="org.jboss.as.deployment-scanner"/>

                        <extension module="org.jboss.as.ee"/>

                        <extension module="org.jboss.as.ejb3"/>

                        <extension module="org.jboss.as.jaxrs"/>

                        <extension module="org.jboss.as.jmx"/>

                        <extension module="org.jboss.as.jpa"/>

                        <extension module="org.jboss.as.logging"/>

                        <extension module="org.jboss.as.naming"/>

                        <extension module="org.jboss.as.osgi"/>

                        <extension module="org.jboss.as.remoting"/>

                        <extension module="org.jboss.as.sar"/>

                        <extension module="org.jboss.as.security"/>

                        <extension module="org.jboss.as.threads"/>

                        <extension module="org.jboss.as.transactions"/>

                        <extension module="org.jboss.as.web"/>

                        <extension module="org.jboss.as.weld"/>

                    </extensions>

                    <management>

                        <security-realms>

                            <security-realm name="PropertiesMgmtSecurityRealm">

                                <authentication>

                                    <properties path="mgmt-users.properties" relative-to="jboss.server.config.dir"/>

                                </authentication>

                            </security-realm>

                        </security-realms>

                        <management-interfaces>

                            <native-interface interface="management" port="9999"/>

                            <http-interface interface="management" port="9990"/>

                        </management-interfaces>

                    </management>

                    <profile>

                        <subsystem xmlns="urn:jboss:domain:logging:1.1">

                            <console-handler name="CONSOLE" autoflush="true">

                                <level name="INFO"/>

                                <formatter>

                                    <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                                </formatter>

                            </console-handler>

                            <periodic-rotating-file-handler name="FILE" autoflush="true">

                                <level name="INFO"/>

                                <formatter>

                                    <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                                </formatter>

                                <file relative-to="jboss.server.log.dir" path="server.log"/>

                                <suffix value=".yyyy-MM-dd"/>

                                <append value="true"/>

                            </periodic-rotating-file-handler>

                            <logger category="com.arjuna">

                                <level name="WARN"/>

                            </logger>

                            <logger category="org.apache.tomcat.util.modeler">

                                <level name="WARN"/>

                            </logger>

                            <logger category="sun.rmi">

                                <level name="WARN"/>

                            </logger>

                            <root-logger>

                                <level name="INFO"/>

                                <handlers>

                                    <handler name="CONSOLE"/>

                                    <handler name="FILE"/>

                                </handlers>

                            </root-logger>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:datasources:1.0">

                            <datasources>

                                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="H2DS" enabled="true" jta="true" use-java-context="true" use-ccm="true">

                                    <connection-url>

                                        jdbc:h2:mem:test;DB_CLOSE_DELAY=-1

                                    </connection-url>

                                    <driver>

                                        h2

                                    </driver>

                                    <pool>

                                        <prefill>

                                            false

                                        </prefill>

                                        <use-strict-min>

                                            false

                                        </use-strict-min>

                                        <flush-strategy>

                                            FailingConnectionOnly

                                        </flush-strategy>

                                    </pool>

                                    <security>

                                        <user-name>

                                            sa

                                        </user-name>

                                        <password>

                                            sa

                                        </password>

                                    </security>

                                </datasource>

                                <datasource jndi-name="SCHWIMMBAD_DS" pool-name="SCHWIMMBAD_DS_Pool" enabled="true" jta="true" use-java-context="true" use-ccm="true">

                                    <connection-url>

                                        jdbc:mysql://localhost/schwimmbad

                                    </connection-url>

                                    <driver>

                                        mysql-connector-java-5.1.17.jar

                                    </driver>

                                    <security>

                                        <user-name>

                                            hauke

                                        </user-name>

                                        <password>

                                            password

                                        </password>

                                    </security>

                                </datasource>

                                <drivers>

                                    <driver name="h2" module="com.h2database.h2">

                                        <xa-datasource-class>

                                            org.h2.jdbcx.JdbcDataSource

                                        </xa-datasource-class>

                                    </driver>

                                </drivers>

                            </datasources>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:deployment-scanner:1.0">

                            <deployment-scanner name="default" path="deployments" scan-enabled="true" scan-interval="5000" relative-to="jboss.server.base.dir" deployment-timeout="60"/>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:ee:1.0"/>

                        <subsystem xmlns="urn:jboss:domain:ejb3:1.1" lite="true">

                            <session-bean>

                                <stateless>

                                    <bean-instance-pool-ref pool-name="slsb-strict-max-pool"/>

                                </stateless>

                            </session-bean>

                            <pools>

                                <bean-instance-pools>

                                    <strict-max-pool name="slsb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>

                                </bean-instance-pools>

                            </pools>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:infinispan:1.0" default-cache-container="hibernate">

                            <cache-container name="hibernate" default-cache="local-query">

                                <local-cache name="entity">

                                    <eviction strategy="LRU" max-entries="10000"/>

                                    <expiration max-idle="100000"/>

                                </local-cache>

                                <local-cache name="local-query">

                                    <eviction strategy="LRU" max-entries="10000"/>

                                    <expiration max-idle="100000"/>

                                </local-cache>

                                <local-cache name="timestamps">

                                    <eviction strategy="NONE"/>

                                </local-cache>

                            </cache-container>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:jaxrs:1.0"/>

                        <subsystem xmlns="urn:jboss:domain:jca:1.0">

                            <archive-validation enabled="false"/>

                            <bean-validation enabled="false"/>

                            <default-workmanager>

                                <short-running-threads blocking="true" allow-core-timeout="false">

                                    <core-threads count="10" per-cpu="20"/>

                                    <queue-length count="10" per-cpu="20"/>

                                    <max-threads count="10" per-cpu="20"/>

                                    <keepalive-time time="10" unit="SECONDS"/>

                                </short-running-threads>

                                <long-running-threads blocking="true" allow-core-timeout="false">

                                    <core-threads count="10" per-cpu="20"/>

                                    <queue-length count="10" per-cpu="20"/>

                                    <max-threads count="10" per-cpu="20"/>

                                    <keepalive-time time="10" unit="SECONDS"/>

                                </long-running-threads>

                            </default-workmanager>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:jmx:1.0">

                            <jmx-connector server-binding="jmx-connector-server" registry-binding="jmx-connector-registry"/>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:jpa:1.0">

                            <jpa default-datasource=""/>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:naming:1.0"/>

                        <subsystem xmlns="urn:jboss:domain:osgi:1.0" activation="lazy">

                            <configuration pid="org.apache.felix.webconsole.internal.servlet.OsgiManager">

                                <property name="manager.root">

                                    jboss-osgi

                                </property>

                            </configuration>

                            <properties>

                                <property name="org.jboss.osgi.system.modules">

                                    org.apache.commons.logging,

                                                                                                                                                                                                                                                                                                                                                                                    org.apache.log4j,

                                                                                                                                                                                                                                                                                                                                                                                    org.jboss.as.osgi,

                                                                                                                                                                                                                                                                                                                                                                                    org.slf4j,

                                </property>

                                <property name="org.osgi.framework.startlevel.beginning">

                                    1

                                </property>

                                <property name="org.osgi.framework.system.packages.extra">

                                    org.apache.commons.logging;version=1.1.1,

                                                                                                                                                                                                                                                                                                                                                                                    org.apache.log4j;version=1.2,

                                                                                                                                                                                                                                                                                                                                                                                    org.jboss.as.osgi.service;version=7.0,

                                                                                                                                                                                                                                                                                                                                                                                    org.jboss.osgi.deployment.interceptor;version=1.0,

                                                                                                                                                                                                                                                                                                                                                                                    org.jboss.osgi.spi.capability;version=1.0,

                                                                                                                                                                                                                                                                                                                                                                                    org.jboss.osgi.spi.util;version=1.0,

                                                                                                                                                                                                                                                                                                                                                                                    org.jboss.osgi.testing;version=1.0,

                                                                                                                                                                                                                                                                                                                                                                                    org.jboss.osgi.vfs;version=1.0,

                                                                                                                                                                                                                                                                                                                                                                                    org.slf4j;version=1.5.10,

                                </property>

                            </properties>

                            <modules>

                                <module identifier="javaee.api"/>

                                <module identifier="org.jboss.logging"/>

                                <module identifier="org.apache.aries.util"/>

                                <module identifier="org.jboss.osgi.webconsole"/>

                                <module identifier="org.osgi.compendium"/>

                                <module identifier="org.apache.felix.log" startlevel="1"/>

                                <module identifier="org.jboss.osgi.logging" startlevel="1"/>

                                <module identifier="org.apache.felix.configadmin" startlevel="1"/>

                                <module identifier="org.jboss.as.osgi.configadmin" startlevel="1"/>

                                <module identifier="org.apache.aries.jmx" startlevel="2"/>

                                <module identifier="org.apache.felix.eventadmin" startlevel="2"/>

                                <module identifier="org.apache.felix.metatype" startlevel="2"/>

                                <module identifier="org.apache.felix.scr" startlevel="2"/>

                                <module identifier="org.apache.felix.webconsole" startlevel="2"/>

                                <module identifier="org.jboss.osgi.jmx" startlevel="2"/>

                                <module identifier="org.jboss.osgi.http" startlevel="2"/>

                                <module identifier="org.jboss.osgi.blueprint" startlevel="3"/>

                                <module identifier="org.jboss.osgi.webapp" startlevel="3"/>

                                <module identifier="org.jboss.osgi.xerces" startlevel="3"/>

                            </modules>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:remoting:1.0"/>

                        <subsystem xmlns="urn:jboss:domain:resource-adapters:1.0"/>

                        <subsystem xmlns="urn:jboss:domain:sar:1.0"/>

                        <subsystem xmlns="urn:jboss:domain:security:1.0">

                            <security-domains>

                                <security-domain name="other" cache-type="default">

                                    <authentication>

                                        <login-module code="Disabled" flag="required"/>

                                    </authentication>

                                </security-domain>

                            </security-domains>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:threads:1.0"/>

                        <subsystem xmlns="urn:jboss:domain:transactions:1.0">

                            <core-environment>

                                <process-id>

                                    <uuid/>

                                </process-id>

                            </core-environment>

                            <recovery-environment socket-binding="txn-recovery-environment" status-socket-binding="txn-status-manager"/>

                            <coordinator-environment default-timeout="300"/>

                            <object-store/>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:web:1.0" default-virtual-server="default-host">

                            <connector name="http" protocol="HTTP/1.1" socket-binding="http" scheme="http"/>

                            <virtual-server name="default-host" enable-welcome-root="true">

                                <alias name="localhost"/>

                                <alias name="example.com"/>

                            </virtual-server>

                        </subsystem>

                        <subsystem xmlns="urn:jboss:domain:weld:1.0"/>

                    </profile>

                    <interfaces>

                        <interface name="management">

                            <inet-address value="127.0.0.1"/>

                        </interface>

                        <interface name="public">

                            <inet-address value="127.0.0.1"/>

                        </interface>

                    </interfaces>

                    <socket-binding-group name="standard-sockets" default-interface="public">

                        <socket-binding name="http" port="8080"/>

                        <socket-binding name="https" port="8443"/>

                        <socket-binding name="jmx-connector-registry" port="1090"/>

                        <socket-binding name="jmx-connector-server" port="1091"/>

                        <socket-binding name="jndi" port="1099"/>

                        <socket-binding name="osgi-http" port="8090"/>

                        <socket-binding name="remoting" port="4447"/>

                        <socket-binding name="txn-recovery-environment" port="4712"/>

                        <socket-binding name="txn-status-manager" port="4713"/>

                    </socket-binding-group>

                    <deployments>

                        <deployment name="mysql-connector-java-5.1.17.jar" runtime-name="mysql-connector-java-5.1.17.jar">

                            <content sha1="60d52df83d1cc6bcfcb4bf7da3d5b3b912e82d8b"/>

                        </deployment>

                    </deployments>

                </server>

                {code}

                • 5. Re: JMS problem on JBoss 7.0.1 Final with JNDI context
                  Fabrizio Benedetti Novice

                  There is no "messaging" subsystem!

                  Take standalone-preview.xml as template.

                  • 6. Re: JMS problem on JBoss 7.0.1 Final with JNDI context
                    Hauke Gulich Newbie

                    Hi,

                     

                    getting closer now.

                     

                    I didn't get the standalone.xml system right away. I thought that jboss would load all standalone*.xml files. I created the queue inside the standalone-xts.xml file

                     

                    So I copied the subsystem tag messaging to standalone.xml (from my standalone-xts.xml) and added the socket binding and the extension.

                    Thanks to http://community.jboss.org/thread/169838

                     

                    But now I get this error

                     

                     

                    {color:#f00}

                    21:02:58,665 ERROR Caused by: org.jboss.modules.ModuleNotFoundException: Module org.jboss.as.messaging:main is not found

                    {color}

                     

                    I just looked at the jboss\modules\org\jboss\as\messaging directory and it's empty.

                     

                    So I downloaded the "everything" version of jboss 7.0.1-Final and copied all modules and that error is gone.

                     

                    THANK YOU !!!

                     

                    Hauke

                    • 7. Re: JMS problem on JBoss 7.0.1 Final with JNDI context
                      Leonardo Silva Newbie

                      Hi All,

                       

                      Just to help I'll describe how to install the resource adapter, follow these steps :

                       

                      1 - Install jboss-as-web-7.0.2.Final

                      2 - Download wmq.jmsra.rar (I got it from mqc6_6.0.2.11_win.zip - IBM MQ client)

                      3 - Change the standalone.xml

                                <subsystem xmlns="urn:jboss:domain:ejb3:1.1" lite="false">

                                  <mdb>

                                      <resource-adapter-ref resource-adapter-name="wmq.jmsra.rar"/>

                                  </mdb>

                                  ....

                      4 - Deploy wmq.jmsra.rar to deployments folder

                      5 - Start the server

                       

                      That's all folks!