mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
13.01.2007 bc825f37f327005ce417c8bda658b591e5bca35a
Update the LDAPConnection object and the classes that use it to ensure that
it can perform an unbind before closing the connection.

OpenDS Issue Number: 1357
6 files modified
74 ■■■■ changed files
opends/src/dsml/org/opends/dsml/protocol/DSMLServlet.java 3 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPCompare.java 12 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPConnection.java 20 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPDelete.java 12 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPModify.java 13 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPSearch.java 14 ●●●● patch | view | raw | blame | history
opends/src/dsml/org/opends/dsml/protocol/DSMLServlet.java
@@ -51,6 +51,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -302,7 +303,7 @@
      }
    } finally {
      if (connection != null) {
        connection.close();
        connection.close(new AtomicInteger(1));
      }
    }
  }
opends/src/server/org/opends/server/tools/LDAPCompare.java
@@ -808,6 +808,7 @@
      }
    }
    LDAPCompare ldapCompare = null;
    try
    {
      if (initializeServer)
@@ -843,7 +844,7 @@
      connection.connectToHost(bindDNValue, bindPasswordValue, nextMessageID);
      LDAPCompare ldapCompare = new LDAPCompare(nextMessageID, out, err);
      ldapCompare = new LDAPCompare(nextMessageID, out, err);
      if(fileNameValue == null && dnStrings.isEmpty())
      {
        // Read from stdin.
@@ -891,7 +892,14 @@
    {
      if(connection != null)
      {
        connection.close();
        if (ldapCompare == null)
        {
          connection.close(null);
        }
        else
        {
          connection.close(ldapCompare.nextMessageID);
        }
      }
    }
    return 0;
opends/src/server/org/opends/server/tools/LDAPConnection.java
@@ -45,6 +45,7 @@
import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.protocols.ldap.UnbindRequestProtocolOp;
import org.opends.server.types.Control;
import org.opends.server.types.DebugLogLevel;
@@ -418,13 +419,28 @@
  }
  /**
   * Close the underlying ASN1 reader and writer.
   * Close the underlying ASN1 reader and writer, optionally sending an unbind
   * request before disconnecting.
   *
   * @param  nextMessageID  The message ID counter that should be used for
   *                        the unbind request, or {@code null} if the
   *                        connection should be closed without an unbind
   *                        request.
   */
  public void close()
  public void close(AtomicInteger nextMessageID)
  {
    if(asn1Writer != null)
    {
      if (nextMessageID != null)
      {
        try
        {
          LDAPMessage message = new LDAPMessage(nextMessageID.getAndIncrement(),
                                                new UnbindRequestProtocolOp());
          asn1Writer.writeElement(message.encode());
        } catch (Exception e) {}
      }
      asn1Writer.close();
    }
    if(asn1Reader != null)
opends/src/server/org/opends/server/tools/LDAPDelete.java
@@ -688,6 +688,7 @@
      }
    }
    LDAPDelete ldapDelete = null;
    try
    {
      if (initializeServer)
@@ -722,7 +723,7 @@
                                      connectionOptions, out, err);
      connection.connectToHost(bindDNValue, bindPasswordValue, nextMessageID);
      LDAPDelete ldapDelete = new LDAPDelete(nextMessageID, out, err);
      ldapDelete = new LDAPDelete(nextMessageID, out, err);
      if(fileNameValue == null && dnStrings.isEmpty())
      {
        // Read from stdin.
@@ -769,7 +770,14 @@
    {
      if(connection != null)
      {
        connection.close();
        if (ldapDelete == null)
        {
          connection.close(null);
        }
        else
        {
          connection.close(ldapDelete.nextMessageID);
        }
      }
    }
    return 0;
opends/src/server/org/opends/server/tools/LDAPModify.java
@@ -1051,6 +1051,7 @@
      }
    }
    LDAPModify ldapModify = null;
    try
    {
      if (initializeServer)
@@ -1085,8 +1086,7 @@
                                      connectionOptions, out, err);
      connection.connectToHost(bindDNValue, bindPasswordValue, nextMessageID);
      LDAPModify ldapModify = new LDAPModify(fileNameValue, nextMessageID,
                                             out, err);
      ldapModify = new LDAPModify(fileNameValue, nextMessageID, out, err);
      InputStream is = System.in;
      if(fileNameValue != null)
      {
@@ -1123,7 +1123,14 @@
    {
      if(connection != null)
      {
        connection.close();
        if (ldapModify == null)
        {
          connection.close(null);
        }
        else
        {
          connection.close(ldapModify.nextMessageID);
        }
      }
    }
    return 0;
opends/src/server/org/opends/server/tools/LDAPSearch.java
@@ -1329,6 +1329,7 @@
      wrapColumn = 0;
    }
    LDAPSearch ldapSearch = null;
    try
    {
      if (initializeServer)
@@ -1386,7 +1387,7 @@
               new PagedResultsControl(true, pageSize, cookieValue)));
          searchOptions.setControls(newControls);
          LDAPSearch ldapSearch = new LDAPSearch(nextMessageID, out, err);
          ldapSearch = new LDAPSearch(nextMessageID, out, err);
          matchingEntries += ldapSearch.executeSearch(connection, baseDNValue,
                                                      filters, attributes,
                                                      searchOptions,
@@ -1432,7 +1433,7 @@
      }
      else
      {
        LDAPSearch ldapSearch = new LDAPSearch(nextMessageID, out, err);
        ldapSearch = new LDAPSearch(nextMessageID, out, err);
        matchingEntries = ldapSearch.executeSearch(connection, baseDNValue,
                                                   filters, attributes,
                                                   searchOptions, wrapColumn);
@@ -1477,7 +1478,14 @@
    {
      if(connection != null)
      {
        connection.close();
        if (ldapSearch == null)
        {
          connection.close(null);
        }
        else
        {
          connection.close(ldapSearch.nextMessageID);
        }
      }
    }
  }