You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/05/05 23:56:09 UTC
svn commit: r771985 -
/directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
Author: elecharny
Date: Tue May 5 21:56:09 2009
New Revision: 771985
URL: http://svn.apache.org/viewvc?rev=771985&view=rev
Log:
Added methods for getRootDSE() and getRootDSE( attrs )
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=771985&r1=771984&r2=771985&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 May 5 21:56:09 2009
@@ -1084,6 +1084,120 @@
// Search operations //
//---------------------------------------------------------------------//
/**
+ * Do a search with no argument. This is semantically a search for the
+ * rootDSE.
+ * SearchRequest parameters default to :
+ * BaseDN : empty
+ * Filter : (ObjectClass=*)
+ * Scope : OBJECT
+ * DerefAlias : N/A
+ * SizeLimit : N/A
+ * TimeLimit : N/A
+ * TypesOnly : N/A
+ * Attributes : all the user's attributes.
+ * This method is blocking.
+ *
+ * @return The rootDSE SearchResultEntry.
+ * @throws LdapException if we weren't able to get the rootDSE
+ */
+ public SearchResultEntry search() throws LdapException
+ {
+ return getRootDSE();
+ }
+
+
+ /**
+ * Do a search for the rootDSE.
+ * This method is blocking.
+ *
+ * @return The rootDSE SearchResultEntry.
+ * @throws LdapException if we weren't able to get the rootDSE
+ */
+ public SearchResultEntry getRootDSE() throws LdapException
+ {
+ // Create a new SearchRequest object
+ SearchRequest searchRequest = new SearchRequestImpl();
+
+ searchRequest.setBaseDn( LdapDN.EMPTY_LDAPDN.toString() );
+ searchRequest.setFilter( "(ObjectClass=*)" );
+ searchRequest.setScope( SearchScope.OBJECT );
+ searchRequest.addAttributes( "*" );
+
+ // Process the request in blocking mode
+ Cursor<SearchResponse> cursor = searchInternal( searchRequest );
+
+ try
+ {
+ cursor.first();
+
+ if ( cursor.available() == false )
+ {
+ // No entry in the cursor ? This is an error.
+ // We didn't received anything : this is an error
+ LOG.error( "getRootDSE() failed" );
+ throw new LdapException( "getRootDSE() failed" );
+ }
+
+ SearchResponse rootDSE = cursor.get();
+
+ return (SearchResultEntry)rootDSE;
+ }
+ catch ( Exception e )
+ {
+ LOG.error( "getRootDSE() failed : " + e.getMessage() );
+ throw new LdapException( "getRootDSE() failed" + e.getMessage() );
+ }
+ }
+
+
+
+
+ /**
+ * Do a search for some attributes of the rootDSE .
+ * This method is blocking.
+ *
+ * @param attributes The attributes to be returned
+ * @return The rootDSE SearchResultEntry.
+ * @throws LdapException if we weren't able to get the rootDSE
+ */
+ public SearchResultEntry getRootDSE( String... attributes ) throws LdapException
+ {
+ // Create a new SearchRequest object
+ SearchRequest searchRequest = new SearchRequestImpl();
+
+ searchRequest.setBaseDn( LdapDN.EMPTY_LDAPDN.toString() );
+ searchRequest.setFilter( "(ObjectClass=*)" );
+ searchRequest.setScope( SearchScope.OBJECT );
+ searchRequest.addAttributes( attributes );
+
+ // Process the request in blocking mode
+ Cursor<SearchResponse> cursor = searchInternal( searchRequest );
+
+ try
+ {
+ cursor.first();
+
+ if ( cursor.available() == false )
+ {
+ // No entry in the cursor ? This is an error.
+ // We didn't received anything : this is an error
+ LOG.error( "getRootDSE() failed" );
+ throw new LdapException( "getRootDSE() failed" );
+ }
+
+ SearchResponse rootDSE = cursor.get();
+
+ return (SearchResultEntry)rootDSE;
+ }
+ catch ( Exception e )
+ {
+ LOG.error( "getRootDSE() failed : " + e.getMessage() );
+ throw new LdapException( "getRootDSE() failed" + e.getMessage() );
+ }
+ }
+
+
+ /**
* Do a search, on the base object, using the given filter. The
* SearchRequest parameters default to :
* Scope : ONE
@@ -1226,11 +1340,18 @@
try
{
- cursor.first();
+ cursor.beforeFirst();
}
catch ( Exception e )
{
- // TODO: handle exception
+ // Catch all other exceptions
+ LOG.error( "The cursor has been closed." );
+ LdapException ldapException = new LdapException();
+ ldapException.initCause( e );
+
+ // Send an abandon request
+ abandon( searchRequest.getMessageId() );
+ throw ldapException;
}
return cursor;
@@ -1433,17 +1554,16 @@
case LdapConstants.BIND_RESPONSE:
// Store the response into the responseQueue
BindResponseCodec bindResponseCodec = response.getBindResponse();
+ bindResponseCodec.setMessageId( response.getMessageId() );
BindResponse bindResponse = convert( bindResponseCodec );
if ( bindListener != null )
{
bindListener.bindCompleted( this, bindResponse );
}
- else
- {
- // Store the response into the responseQueue
- bindResponseQueue.add( bindResponse );
- }
+
+ // Store the response into the responseQueue
+ bindResponseQueue.add( bindResponse );
break;
@@ -1467,6 +1587,9 @@
IntermediateResponseCodec intermediateResponseCodec =
response.getIntermediateResponse();
+ // Store the messageId
+ intermediateResponseCodec.setMessageId( response.getMessageId() );
+
if ( intermediateResponseListener != null )
{
intermediateResponseListener.responseReceived( this,
@@ -1495,6 +1618,9 @@
SearchResultDoneCodec searchResultDoneCodec =
response.getSearchResultDone();
+ // Store the messageId
+ searchResultDoneCodec.setMessageId( response.getMessageId() );
+
if ( searchListener != null )
{
searchListener.searchDone( this, convert( searchResultDoneCodec ) );
@@ -1511,6 +1637,9 @@
SearchResultEntryCodec searchResultEntryCodec =
response.getSearchResultEntry();
+ // Store the messageId
+ searchResultEntryCodec.setMessageId( response.getMessageId() );
+
if ( searchListener != null )
{
searchListener.entryFound( this, convert( searchResultEntryCodec ) );
@@ -1528,6 +1657,9 @@
SearchResultReferenceCodec searchResultReferenceCodec =
response.getSearchResultReference();
+ // Store the messageId
+ searchResultReferenceCodec.setMessageId( response.getMessageId() );
+
if ( searchListener != null )
{
searchListener.referralFound( this, convert( searchResultReferenceCodec ) );