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 4335FCDD8 for ; Wed, 12 Nov 2014 21:24:35 +0000 (UTC) Received: (qmail 37938 invoked by uid 500); 12 Nov 2014 21:24:35 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 37885 invoked by uid 500); 12 Nov 2014 21:24: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 37874 invoked by uid 99); 12 Nov 2014 21:24: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 21:24:35 +0000 Date: Wed, 12 Nov 2014 21:24:35 +0000 (UTC) From: "Chris Harris (JIRA)" To: dev@directory.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (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= 8722#comment-14208722 ]=20 Chris Harris commented on DIRAPI-202: ------------------------------------- [~ltheisen@mitre.org], I tried ValidatingPoolableLdapConnectionFactory, but I received the same er= ror: java.lang.RuntimeException: ERR_02002_FAILURE_ON_UNDERLYING_CURSOR Failure = on underlying Cursor. =09at org.apache.directory.ldap.client.api.EntryCursorImpl.get(EntryCursorI= mpl.java:164) =09at org.apache.directory.ldap.client.api.EntryCursorImpl.get(EntryCursorI= mpl.java:50) =09at org.apache.directory.api.ldap.model.cursor.CursorIterator.next(Cursor= Iterator.java:80) =09at org.apache.directory.ldap.client.template.LdapConnectionTemplate.sear= ch(LdapConnectionTemplate.java:668) =09at org.apache.directory.ldap.client.template.LdapConnectionTemplate.sear= ch(LdapConnectionTemplate.java:621) =09at com.name.group.project.ldap.LdapClient.searchLdapForCeoUsingTemplate(= LdapClient.java:83) =09at com.name.group.project.ldap.LdapClientTest.testSearch(LdapClientTest.= java:40) Results : Tests in error:=20 LdapClientTest.testSearch:40 =C2=BB Runtime ERR_02002_FAILURE_ON_UNDERLYI= NG_CURSOR ... I'm using a service account, not an admin account. Is there anything wrong with the following updated code? public Muppet searchLdapForCeoUsingTemplate() { =09=09LdapConnectionConfig config =3D new LdapConnectionConfig(); =09=09config.setLdapHost( myHost ); =09=09config.setLdapPort( portNum ); =09=09config.setName( myDN ); =09=09config.setCredentials( myPassword ); =09=09DefaultLdapConnectionFactory factory =3D new DefaultLdapConnectionFac= tory( config ); =09=09factory.setTimeOut( 30000 ); =09=09// optional, values below are defaults =09=09GenericObjectPool.Config poolConfig =3D new GenericObjectPool.Config(= ); =09=09poolConfig.lifo =3D true; =09=09poolConfig.maxActive =3D 8; =09=09poolConfig.maxIdle =3D 8; =09=09poolConfig.maxWait =3D -1L; =09=09poolConfig.minEvictableIdleTimeMillis =3D 1000L * 60L * 30L; =09=09poolConfig.minIdle =3D 0; =09=09poolConfig.numTestsPerEvictionRun =3D 3; =09=09poolConfig.softMinEvictableIdleTimeMillis =3D -1L; =09=09poolConfig.testOnBorrow =3D false; =09=09poolConfig.testOnReturn =3D false; =09=09poolConfig.testWhileIdle =3D false; =09=09poolConfig.timeBetweenEvictionRunsMillis =3D -1L; =09=09poolConfig.whenExhaustedAction =3D GenericObjectPool.WHEN_EXHAUSTED_B= LOCK; =09=09LdapConnectionTemplate ldapConnectionTemplate =3D=20 =09=09 new LdapConnectionTemplate( new LdapConnectionPool( =09=09 new ValidatingPoolableLdapConnectionFactory( factory ), poolC= onfig ) ); =09=09 =09=09List allThePeople =3D ldapConnectionTemplate.search(=20 =09=09=09 myADSearchBase,=20 =09=09=09 myADQuery,=20 =09=09=09 SearchScope.SUBTREE, =09=09=09 Muppet.getEntryMapper() ); =09=09 =09=09for (Muppet m : allThePeople) { =09=09=09System.out.println(m.getSn()); =09=09=09System.out.println(m.getGivenName()); =09=09} =09=09 =09=09return allThePeople.get(0); =09} public static class Muppet { private static final EntryMapper entryMapper =3D=20 new EntryMapper() { @Override public Muppet map( Entry entry ) throws LdapException { return new Muppet() .setCn( entry.get( "cn" ).getString() ) .setGivenName( entry.get( "givenName" ).getString()= ) .setMail( entry.get( "mail" ).getString() ) .setSn( entry.get( "sn" ).getString() ); } }; private String cn; private String givenName; private String mail; private String sn; public String getCn() { return cn; } =20 =20 public static EntryMapper getEntryMapper() { return entryMapper; } =20 public String getGivenName() { return givenName; } =20 =20 public String getMail() { return mail; } =20 =20 public String getSn() { return sn; } =20 =20 public Muppet setCn( String cn ) { this.cn =3D cn; return this; } =20 =20 public Muppet setGivenName( String givenName ) { this.givenName =3D givenName; return this; } =20 =20 public Muppet setMail( String mail ) { this.mail =3D mail; return this; } =20 =20 public Muppet setSn( String sn ) { this.sn =3D sn; return this; } } > 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)