title: LdapContext socket closed exception when server url is up and running
body: <p>I cannot tell if its a credentials/SSL issue or an LDAP configuration issue on the server. I tried accessing the local version and i had no problem (then again local Ldap and server setup is a little different). The socket is definitely not closed as we are using that url in our processing system and it is not down.</p>
  
  <p>Code is failing at this line:</p>
  
  <pre><code>NamingEnumeration&lt;?&gt; namingEnum = ctx.search("dc=barney,dc=com", "(objectclass=person)", getSimpleSearchControls());    
  </code></pre>
  
  <p>Code block:</p>
  
  <pre><code>final String ldapAdServer = "ldap://myspecialhost.barney.us:389";                               
          env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL, ldapAdServer);    
  LdapContext ctx = new InitialLdapContext(env, null);
              ctx.setRequestControls(null);
     NamingEnumeration&lt;?&gt; namingEnum = ctx.search("dc=barney,dc=com", "(objectclass=person)", getSimpleSearchControls()); 
  </code></pre>
  
  <p>And the stacktrace is here:</p>
  
  <pre><code>javax.naming.ServiceUnavailableException: tiffany.barney.ca:389; socket closed; remaining name 'dc=barney,dc=com'
      at com.sun.jndi.ldap.Connection.readReply(Connection.java:437)
      at com.sun.jndi.ldap.LdapClient.getSearchReply(LdapClient.java:613)
      at com.sun.jndi.ldap.LdapClient.search(LdapClient.java:536)
      at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:1965)
      at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1827)
      at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1752)
      at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:368)
      at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:338)
      at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:321)
      at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:248)
      at com.barney.shopping.tiffany.LDAPImpTest.main(LDAPImplTest.java:154)
  </code></pre>
  
  <p>EDIT 1:
  I tried using a different url and i get a connection timed out. Does this new url seem <em>more right</em> and i'm getting closer to the correct url perhaps?</p>
  
  <p>EDIT 2:</p>
  
  <p>new stacktrace</p>
  
  <pre><code>javax.naming.CommunicationException: possibleURL:389 [Root exception is java.net.ConnectException: Connection timed out: connect]
      at com.sun.jndi.ldap.Connection.&lt;init&gt;(Connection.java:209)
      at com.sun.jndi.ldap.LdapClient.&lt;init&gt;(LdapClient.java:116)
      at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1582)
      at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2678)
      at com.sun.jndi.ldap.LdapCtx.&lt;init&gt;(LdapCtx.java:296)
      at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)
      at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193)
      at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136)
      at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
      at javax.naming.InitialContext.init(InitialContext.java:223)
      at javax.naming.ldap.InitialLdapContext.&lt;init&gt;(InitialLdapContext.java:134)
      at blablalbla.LDAPInterfaceTest.main(LDAPInterfaceTest.java:154)
  Caused by: java.net.ConnectException: Connection timed out: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
      at java.net.Socket.connect(Socket.java:529)
      at java.net.Socket.connect(Socket.java:478)
      at java.net.Socket.&lt;init&gt;(Socket.java:375)
      at java.net.Socket.&lt;init&gt;(Socket.java:189)
      at com.sun.jndi.ldap.Connection.createSocket(Connection.java:351)
      at com.sun.jndi.ldap.Connection.&lt;init&gt;(Connection.java:186)
      ... 13 more
  </code></pre>