1 Reply Latest reply on Feb 7, 2002 6:04 AM by Sebastian Hallensleben

    Problem while connecting to remote machine which is running

    seshusrinivas Newbie

      Hi,

      We are running the java client from one system to connect JBOSS2.4.4 running in other system. For that we used JMSHelper which is giving the exception

      "java.lang.ClassCastException:javax.naming.Reference".

      This exception is coming after the statement System.out.println("init 1"); and before the statement System.out.println("init 2"); in the JMSHelper.java code given below.

      Please let me know the problem we are in the middle of the project.

      Thanks,

      Bye
      Seshu Srinivas



      Below are the 2 files JMSUtility and JMSHelper.

      import java.io.*;
      import java.util.*;
      import javax.transaction.*;
      import javax.naming.*;
      import javax.jms.*;

      public class JMSUtility
      {
      public static InitialContext getInitialContext()
      throws NamingException
      {
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL,"jeelani:1099");
      env.put("java.naming.rmi.security.manager","no");
      env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming");
      return new InitialContext(env);
      }

      }

      JMSHelper.java
      -----------------

      import java.io.*;
      import java.util.*;
      import javax.transaction.*;
      import javax.naming.*;
      import javax.jms.*;

      import javax.mail.internet.*;

      import com.insync.rnif.util.beans.JMSUtility;

      Public class JMSHelper
      {
      public final static String QUEUE = "queue/rnifQueue";
      public final static String JMS_FACTORY = "QueueConnectionFactory";

      private QueueConnectionFactory qconFactory;
      private QueueConnection qcon;
      private QueueSession qsession;
      private QueueSender qsender;
      private Queue queue;
      private TextMessage msg;

      public JMSHelper() throws Exception
      {
      InitialContext ic = JMSUtility.getInitialContext();
      System.out.println("context of jeelani :"+ic);
      this.init(ic, QUEUE);
      }

      public void init(Context ctx, String queueName)
      throws NamingException, JMSException
      {
      System.out.println("init 1");
      qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
      System.out.println("init 2");
      qcon = qconFactory.createQueueConnection();
      System.out.println("init 3");
      qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      System.out.println("init 4");
      queue = (Queue) ctx.lookup(queueName);
      System.out.println("init 5");
      qsender = qsession.createSender(queue);
      System.out.println("init 6");
      msg = qsession.createTextMessage();
      System.out.println("init 7");
      qcon.start();
      }

      public void send(String message) throws JMSException
      {
      System.out.println("init 8");
      msg.setText(message);
      System.out.println("init 9");
      qsender.send(msg);
      System.out.println("init 10");
      }

      public void close() throws JMSException
      {
      qsender.close();
      qsession.close();
      qcon.close();
      }
      }