6 Replies Latest reply on Apr 4, 2006 6:28 AM by weston.price

    Problem in accessing Connection Factory

    baba79au

      Hi
      I am new to JBoss. I am having a problem accessing the "ConnectionFactory" to send a Message to Queue.

      The code i have used is below:


      InitialContext ctx;
      QueueConnectionFactory cf;
      QueueConnection connection;
      QueueSession session;
      Queue destination;
      QueueSender sender;
      TextMessage message;

      MessageToQueue mtq = new MessageToQueue();
      ctx= mtq.getInitialContext();

      cf = (QueueConnectionFactory)ctx.lookup("ConnectionFactory");
      destination = (Queue)ctx.lookup("advantJMS");



      My getInitialContext() method is having the following code:



      protected InitialContext getInitialContext() throws Exception {
      String url = "jnp://localhost:1099"; //specify the host name where JBoss is running on
      String user = null;
      String password = null;
      Properties properties = null;
      try {
      properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); //JBoss Naming Context
      properties.put(Context.PROVIDER_URL, url);
      properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      if (user != null) {
      properties.put(Context.SECURITY_PRINCIPAL, user);
      properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
      }

      return new InitialContext(properties);
      }
      catch(Exception e) {
      System.out.println("Unable to connect to JBoss server at " + url);
      System.out.println("Please make sure that the server is running.");
      throw e;
      }



      The error I am getting on is


      javax.naming.NameNotFoundException: ConnectionFactory not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:534)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at MessageToQueue.main(MessageToQueue.java:32)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)

        • 1. Re: Problem in accessing Connection Factory
          baba79au

          I would like to know is there any configuration setting to be added/enabled to activate the ConnectionFactory. Please help me...

          Thanks for your help..

          • 2. Re: Problem in accessing Connection Factory
            jaikiran

             

            cf = (QueueConnectionFactory)ctx.lookup("ConnectionFactory");


            Change this to:

            cf = (QueueConnectionFactory)ctx.lookup("java:/JmsXA");


            • 3. Re: Problem in accessing Connection Factory
              baba79au

              Hi
              Thanks for your reply, I tried accessing "java:/JmsXA", but agian the same error was thrown. Any suggestions please. I really need help solving this issue.

              Regards
              Bava S

              • 4. Re: Problem in accessing Connection Factory
                lafr

                Where does this piece of code run?
                Seems to me, that it is run inside jboss, not a standalone application.
                If so, avoid setting the properties again. They are already known.
                Try to simply use "ctx = new InitialContext()".
                This work for me perfect.

                • 5. Re: Problem in accessing Connection Factory
                  baba79au

                  Hi
                  I think there must be some sort of good documentation be provided on JBoss JMS features. As of i know i am really exhausted, it took totally 2 weeks to fix this error for me. I was continually searching on the net and then i came to the conclusion that I am not going to get any sort of help. So i started mining into the examples of the jboss server, where i found my self profound to know that to use JMS we need to configure the jdbc-state-service.xml & jdbc2-service.xml files for the particular database you are using.
                  So who ever maintaining this forum please be patient to look into the problem and provide solutions.

                  Regards
                  Baba S

                  • 6. Re: Problem in accessing Connection Factory
                    weston.price

                    Unfortunately, none of these response/posts are correct. JBossJMS can be used out of the box with no issues. But first, please read the following:


                    http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossHelp

                    At the very least, please provide the version of JBoss you are running, Operating system, etc, etc. Did you look at the JBoss Wiki, most notably the section on JMS?

                    http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossMQ

                    It is clear that you are accessing the JNDI context from outside of the server, therefore nothing in the java: namespace is available to you.

                    Did you check the JNDI view service of JBoss to make sure the CF is deployed correctly?

                    Try this stuff and post again.