2 Replies Latest reply on Dec 1, 2004 1:42 PM by George Berish

    One Last ConnectionFactory Lookup Question.

    George Berish Novice

      Hi:

      I have tried for hours to read all the questions related to looking up a ConnectionFactory object with no success. Is there anyone who would be willing to tell me how to this code to get an out of the box, locally installed JBoss 3.2 give me the object?

      import java.util.*;
      import javax.jms.*;
      import javax.naming.*;
      
      public class JmsConnection {
      
       public static void main (String[] args) {
       System.out.println ("Start Main");
       JmsConnection c = new JmsConnection ();
       System.out.println ("End Main");
       }
      
       /***
       * Constructor
       ***/
       public JmsConnection () {
       try {
       Context jndiContext = getInitialContext();
       System.out.println("Initial context obtained");
       Object tmp = jndiContext.lookup("ConnectionFactory");
       } catch (NamingException ne) {
       System.out.println ("NamingException Msg: "+ne.getMessage ());
       }
       }
      
       /***
       * Methods
       ***/
       public Context getInitialContext() throws NamingException {
       Properties env = new Properties();
       env.put(
       Context.INITIAL_CONTEXT_FACTORY,
       "org.jboss.naming.NamingContextFactory");
       env.put(
       Context.PROVIDER_URL,
       "jnp://localhost:1099/");
       return new InitialContext(env);
       }
      }
      The screen print is:
      Start Main
      Initial context obtained
      NamingException Msg: Receive timed out
      End Main
      Press any key to continue . . .



        • 1. Re: One Last ConnectionFactory Lookup Question.
          Elias Ross Master


          What does "telnet 1099" give you?

          Are you using factory.url?

          java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
          java.naming.provider.url=jnp://localhost:1099
          java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

          • 2. Re: One Last ConnectionFactory Lookup Question.
            George Berish Novice

            Thanks.

            It seems I needed to add "java.naming.factory.url.pkgs"="org.jboss.naming:org.jnp.interfaces" to the Properties parameter for new InitialContext ().

            The code and screen output is shown below for the next new guy to attempt JMS.

            (PS: I didn't understand the question about telnet.)

            import java.util.*;
            import javax.jms.*;
            import javax.naming.*;
            
            public class JmsConnection {
            
             public static void main (String[] args) {
             System.out.println ("Start Main");
             JmsConnection c = new JmsConnection ();
             System.out.println ("End Main");
             }
            
             /***
             * Constructor
             ***/
             public JmsConnection () {
             try {
             Context jndiContext = getInitialContext();
             System.out.println("Initial context obtained");
             Object tmp = jndiContext.lookup("ConnectionFactory");
             System.out.println ("ConnectionFactory looked up as Object");
             TopicConnectionFactory factory = (TopicConnectionFactory) tmp;
             System.out.println ("Object cast to TopicConnectionFactory");
             } catch (NamingException ne) {
             System.out.println ("NamingException Msg: "+ne.getMessage ());
             } catch (NoClassDefFoundError ncfe) {
             System.out.println ("NoClassDefFoundERror Msg: "+ncfe.getMessage ());
             }
             }
            
             /***
             * Methods
             ***/
             public Context getInitialContext() throws NamingException {
             Properties env = new Properties();
             env.put(
             Context.INITIAL_CONTEXT_FACTORY,
             "org.jboss.naming.NamingContextFactory");
             env.put(
             Context.PROVIDER_URL,
             "jnp://localhost:1099/");
             env.put (
             "java.naming.factory.url.pkgs",
             "org.jboss.naming:org.jnp.interfaces");
             return new InitialContext(env);
             }
            
            }

            Screen Output
            Start Main
            Initial context obtained
            ConnectionFactory looked up as Object
            Object cast to TopicConnectionFactory
            End Main
            Press any key to continue . . .