Return-Path: X-Original-To: apmail-directory-dev-archive@www.apache.org Delivered-To: apmail-directory-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7069DCBC3 for ; Wed, 12 Nov 2014 20:42:35 +0000 (UTC) Received: (qmail 39806 invoked by uid 500); 12 Nov 2014 20:42:35 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 39726 invoked by uid 500); 12 Nov 2014 20:42:35 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 39467 invoked by uid 99); 12 Nov 2014 20:42:35 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Nov 2014 20:42:35 +0000 Date: Wed, 12 Nov 2014 20:42:35 +0000 (UTC) From: "Chris Harris (JIRA)" To: dev@directory.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (DIRAPI-202) Can't get LdapConnectionTemplate working MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/DIRAPI-202?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1420= 8555#comment-14208555 ]=20 Chris Harris edited comment on DIRAPI-202 at 11/12/14 8:42 PM: --------------------------------------------------------------- Hi, [~elecharny]. I'm still having no luck with M-24. I can successfully = query AD by using a simple search operation, however I cannot successfully = query AD when using the LdapConnectionTemplate AND an EntryMapper. I can s= uccessfully query AD by using a simple search operation AND an EntryMapper. I updated my working copy of M-25. I'll try DefaultPoolableLdapConnectionF= actory. was (Author: chris harris): Hi, [~elecharny]. I'm still having no luck with M-24. I can successfully = query AD by using a simple search operation, however I cannot successfully = query AD when using the LdapConnectionTemplate AND an EntryMapper. I can s= uccessfully query AD by using a simple search operation AND an EntryMapper. I tried M-25-SNAPSHOT, but RAD/Eclipse complains about not being able to fi= nd symbol for PoolableConnectionFactory. > Can't get LdapConnectionTemplate working > ---------------------------------------- > > Key: DIRAPI-202 > URL: https://issues.apache.org/jira/browse/DIRAPI-202 > Project: Directory Client API > Issue Type: Bug > Affects Versions: 1.0.0-M24 > Environment: WAS 8.0 JDK, RAD 9.0.1, Windows 7 Enterprise Edition > Reporter: Chris Harris > Priority: Blocker > Labels: EntryMapper, LdapConnectionTemplate, documentation, = newbie > > Hi, > I=E2=80=99ve been following the example code from Section 2.10 using v1.0= .0-M24. My goal is to use an LdapConnectionTemplate to bind to AD, return = a response/cursor, and use an EntryMapper to map each cursor iteration=E2= =80=99s value to a Person object. > I=E2=80=99m getting the following error message: > ERR_02002_FAILURE_ON_UNDERLYING_CURSOR Failure on underlying Cursor > I=E2=80=99m not sure what=E2=80=99s wrong at this point. I have a basic = query example working that doesn=E2=80=99t use a template. > I=E2=80=99m including my code, which contains the method with the basic q= uery that does work and the method with the query using the template that d= oesn=E2=80=99t work. > Can you help me figure out why searchLdapForCeoUsingTemplate() is not wor= king? > Here=E2=80=99s LdapClient.java: > {code} > /** > *=20 > */ > 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 { > =20 > public LdapClient() { > =20 > } > =20 > private static final EntryMapper personEntryMapper =3D=20 > new EntryMapper() { > @Override > public Person map( Entry ent= ry ) throws LdapException { > return new Pe= rson.Builder() > = .setFirstName(entry.get( "givenName" ).getString()) > = .setLastName(entry.get( "sn" ).getString()) > = .build(); > } > }; > =20 > public Person searchLdapForCeoUsingTemplate() { > LdapConnectionConfig config =3D new LdapCon= nectionConfig(); > config.setLdapHost( ); > config.setLdapPort( ); > config.setName( ); > config.setCredentials( ); > DefaultLdapConnectionFactory factory =3D ne= w DefaultLdapConnectionFactory( config ); > factory.setTimeOut( 30000 ); > // optional, values below are defaults > GenericObjectPool.Config poolConfig =3D new= GenericObjectPool.Config(); > poolConfig.lifo =3D true; > poolConfig.maxActive =3D 8; > poolConfig.maxIdle =3D 8; > poolConfig.maxWait =3D -1L; > poolConfig.minEvictableIdleTimeMillis =3D 1= 000L * 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 GenericO= bjectPool.WHEN_EXHAUSTED_BLOCK; > LdapConnectionTemplate ldapConnectionTempla= te =3D=20 > new LdapConnectionTemplate( new LdapCon= nectionPool( > new PoolableLdapConnectionFactory( = factory ), poolConfig ) ); > =20 > List allThePeople =3D ldapConnectio= nTemplate.search(=20 > ,=20 > ,=20 > SearchScope.SUBTREE, > personEntryMapper ); > =20 > for (Person p : allThePeople) { > System.out.println(p.getFirs= tName()); > System.out.println(p.getLast= Name()); > } > =20 > return allThePeople.get(0); > } > =20 > public Entry searchLdapForCeo() { > SearchCursor cursor =3D new SearchCursorImp= l(null, 30000, TimeUnit.SECONDS); > LdapConnection connection =3D new LdapNetworkConnection(= , ); > Entry entry =3D null; > try { > connection.bind(, ); > =20 > 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.SE= VERE, null, ex); > } > } > return entry; > } > } > {code} > Here=E2=80=99s Person.java: > {code} > /** > *=20 > */ > public class Person { > =20 > protected Person() { > =20 > } > public static class Builder { > private Person person; > =20 > public Builder() { > this.person =3D new Person(); > } > =20 > public Builder setFirstName(String firstName) { > this.person.firstName =3D firstName; > return this; > } > =20 > public Builder setLastName(String lastName) { > this.person.lastName =3D lastName; > return this; > } > public Person build() { > return this.person; > } > } > =20 > private String firstName; > private String lastName; > =20 > 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; > } > } > {code} > Here=E2=80=99s my JUnit test: > {code} > /** > *=20 > */ > 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; > =20 > @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()); > } > =20 > @Test > public void testSearchLdapForCeoUsingLdapSearchTemplate() { > assertNotEquals(null, ldapClient.searchLdapForCeoUsingTempla= te()); > } > =20 > @After > public void tearDown() throws Exception { > } > =20 > @AfterClass > public static void tearDownAfterClass() throws Exception { > } > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)