4 Replies Latest reply on Aug 9, 2011 6:21 PM by shelleyb

    Failure to Instantiate DnsContextFactory

    shelleyb

      When attempting to create a new InitialDirContext using the com.sun.jndi.dns.DnsContextFactory, the following exception occurs:

      Caused by: javax.naming.NamingException: Failed instantiate InitialContextFactory com.sun.jndi.dns.DnsContextFactory from classloader ModuleClassLoader for Module "deployment.test-case.ear.test-web.war:main" from Service Module Loader
              at org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:58)
              at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:664) [:1.6.0_26]
              at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) [:1.6.0_26]
              at javax.naming.InitialContext.init(InitialContext.java:223) [:1.6.0_26]
              at javax.naming.InitialContext.(InitialContext.java:197) [:1.6.0_26]
              at javax.naming.directory.InitialDirContext.(InitialDirContext.java:82) [:1.6.0_26]
              at com.test.messaging.internal.resource.dns.DnsClientImpl.querySrv(DnsClientImpl.java:328) [dns-lookup-jar.jar:]
              ...
      
      16:36:36,000 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-5) Error listenerStart
      16:36:36,013 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-5) Context [/test] startup failed due to previous errors
      16:36:36,023 INFO  [org.jboss.web] (MSC service thread 1-5) registering web context: /test
      

      Here is my relevant code snippet:

      Hashtable env = new Hashtable();
      env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
      env.put("java.naming.authoritative", "false");
      env.put("com.sun.jndi.dns.recursion", "true");
      env.put("com.sun.jndi.dns.timeout.initial", timeoutProp);
      env.put("com.sun.jndi.dns.timeout.retries", "1");
      env.put("java.naming.provider.url", providerProp);
      DirContext ctx = new InitialDirContext(env);
      

      I found this thread which seemed very similar to the problem that I am running into, but setting the "jboss.modules.system.pkgs" property to "com.sun.jndi.dns" had no effect.

      I'm running JBoss AS 7.0.0.Final, using the 1.6.0_26 JRE.

      Any suggestions on how to resolve this problem would be greatly appreciated.

        • 1. Re: Failure to Instantiate DnsContextFactory
          shelleyb

          I found a workaround for this issue:

          • Create a com.sun.jndi.dns module, by copying $JBOSS_HOME/modules/com/sun/jndi/ldap to $JBOSS_HOME/modules/com/sun/jndi/dns and modify occurrences of "ldap" to "dns"
          • Add the following entry to the web module's MANIFEST.MF: Dependencies: com.sun.jndi.dns

          Although this now allows the DnsContextFactory to instantiate properly, this doesn't seem to be a feasible solution, requiring modification of all JBoss servers as well as any applications that utilize the DnsContextFactory. Is there a bug or enhancement that could be added to JBoss to prevent these manual modifications? Or is there already an existing approach that can resolve this issue?

          • 2. Re: Failure to Instantiate DnsContextFactory
            shelleyb

            I found an alternative that is slightly better. I added the jboss-deployment-structure.xml file to my EAR's META-INF directory, as follows:

            <jboss-deployment-structure>
            
                <sub-deployment name="test-web.war">
                    <dependencies>
                        <module name="deployment.com.sun.jndi.dns" />
                    </dependencies>
                </sub-deployment>
            
                <module name="deployment.com.sun.jndi.dns">
                    <dependencies>
                        <module name="system" export="false">
                            <exports>
                                <include-set>
                                    <path name="com/sun/jndi/dns"/>
                                </include-set>
                            </exports>
                        </module>
                    </dependencies>
                </module>
            
            </jboss-deployment-structure>
            

            This also worked, in lieu of the manifest entry and custom module in the jboss directory. This is slightly better since it only requires modification to the application, and not also the JBoss modules, but is unfortunate that all applications that use the DnsContextFactory must include this configuration. I'm still looking for suggestions on the most appropriate, recommended approach, particularly if there is a way that we can avoid including more JBoss-specific configuration in our applications.

            • 3. Re: Failure to Instantiate DnsContextFactory
              dmlloyd

              The first workaround will definitely solve the problem, but really this package path should just be added to the existing "sun.jdk" module.  Note that the second workaround will not work under 7.1 as the "system" module is being eliminated for various technical reasons.

               

              The suggested solution is to file an enhancement request to add the Sun JNDI DNS package to "sun.jdk".

              • 4. Re: Failure to Instantiate DnsContextFactory
                shelleyb

                Thanks, David! I've logged a feature request to get the DNS package (as well as a couple other missing packages) added to the "sun.jdk" module.