Return-Path: X-Original-To: apmail-directory-api-archive@minotaur.apache.org Delivered-To: apmail-directory-api-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 05B6611737 for ; Thu, 14 Aug 2014 23:42:40 +0000 (UTC) Received: (qmail 94748 invoked by uid 500); 14 Aug 2014 23:42:39 -0000 Delivered-To: apmail-directory-api-archive@directory.apache.org Received: (qmail 94690 invoked by uid 500); 14 Aug 2014 23:42:39 -0000 Mailing-List: contact api-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: api@directory.apache.org Delivered-To: mailing list api@directory.apache.org Received: (qmail 94671 invoked by uid 99); 14 Aug 2014 23:42:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Aug 2014 23:42:39 +0000 X-ASF-Spam-Status: No, hits=-2.8 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_HI,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [198.89.159.242] (HELO Mail3.baxter.com) (198.89.159.242) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Aug 2014 23:42:10 +0000 X-SBRS: None X-Spoof: Baxter Forged Domain X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,866,1400043600"; d="scan'208,217";a="418807616" From: "Harris, Christopher P" To: "api@directory.apache.org" Subject: Trying to get LdapConnectionTemplate working Thread-Topic: Trying to get LdapConnectionTemplate working Thread-Index: Ac+4Fv+PNwH9tnUvTlKqFdfKvMncng== Date: Thu, 14 Aug 2014 23:42:03 +0000 Message-ID: <9BD825F3554FD04AAB3B8BCBA96F192F3E5109F2@BN1PRD9201MB007.026d.mgd.msft.net> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [141.251.40.68] MIME-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on USRLSMTP001/NA/Baxter(Release 6.5.6FP2HF369 | June 5, 2009) at 08/14/2014 18:42:04, Serialize by Router on USRLSMTP001/NA/Baxter(Release 6.5.6FP2HF369 | June 5, 2009) at 08/14/2014 18:42:04 Content-Type: multipart/alternative; boundary="_000_9BD825F3554FD04AAB3B8BCBA96F192F3E5109F2BN1PRD9201MB007_" Content-Language: en-US X-Virus-Checked: Checked by ClamAV on apache.org --_000_9BD825F3554FD04AAB3B8BCBA96F192F3E5109F2BN1PRD9201MB007_ Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Hi, I've been following the example code from Section 2.10 using v1.0.0-M24. M= y goal is to use an LdapConnectionTemplate to bind to AD, return a response= /cursor, and use an EntryMapper to map each cursor iteration's value to a P= erson object. I'm getting the following error message: ERR_02002_FAILURE_ON_UNDERLYING_CURSOR Failure on underlying Cursor I'm not sure what's wrong at this point. I have a basic query example work= ing that doesn't use a template. I'm including my code, which contains the method with the basic query that = does work and the method with the query using the template that doesn't wor= k. Can you help me figure out why searchLdapForCeoUsingTemplate() is not worki= ng? Here's LdapClient.java: /** * */ import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.pool.impl.GenericObjectPool; import org.apache.directory.api.ldap.model.cursor.CursorException; import org.apache.directory.api.ldap.model.cursor.SearchCursor; import org.apache.directory.api.ldap.model.entry.Entry; import org.apache.directory.api.ldap.model.exception.LdapException; import org.apache.directory.api.ldap.model.message.Response; import org.apache.directory.api.ldap.model.message.SearchRequest; import org.apache.directory.api.ldap.model.message.SearchRequestImpl; import org.apache.directory.api.ldap.model.message.SearchResultDone; import org.apache.directory.api.ldap.model.message.SearchResultEntry; import org.apache.directory.api.ldap.model.message.SearchScope; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.ldap.client.api.DefaultLdapConnectionFactory; import org.apache.directory.ldap.client.api.LdapConnection; import org.apache.directory.ldap.client.api.LdapConnectionConfig; import org.apache.directory.ldap.client.api.LdapConnectionPool; import org.apache.directory.ldap.client.api.LdapNetworkConnection; import org.apache.directory.ldap.client.api.PoolableLdapConnectionFactory; import org.apache.directory.ldap.client.api.SearchCursorImpl; import org.apache.directory.ldap.client.template.EntryMapper; import org.apache.directory.ldap.client.template.LdapConnectionTemplate; /** * @author Chris Harris * */ public class LdapClient { public LdapClient() { } private static final EntryMapper personEntryMapper =3D new EntryMapper() { @Override public Person map( Entry entry= ) throws LdapException { return new Pers= on.Builder() = .setFirstName(entry.get( "givenName" ).getString()) = .setLastName(entry.get( "sn" ).getString()) = .build(); } }; public Person searchLdapForCeoUsingTemplate() { LdapConnectionConfig config =3D new LdapConne= ctionConfig(); config.setLdapHost( ); config.setLdapPort( ); config.setName( ); config.setCredentials( ); DefaultLdapConnectionFactory factory =3D new = DefaultLdapConnectionFactory( config ); factory.setTimeOut( 30000 ); // optional, values below are defaults GenericObjectPool.Config poolConfig =3D new G= enericObjectPool.Config(); poolConfig.lifo =3D true; poolConfig.maxActive =3D 8; poolConfig.maxIdle =3D 8; poolConfig.maxWait =3D -1L; poolConfig.minEvictableIdleTimeMillis =3D 100= 0L * 60L * 30L; poolConfig.minIdle =3D 0; poolConfig.numTestsPerEvictionRun =3D 3; poolConfig.softMinEvictableIdleTimeMillis =3D= -1L; poolConfig.testOnBorrow =3D false; poolConfig.testOnReturn =3D false; poolConfig.testWhileIdle =3D false; poolConfig.timeBetweenEvictionRunsMillis =3D = -1L; poolConfig.whenExhaustedAction =3D GenericObj= ectPool.WHEN_EXHAUSTED_BLOCK; LdapConnectionTemplate ldapConnectionTemplate= =3D new LdapConnectionTemplate( new LdapConne= ctionPool( new PoolableLdapConnectionFactory( fa= ctory ), poolConfig ) ); List allThePeople =3D ldapConnectionT= emplate.search( , , SearchScope.SUBTREE, personEntryMapper ); for (Person p : allThePeople) { System.out.println(p.getFirstN= ame()); System.out.println(p.getLastNa= me()); } return allThePeople.get(0); } public Entry searchLdapForCeo() { SearchCursor cursor =3D new SearchCursorImpl(= null, 30000, TimeUnit.SECONDS); LdapConnection connection =3D new LdapNetworkConnection(, = ); Entry entry =3D null; try { connection.bind(, ); SearchRequest sr =3D new SearchRequestImpl(); sr.setBase(new Dn()); StringBuilder sb =3D new StringBuilder(); sr.setFilter(sb.toString()); sr.setScope( SearchScope.SUBTREE ); cursor =3D connection.search(sr); Response response; while (cursor.next() && cursor.isEntry()) { response =3D cursor.get(); System.out.println(((SearchResultEntry)response).getEntry()= ); entry =3D cursor.getEntry(); } SearchResultDone done =3D cursor.getSearchResultDone(); } catch (LdapException ex) { Logger.getLogger(LdapClient.class.getName()).log(Level.SEVERE, = null, ex); } catch (CursorException ex) { Logger.getLogger(LdapClient.class.getName()).log(Level.SEVERE, = null, ex); } finally { cursor.close(); try { connection.close(); } catch (IOException ex) { Logger.getLogger(LdapClient.class.getName()).log(Level.SEVE= RE, null, ex); } } return entry; } } Here's Person.java: /** * */ public class Person { protected Person() { } public static class Builder { private Person person; public Builder() { this.person =3D new Person(); } public Builder setFirstName(String firstName) { this.person.firstName =3D firstName; return this; } public Builder setLastName(String lastName) { this.person.lastName =3D lastName; return this; } public Person build() { return this.person; } } private String firstName; private String lastName; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName =3D firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName =3D lastName; } } Here's my JUnit test: /** * */ import static org.junit.Assert.*; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; public class LdapClientTest { private static LdapClient ldapClient; @BeforeClass public static void setUpBeforeClass() throws Exception { ldapClient =3D new LdapClient(); } @Before public void setUp() throws Exception { } @Test public void testSearchLdapForCeo() { assertNotEquals(null, ldapClient.searchLdapForCeo()); } @Test public void testSearchLdapForCeoUsingLdapSearchTemplate() { assertNotEquals(null, ldapClient.searchLdapForCeoUsingTemplate= ()); } @After public void tearDown() throws Exception { } @AfterClass public static void tearDownAfterClass() throws Exception { } } The information transmitted is intended only for the person(s) or entity to= which it is addressed and may contain confidential and/or legally privileg= ed material. Delivery of this message to any person other than the intended= recipient(s) is not intended in any way to waive privilege or confidential= ity. Any review, retransmission, dissemination or other use of, or taking o= f any action in reliance upon, this information by entities other than the = intended recipient is prohibited. If you receive this in error, please cont= act the sender and delete the material from any computer. For Translation: http://www.baxter.com/email_disclaimer --_000_9BD825F3554FD04AAB3B8BCBA96F192F3E5109F2BN1PRD9201MB007_--