Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-3402

Unable to use mongo+srv scheme when java.naming.provider.url JNDI property is invalid

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.1.0
    • Affects Version/s: 3.11.0
    • Component/s: Configuration
    • Labels:
      None

      When creating a MongoClient with mongo+srv scheme and that java.naming.provider.url JNDI property is set to a file URL, the driver throws

       

      com.mongodb.MongoClientException: Unable to support mongodb+srv// style connections as the 'com.sun.jndi.dns.DnsContextFactory' class is not available in this JRE. A JNDI context is required for resolving SRV records.com.mongodb.MongoClientException: Unable to support mongodb+srv// style connections as the 'com.sun.jndi.dns.DnsContextFactory' class is not available in this JRE. A JNDI context is required for resolving SRV records.
       at com.mongodb.internal.dns.DefaultDnsResolver.createDnsDirContext(DefaultDnsResolver.java:152)
      at com.mongodb.internal.dns.DefaultDnsResolver.resolveAdditionalQueryParametersFromTxtRecords(DefaultDnsResolver.java:112)
      at com.mongodb.ConnectionString.<init>(ConnectionString.java:377)
      at com.mongodb.client.MongoClients.create(MongoClients.java:61)
      at io.toro.fluxengine.Testeer.srvTest(Testeer.java:17)
      at ......
      org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)Caused by: javax.naming.ConfigurationException: file:/tmp is not a valid DNS pseudo-URL
      at com.sun.jndi.dns.DnsContextFactory.urlToContext(DnsContextFactory.java:105)
      at com.sun.jndi.dns.DnsContextFactory.getInitialContext(DnsContextFactory.java:64)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
      at javax.naming.InitialContext.init(InitialContext.java:244)
      at javax.naming.InitialContext.<init>(InitialContext.java:216)
      at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:101)
      at com.mongodb.internal.dns.DefaultDnsResolver.createDnsDirContext(DefaultDnsResolver.java:150)
      

       

      There are two issues here. First is that the exception message is misleading. DefaultDnsResolver.createDnsDirContext assumes all NamingException}}s are caused by the unavailability of DnsContextFactory. Checking the causing exception, it fails because I have this JNDI property

       

      java.naming.provider.url=file:/tmp

      which is not supported by the DnsContextFactory.

       

      To reproduce:

         1. Add jndi.properties file to the classpath with content

      java.naming.provider.url=file:/tmp

         2. Run the following code

      MongoClients.create( "mongodb+srv://server.example.com/" );

       

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            djgomez23@gmail.com Daniel John Gomez
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: