5 Replies Latest reply on Sep 30, 2009 5:48 AM by gunther verhemeldonck

    Fail to get a remote JMS Session due to NullPointerException

    gunther verhemeldonck Newbie

      Hi all

      My JMS client application running on JBoss 4.2.3 fails to create a JMS Session on startup due to a NullpointerException. Threads mentioned below already discuss the issue, but even when trying to change the scoping/loader the issue remains.

      I've got a standalone WAR file that connects to the JBM 1.4.4 server from the ServletContextListener.contextInitialized() callback method.

      I've tried adding a jboss-web.xml but without success.

      13:37:18,980 INFO [StartupListener] ~~ Creating JMS Session ...
      13:37:18,989 FATAL [StartupListener]
       at org.jboss.jms.client.container.FailoverValveInterceptor.invoke(FailoverValveInterceptor.java:87)
       at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:105)
       at org.jboss.jms.client.delegate.ClientConnectionDelegate$createSessionDelegate_6052335267724906805.invokeNext(ClientConnectionDelegate$createSessionDelegate_6052335267724906805.java)
       at org.jboss.jms.client.container.ClosedInterceptor.invoke(ClosedInterceptor.java:170)
       at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:105)
       at org.jboss.jms.client.delegate.ClientConnectionDelegate$createSessionDelegate_6052335267724906805.invokeNext(ClientConnectionDelegate$createSessionDelegate_6052335267724906805.java)
       at org.jboss.jms.client.delegate.ClientConnectionDelegate.createSessionDelegate(ClientConnectionDelegate.java)
       at org.jboss.jms.client.JBossConnection.createSessionInternal(JBossConnection.java:269)
       at org.jboss.jms.client.JBossConnection.createSession(JBossConnection.java:91)



      I'm stuck on this and I hope somebody can point me to a solution for this.

      Thank you in advance.


        • 1. Re: Fail to get a remote JMS Session due to NullPointerExcep
          gunther verhemeldonck Newbie

          If I'm using JBM from a JBoss 4.2.4 server, do I need to disable JBossMQ on the client server and/or also install JBM on this server? Or do I only need to make sure the jboss-remoting.jar and jboss-messaging-client.jar are on the clients' (WAR) classpath?

          Thank you

          • 2. Re: Fail to get a remote JMS Session due to NullPointerExcep
            Yong Hao Gao Master


            What's your code that makes the connection to jbm looks like?

            JBM and JBoss MQ cannot be mixed. You need to remove MQ stuff if you want JBM.

            Btw, we usually discuss jbm user issues in the user forum. This forum is for development discussion.

            • 3. Re: Fail to get a remote JMS Session due to NullPointerExcep
              gunther verhemeldonck Newbie

              Yes, I've removed the server/default/deploy/jms folder but the issue remains. The code works on Windows, but on linux with remoting this issue shows up. Here's the code that makes the connection:

              <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
               <property name="environment">
               <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
               <prop key="java.naming.provider.url">jnp://someIP:1099</prop>
               <prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
               <bean id="threadPoolSize" class="java.lang.Integer">
               <constructor-arg value="${threadPoolSize}"/>
               <bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
               <property name="jndiTemplate"><ref bean="jndiTemplate" /></property>
               <property name="jndiName" value="/ConnectionFactory"/>
               <bean id="requestQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
               <property name="jndiTemplate"><ref bean="jndiTemplate" /></property>
               <property name="jndiName" value="${queue}"/>

              public class StartupListener implements ServletContextListener {
               private static final Log log = LogFactory.getLog(StartupListener.class);
               private static Connection connection;
               private static Session session;
               private static MessageConsumer consumer;
               private static Boolean run = Boolean.TRUE;
               private static ExecutorService pool;
               private static Thread daemonThread;
               private static final String PREFIX = " ~~ ";
               private static MeteoService metService;
               * Startup trigger of the application.
               public void contextInitialized(ServletContextEvent ctx) {
               log.info("==== Initializing ServiceBroker");
               logInfo("Creating polling thread ...");
               daemonThread = new Thread(new MessageDispatcher());
               try {
               ApplicationContext _ctx = WebApplicationContextUtils.getWebApplicationContext(ctx.getServletContext());
               metService = (MeteoService) _ctx.getBean("metService");
               logInfo("Starting the Session ...");
               logInfo("Starting a Daemon Thread responsible for message dispatching ...");
               log.info("==== ServiceBroker initialized successfully");
               } catch (Throwable e) {
               log.fatal(e.getMessage(), e);
               * This is a context lifecycle (callback) method.
               * The Servlet Context is being destroyed by the Container due to a shutdown.
               * As a result we need to clean up our privately managed resources.
               public void contextDestroyed(ServletContextEvent ctx) {
               synchronized (run) {
               log.info("==== Shutting down PilotBriefing ServiceBroker ...");
               run = Boolean.FALSE;
               logInfo("Interrupting polling thread ...");
               if (session != null) {
               try {
               logInfo("Closing JMS Session ...");
               } catch (JMSException e) {
               log.error(e.getMessage(), e);
               if (connection != null) {
               try {
               logInfo("Closing JMS Connection ...");
               } catch (JMSException e) {
               log.error(e.getMessage(), e);
               if (pool != null) {
               logInfo("Shutting down ThreadPool");
               log.info("==== ServiceBroker shutdown complete");
               private void logInfo(String msg) {
               log.info(PREFIX + msg);
               * Initialization of JMS environment.
               * @param _ctx external configuration parameters
               * @throws NamingException
               * @throws JMSException
               private void initializeJMSEnvironment(ApplicationContext _ctx) throws NamingException, JMSException {
               Queue queue = (Queue) _ctx.getBean("requestQueue");
               logInfo("Lookup of ConnectionFactory ...");
               ConnectionFactory cf = (ConnectionFactory) _ctx.getBean("jmsConnectionFactory");
               logInfo("Creating JMS Connection ...");
               connection = cf.createConnection();
               logInfo("Creating JMS Session ...");
               session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
               logInfo("Creating MessagConsumer ...");
               consumer = session.createConsumer(queue);
               * Setup a pool of worker threads for message handling.
               * @param _ctx external configuration parameters
               private void initializeWorkerThreadPool(ApplicationContext _ctx) {
               int poolSize = (Integer) _ctx.getBean("threadPoolSize");
               logInfo("Initializing Thread Pool [#" + poolSize + "] ...");
               pool = Executors.newFixedThreadPool(poolSize);
               * Daemon thread for the dispatching of incoming messages to a pooled Worker Thread that will handle the request.
               * This class is implemented as a Thread because otherwise the Servlet Container Thread that executes this listener class,
               * fails to complete as a result of the polling-loop.
               class MessageDispatcher implements Runnable {
               public void run() {
               try {
               while (run) {
               TextMessage message = (TextMessage) consumer.receive();
               if (message != null) {
               JMSUtils.printMessage("Received request", message);
               } catch (Throwable t) {
               log.error(t.getMessage(), t);
               * Factory method.
               * @param message
               * @return
               * @throws JMSException
               private Runnable createMessageHandler(TextMessage message) throws JMSException {
               return new MessageHandler(metService, session, message.getJMSReplyTo(), message.getJMSMessageID(), message.getText());