6 Replies Latest reply on Mar 14, 2007 5:36 AM by emcwoo

    javax.naming.NoInitialContextException error when accessing

    emcwoo

      Problem description:
      The javax.naming.NoInitialContextException was encountered when
      running the QUEUE example with the following jndi.properties setting

      java.naming.factory.initial=org.jnp.interfaces.HttpNamingContextFactory
      java.naming.provider.url=http://localhost:8080/invoker/JNDIFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

      whereas the QUEUE example runs successfully with the following
      default setting:

      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

      Version used:
      JBoss 4.0.5GA
      Boss Messaging 1.0.1SP2

      OS: Windows or UNIX

      Help on this problem is much appreciated!

        • 1. Re: javax.naming.NoInitialContextException error when access
          jaikiran

           

          java.naming.factory.initial=org.jnp.interfaces.HttpNamingContextFactory
          java.naming.provider.url=http://localhost:8080/invoker/JNDIFactory
          java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces


          That's not the right url. Any reason why you are changing these properties instead of using the default one?



          • 2. Re: javax.naming.NoInitialContextException error when access
            emcwoo

            I followed the steps in:

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

            However, the error javax.naming.NoInitialContextException was encountered.

            The error also occurred after I followed the steps in

            http://docs.jboss.org/jbossas/admindevel326/html/ch3.chapter.html#ch3.accessingjndi to set the provider url as follows instead

            java.naming.provider.url=http://localhost:8080/invoker/JMXInvokerServlet


            • 3. Re: javax.naming.NoInitialContextException error when access
              jaikiran

              emcwoo, i havent tried this before so i might not be of much help. However, you could try changing

              java.naming.provider.url=http://localhost:8080/invoker/JMXInvokerServlet


              to

              java.naming.provider.url=http://<your-machine-name>:8080/invoker/JMXInvokerServlet


              I did the following to figure out what provider url to specify:

              - Go to http://localhost:8080/jmx-console
              - Click on service=invoker,target=Naming,type=http
              - On the page that comes up, check what's the value in the textbox corresponding to the 'InvokerURL' property.
              - Use this exact value as the value for java.naming.provider.url and then use it for running your application






              • 4. Re: javax.naming.NoInitialContextException error when access
                emcwoo

                jaikiran, thanks for your help. However, the error occurred no matter how I set the java.naming.provider.url, even for a non-exist URL. From the error message on the client side quoted below, the problem seems related to the property java.naming.factory.initial=org.jnp.interfaces.HttpNamingContextFactory


                Detail error message:

                [java] javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.HttpNamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.HttpNamingContextFactory]
                [java] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
                [java] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
                [java] at javax.naming.InitialContext.init(InitialContext.java:223)
                [java] at javax.naming.InitialContext.(InitialContext.java:175)
                [java] at org.jboss.example.jms.common.Util.doesDestinationExist(Util.java:43)
                [java] at org.jboss.example.jms.common.ExampleSupport.setup(ExampleSupport.java:146)
                [java] at org.jboss.example.jms.common.ExampleSupport.run(ExampleSupport.java:57)
                [java] at org.jboss.example.jms.queue.QueueExample.main(QueueExample.java:134)
                [java] Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.HttpNamingContextFactory
                [java] at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
                [java] at java.security.AccessController.doPrivileged(Native Method)
                [java] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                [java] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
                [java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
                [java] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
                [java] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
                [java] at java.lang.Class.forName0(Native Method)
                [java] at java.lang.Class.forName(Class.java:242)
                [java] at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
                [java] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
                [java] ... 7 more

                • 5. Re: javax.naming.NoInitialContextException error when access
                  jaikiran

                   

                  Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.HttpNamingContextFactory


                  Hmmm.... Try this, change

                  java.naming.factory.initial=org.jnp.interfaces.HttpNamingContextFactory


                  to

                  java.naming.factory.initial=org.jboss.naming.HttpNamingContextFactory


                  P.S.: The org.jboss.naming.HttpNamingContextFactory is present in the jboss.jar file. In case you dont have this jar file in your classpath, you can find it in %JBOSS_HOME%\server\default\lib folder




                  • 6. Re: javax.naming.NoInitialContextException error when access
                    emcwoo

                    I have modified the classpath (by modifying the build file of the QUEUE example) to include the jar files under the following folders:

                    C:\Program Files\jboss-4.0.4.GA\server\default\lib
                    C:\Program Files\jboss-4.0.4.GA\server\messaging\lib
                    C:\Program Files\jboss-4.0.4.GA\client

                    However, the following error was encountered.


                    [java] javax.naming.NamingException: Failed to retrieve Naming interface [Root exception is java.io.IOException]
                    [java] at org.jboss.naming.HttpNamingContextFactory.getInitialContext(HttpNamingContextFactory.java:84)
                    [java] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
                    [java] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
                    [java] at javax.naming.InitialContext.init(InitialContext.java:219)
                    [java] at javax.naming.InitialContext.(InitialContext.java:175)
                    [java] at org.jboss.example.jms.common.Util.doesDestinationExist(Util.java:43)
                    [java] at org.jboss.example.jms.common.ExampleSupport.setup(ExampleSupport.java:146)
                    [java] at org.jboss.example.jms.common.ExampleSupport.run(ExampleSupport.java:57)
                    [java] at org.jboss.example.jms.queue.QueueExample.main(QueueExample.java:134)
                    [java] Caused by: java.io.IOException
                    [java] at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:602)
                    [java] at org.jboss.naming.HttpNamingContextFactory.getNamingServer(HttpNamingContextFactory.java:133)
                    [java] at org.jboss.naming.HttpNamingContextFactory.getInitialContext(HttpNamingContextFactory.java:80)
                    [java] ... 8 more
                    [java] Caused by: java.net.ConnectException: Connection timed out: connect
                    [java] at java.net.PlainSocketImpl.socketConnect(Native Method)
                    [java] at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
                    [java] at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
                    [java] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
                    [java] at java.net.Socket.connect(Socket.java:452)
                    [java] at java.net.Socket.connect(Socket.java:402)
                    [java] at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
                    [java] at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
                    [java] at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
                    [java] at sun.net.www.http.HttpClient.(HttpClient.java:306)
                    [java] at sun.net.www.http.HttpClient.(HttpClient.java:267)
                    [java] at sun.net.www.http.HttpClient.New(HttpClient.java:339)
                    [java] at sun.net.www.http.HttpClient.New(HttpClient.java:320)
                    [java] at sun.net.www.http.HttpClient.New(HttpClient.java:315)
                    [java] at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:521)
                    [java] at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:498)
                    [java] at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:626)
                    [java] at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:1502)
                    [java] at java.net.URLConnection.getHeaderFieldInt(URLConnection.java:476)
                    [java] at java.net.URLConnection.getContentLength(URLConnection.java:371)
                    [java] at org.jboss.naming.HttpNamingContextFactory.getNamingServer(HttpNamingContextFactory.java:128)
                    [java] ... 9 more