1 Reply Latest reply: Feb 20, 2013 11:49 AM by 989618 RSS

    java:comp/env NameNotFoundException

    989618
      I have been digging around for a long time trying to find an answer to this problem but have yet to find one... I am running Weblogic 10.3.6

      When I run the following code on an admin server (doing this to do LDAP lookups) it fails:
              try {
               ctx = new InitialContext();
              } catch (NamingException e)
              {
                  // this succeeds every time
              }
      
              try {
                      server = (MBeanServerConnection) ctx.lookup("java:comp/env/jmx/domainRuntime");
                  } catch (NamingException e) {
                      // this fails every time with a NameNotFoundException remaining name: env/jmx/domainRuntime
                  }
      So I decided to try and list what I could in the context like:
              NamingEnumeration<NameClassPair> list = ctx.list("java:");
           while (list.hasMore()) {
                  log.error("CTX FOR 'JAVA:' IS : " + list.next().getName());
           }
      The above prints out that 'comp' and 'global' are there but when I try this:
              NamingEnumeration<NameClassPair> list = ctx.list("java:comp");
           while (list.hasMore()) {
                  log.error("CTX FOR 'JAVA:COMP' IS : " + list.next().getName());
      I get another NameNotFoundException for /comp. Any idea what is going on? Thanks for any help.

      --S

      Edited by: 986615 on Feb 6, 2013 3:25 PM
        • 1. Re: java:comp/env NameNotFoundException
          989618
          I don't know how this error began to pop-up. This code worked previously... that said we found a workaround. The workaround is to always connect as if you are running remotely, don't bother doing the check to see if you are running on the admin server. Here is what we are doing now:
                     // Make remote connection to Mbean
                      Hashtable<String, Object> h = new Hashtable<String, Object>();
                      h.put(Context.SECURITY_PRINCIPAL, adminServerUsername);
          
                      h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
                      h.put("jmx.remote.x.request.waiting.timeout", new Long(10000));
          
                      String jndiroot = "/jndi/";
                      String mserver = "weblogic.management.mbeanservers.domainruntime";  // you can see this in the JNDI tree for the admin server
                      JMXServiceURL serviceURL = null;
          
                      // Make a JMX URL object
                      try {
                          serviceURL = new JMXServiceURL(protocol, adminServerHost, adminServerPortSSL, jndiroot + mserver);
                      } catch (MalformedURLException e) {
                          e.printStackTrace();
                      }
          
                      Object connector = null;
          
                      // Get MBEAN connector
                      h.put(Context.SECURITY_CREDENTIALS, credential);
                      try {
                          connector = JMXConnectorFactory.connect(serviceURL, h);
                          h.clear();
                          h = null;
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
          
                      // Get Mbean server connection
                      try {
                          server = ((JMXConnector) connector).getMBeanServerConnection();
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
          I hope this helps some poor soul out there that ran into the same thing I did.

          --S