Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 2679 invoked from network); 31 Mar 2009 22:55:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 31 Mar 2009 22:55:35 -0000 Received: (qmail 87812 invoked by uid 500); 31 Mar 2009 22:55:35 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 87754 invoked by uid 500); 31 Mar 2009 22:55:35 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 87745 invoked by uid 99); 31 Mar 2009 22:55:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Mar 2009 22:55:35 +0000 X-ASF-Spam-Status: No, hits=-1998.8 required=10.0 tests=ALL_TRUSTED,FS_REPLICA X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Mar 2009 22:55:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 212F92388A04; Tue, 31 Mar 2009 22:55:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r760710 - /directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java Date: Tue, 31 Mar 2009 22:55:11 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090331225512.212F92388A04@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Tue Mar 31 22:55:11 2009 New Revision: 760710 URL: http://svn.apache.org/viewvc?rev=760710&view=rev Log: o Added the AbandonRequest support o Fixed a bung in the messageId generation for BindRequest Modified: directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java Modified: directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java?rev=760710&r1=760709&r2=760710&view=diff ============================================================================== --- directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java (original) +++ directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java Tue Mar 31 22:55:11 2009 @@ -37,6 +37,8 @@ import org.apache.directory.shared.ldap.client.api.exception.LdapException; import org.apache.directory.shared.ldap.client.api.listeners.BindListener; import org.apache.directory.shared.ldap.client.api.listeners.SearchListener; +import org.apache.directory.shared.ldap.client.api.messages.AbandonRequest; +import org.apache.directory.shared.ldap.client.api.messages.AbandonRequestImpl; import org.apache.directory.shared.ldap.client.api.messages.BindRequest; import org.apache.directory.shared.ldap.client.api.messages.BindRequestImpl; import org.apache.directory.shared.ldap.client.api.protocol.LdapProtocolCodecFactory; @@ -44,6 +46,7 @@ import org.apache.directory.shared.ldap.codec.LdapMessage; import org.apache.directory.shared.ldap.codec.LdapMessageContainer; import org.apache.directory.shared.ldap.codec.LdapResponse; +import org.apache.directory.shared.ldap.codec.abandon.AbandonRequestCodec; import org.apache.directory.shared.ldap.codec.bind.LdapAuthentication; import org.apache.directory.shared.ldap.codec.bind.SaslCredentials; import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication; @@ -228,6 +231,27 @@ } } + + /** + * Inject the client Controls into the message + */ + private void setControls( Map controls, LdapMessage message ) + { + // Add the controls + if ( controls != null ) + { + for ( Control control:controls.values() ) + { + org.apache.directory.shared.ldap.codec.Control ctrl = + new org.apache.directory.shared.ldap.codec.Control(); + + ctrl.setControlType( control.getID() ); + ctrl.setControlValue( control.getEncodedValue() ); + + message.addControl( ctrl ); + } + } + } //------------------------- The constructors --------------------------// /** @@ -519,6 +543,63 @@ */ //------------------------ The LDAP operations ------------------------// + // Abandon operations // + // The Abandon request just have one parameter : the MessageId to // + // abandon. We also have to allow controls and a client timeout. // + // The abandonRequest is always non-blocking, because no response is // + // expected // + //---------------------------------------------------------------------// + /** + * A simple abandon request. + */ + public void abandon( int messageId ) throws LdapException + { + AbandonRequest abandonRequest = new AbandonRequestImpl(); + abandonRequest.setAbandonedMessageId( messageId ); + + abandonInternal( abandonRequest ); + } + + + /** + * An abandon request with potentially some controls and timeout. + */ + public void abandon( AbandonRequest abandonRequest ) throws LdapException + { + abandonInternal( abandonRequest ); + } + + + /** + * Internal AbandonRequest handling + */ + private void abandonInternal( AbandonRequest abandonRequest ) + { + // Create the new message and update the messageId + LdapMessage message = new LdapMessage(); + message.setMessageId( messageId++ ); + + // Create the inner abandonRequest + AbandonRequestCodec request = new AbandonRequestCodec(); + + // Inject the data into the request + request.setAbandonedMessageId( abandonRequest.getAbandonedMessageId() ); + + // Inject the request into the message + message.setProtocolOP( request ); + + // Inject the controls + setControls( abandonRequest.getControls(), message ); + + LOG.debug( "-----------------------------------------------------------------" ); + LOG.debug( "Sending request \n{}", message ); + + // Send the request to the server + ldapSession.write( message ); + } + + + //------------------------ The LDAP operations ------------------------// // Bind operations // //---------------------------------------------------------------------// /** @@ -526,7 +607,7 @@ * * @return The BindResponse LdapResponse */ - public LdapResponse bind() throws LdapException + public LdapResponse bind() throws LdapException { return bind( (String)null, (byte[])null ); } @@ -539,23 +620,10 @@ * @param name The name we use to authenticate the user. It must be a * valid DN * @return The BindResponse LdapResponse - * + */ public LdapResponse bind( String name ) throws Exception { - LOG.debug( "Anonymous bind" ); - - LdapResponse response = bind( name, (byte[])null ); - - if (response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS ) - { - LOG.debug( "Anonymous bind successfull" ); - } - else - { - LOG.debug( "Anonymous bind failure {}", response ); - } - - return response; + return bind( name, (byte[])null ); } @@ -614,17 +682,29 @@ */ public LdapResponse bind( BindRequest bindRequest ) throws LdapException { - return bind( bindRequest, null ); + return bindInternal( bindRequest, null ); } /** + * Do a non-blocking bind non-blocking + * + * @param bindRequest The BindRequest to send + * @param listener The listener + */ + public void bind( BindRequest bindRequest, BindListener bindListener ) throws LdapException + { + bindInternal( bindRequest, bindListener ); + } + + + /** * Do the bind blocking or non-blocking, depending on the listener value. * * @param bindRequest The BindRequest to send * @param listener The listener (Can be null) */ - public LdapResponse bind( BindRequest bindRequest, BindListener bindListener ) throws LdapException + private LdapResponse bindInternal( BindRequest bindRequest, BindListener bindListener ) throws LdapException { // If the session has not been establish, or is closed, we get out immediately checkSession(); @@ -633,7 +713,7 @@ // running at the same time lock(); - // Encode the request + // Create the new message and update the messageId LdapMessage message = new LdapMessage(); message.setMessageId( messageId++ ); @@ -679,25 +759,8 @@ message.setProtocolOP( request ); // Add the controls - Map controls = bindRequest.getControls(); - - if ( controls != null ) - { - for ( Control control:controls.values() ) - { - org.apache.directory.shared.ldap.codec.Control ctrl = - new org.apache.directory.shared.ldap.codec.Control(); - - ctrl.setControlType( control.getID() ); - ctrl.setControlValue( control.getEncodedValue() ); - - message.addControl( ctrl ); - } - } + setControls( bindRequest.getControls(), message ); - // Set the message ID now - message.setMessageId( messageId++ ); - LOG.debug( "-----------------------------------------------------------------" ); LOG.debug( "Sending request \n{}", message );