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
| | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.StringTokenizer; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | } finally { |
| | | if (connection != null) { |
| | | connection.close(); |
| | | connection.close(new AtomicInteger(1)); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | LDAPCompare ldapCompare = null; |
| | | try |
| | | { |
| | | if (initializeServer) |
| | |
| | | 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. |
| | |
| | | { |
| | | if(connection != null) |
| | | { |
| | | connection.close(); |
| | | if (ldapCompare == null) |
| | | { |
| | | connection.close(null); |
| | | } |
| | | else |
| | | { |
| | | connection.close(ldapCompare.nextMessageID); |
| | | } |
| | | } |
| | | } |
| | | return 0; |
| | |
| | | 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; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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) |
| | |
| | | } |
| | | } |
| | | |
| | | LDAPDelete ldapDelete = null; |
| | | try |
| | | { |
| | | if (initializeServer) |
| | |
| | | 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. |
| | |
| | | { |
| | | if(connection != null) |
| | | { |
| | | connection.close(); |
| | | if (ldapDelete == null) |
| | | { |
| | | connection.close(null); |
| | | } |
| | | else |
| | | { |
| | | connection.close(ldapDelete.nextMessageID); |
| | | } |
| | | } |
| | | } |
| | | return 0; |
| | |
| | | } |
| | | } |
| | | |
| | | LDAPModify ldapModify = null; |
| | | try |
| | | { |
| | | if (initializeServer) |
| | |
| | | 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) |
| | | { |
| | |
| | | { |
| | | if(connection != null) |
| | | { |
| | | connection.close(); |
| | | if (ldapModify == null) |
| | | { |
| | | connection.close(null); |
| | | } |
| | | else |
| | | { |
| | | connection.close(ldapModify.nextMessageID); |
| | | } |
| | | } |
| | | } |
| | | return 0; |
| | |
| | | wrapColumn = 0; |
| | | } |
| | | |
| | | LDAPSearch ldapSearch = null; |
| | | try |
| | | { |
| | | if (initializeServer) |
| | |
| | | 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, |
| | |
| | | } |
| | | else |
| | | { |
| | | LDAPSearch ldapSearch = new LDAPSearch(nextMessageID, out, err); |
| | | ldapSearch = new LDAPSearch(nextMessageID, out, err); |
| | | matchingEntries = ldapSearch.executeSearch(connection, baseDNValue, |
| | | filters, attributes, |
| | | searchOptions, wrapColumn); |
| | |
| | | { |
| | | if(connection != null) |
| | | { |
| | | connection.close(); |
| | | if (ldapSearch == null) |
| | | { |
| | | connection.close(null); |
| | | } |
| | | else |
| | | { |
| | | connection.close(ldapSearch.nextMessageID); |
| | | } |
| | | } |
| | | } |
| | | } |