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 1C85C10DE7 for ; Wed, 12 Mar 2014 08:09:52 +0000 (UTC) Received: (qmail 51385 invoked by uid 500); 12 Mar 2014 08:09:51 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 51190 invoked by uid 500); 12 Mar 2014 08:09:46 -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 51139 invoked by uid 99); 12 Mar 2014 08:09:44 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Mar 2014 08:09:44 +0000 Date: Wed, 12 Mar 2014 08:09:43 +0000 (UTC) From: "Robert Hou (JIRA)" To: dev@directory.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (DIRAPI-178) How to use Apache Directory API to do persistent search MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/DIRAPI-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13931507#comment-13931507 ] Robert Hou commented on DIRAPI-178: ----------------------------------- Below are the test cases for four LDAP Servers, I refer to the implementation from Kiran. @Test public void testPsearchNovell() throws Exception { LdapNetworkConnection connection = new LdapNetworkConnection( "192.168.80.31", 389); DefaultConfigurableBinaryAttributeDetector bad = new DefaultConfigurableBinaryAttributeDetector(); bad.addBinaryAttribute("objectSid","objectGUID"); connection.setBinaryAttributeDetector(bad); connection.setTimeOut(0); LdapConnectionConfig config = connection.getConfig(); // config.setKeyManagers(keyManagers); connection.bind("cn=Admin,o=tibco", "admin"); SearchRequest sr = new SearchRequestImpl(); sr.setBase(new Dn("o=tibco")); sr.setFilter("(objectClass=inetorgperson)"); sr.setDerefAliases(AliasDerefMode.DEREF_ALWAYS); sr.setScope(SearchScope.SUBTREE); sr.addControl(new PersistentSearchImpl()); final SearchCursor cursor = connection.search(sr); final List entryList = new ArrayList(); Runnable r = new Runnable() { @Override public void run() { try { while (cursor.next()) { entryList.add(cursor.getEntry()); } } catch (Exception e) { throw new RuntimeException(e); } } }; new Thread(r).start(); while(true){ Thread.sleep(1000); if(!entryList.isEmpty()){ System.out.println(entryList); entryList.clear(); } } } @Test public void testPsearchSunONE() throws Exception { LdapNetworkConnection connection = new LdapNetworkConnection( "192.168.80.166", 1389); DefaultConfigurableBinaryAttributeDetector bad = new DefaultConfigurableBinaryAttributeDetector(); bad.addBinaryAttribute("objectSid","objectGUID"); connection.setBinaryAttributeDetector(bad); connection.bind("CN=Directory Manager", "tibco123"); connection.setTimeOut(0); SearchRequest sr = new SearchRequestImpl(); sr.setBase(new Dn("dc=tibco,dc=com")); sr.setFilter("(objectClass=inetorgperson)"); sr.setScope(SearchScope.SUBTREE); sr.addControl(new PersistentSearchImpl()); final SearchCursor cursor = connection.search(sr); final List entryList = new ArrayList(); Runnable r = new Runnable() { @Override public void run() { try { while (cursor.next()) { entryList.add(cursor.getEntry()); // System.out.println(cursor.getEntry()); } } catch (Exception e) { throw new RuntimeException(e); } } }; new Thread(r).start(); while(true){ Thread.sleep(1000); if(!entryList.isEmpty()){ System.out.println(entryList); entryList.clear(); } } } @Test public void testPsearchIBM() throws Exception { LdapNetworkConnection connection = new LdapNetworkConnection( "192.168.80.56", 389); DefaultConfigurableBinaryAttributeDetector bad = new DefaultConfigurableBinaryAttributeDetector(); bad.addBinaryAttribute("objectSid","objectGUID"); connection.setBinaryAttributeDetector(bad); connection.bind("cn=root", "Tibco1234"); SearchRequest sr = new SearchRequestImpl(); sr.setBase(new Dn("cn=configuration")); sr.setFilter("(objectClass=inetorgperson)"); sr.setScope(SearchScope.SUBTREE); sr.addControl(new PersistentSearchImpl()); final SearchCursor cursor = connection.search(sr); final List entryList = new ArrayList(); Runnable r = new Runnable() { @Override public void run() { try { while (cursor.next()) { entryList.add(cursor.getEntry()); // System.out.println(cursor.getEntry()); } } catch (Exception e) { throw new RuntimeException(e); } } }; new Thread(r).start(); while(true){ Thread.sleep(1000); if(!entryList.isEmpty()){ System.out.println(entryList); entryList.clear(); } } } @Test public void testPsearchRedHat() throws Exception { LdapNetworkConnection connection = new LdapNetworkConnection( "192.168.80.50", 389); DefaultConfigurableBinaryAttributeDetector bad = new DefaultConfigurableBinaryAttributeDetector(); bad.addBinaryAttribute("objectSid","objectGUID"); connection.setBinaryAttributeDetector(bad); connection.bind("cn=directory manager", "12345678"); connection.setTimeOut(0); SearchRequest sr = new SearchRequestImpl(); sr.setBase(new Dn("dc=qa,dc=com")); sr.setFilter("(objectClass=inetorgperson)"); sr.setScope(SearchScope.SUBTREE); sr.addControl(new PersistentSearchImpl()); // sr.setTimeLimit(0); final SearchCursor cursor = connection.search(sr); final List entryList = new ArrayList(); Runnable r = new Runnable() { @Override public void run() { try { while (cursor.next()) { entryList.add(cursor.getEntry()); // System.out.println(cursor.getEntry()); } } catch (Exception e) { throw new RuntimeException(e); } } }; new Thread(r).start(); while(true){ Thread.sleep(1000); if(!entryList.isEmpty()){ System.out.println(entryList); entryList.clear(); } } } > How to use Apache Directory API to do persistent search > ------------------------------------------------------- > > Key: DIRAPI-178 > URL: https://issues.apache.org/jira/browse/DIRAPI-178 > Project: Directory Client API > Issue Type: Question > Affects Versions: 1.0.0-M20 > Reporter: Robert Hou > > Persistent search in Directory Client API seems not work, the code I write as below: I refer to the code under DIRSERVER-1908 to complete following code. After the code run, it will print all the entries it searched, but the printed entries are not changed entries. In the while block, I clear the list of entries after first print, then I want to it print the entires I modified later, but it doesn't print. > @Test > public void testPsearchMove() throws Exception > { > LdapNetworkConnection connection = new LdapNetworkConnection( > "192.168.80.223", 50001); > connection.bind("cn=robert,cn=roles,dc=tibco,dc=com", "robert"); > // Entry newOu = new DefaultEntry("uid=persist, ou=users,ou=system"); > // newOu.add("objectClass", "inetOrgPerson"); > // newOu.add("cn", "persist_cn"); > // newOu.add("sn", "persist_sn"); > // connection.add(newOu); > SearchRequest sr = new SearchRequestImpl(); > sr.setBase(new Dn("dc=tibco,dc=com")); > sr.setFilter("(objectClass=inetorgperson)"); > sr.setScope(SearchScope.SUBTREE); > sr.addControl(new PersistentSearchImpl()); > final SearchCursor cursor = connection.search(sr); > final List entryList = new ArrayList(); > Runnable r = new Runnable() { > @Override > public void run() { > try { > while (cursor.next()) { > entryList.add(cursor.getEntry()); > // System.out.println(cursor.getEntry()); > } > } catch (Exception e) { > throw new RuntimeException(e); > } > } > }; > new Thread(r).start(); > // connection.move(newOu.getDn(), newOu.getDn().getParent().getParent()); > while(true){ > Thread.sleep(1000); > if(!entryList.isEmpty()){ > System.out.println(entryList); > entryList.clear(); > } > } > > // assertFalse(entryList.isEmpty()); > // assertEquals(1, entryList.size()); > // assertEquals("uid=persist,ou=system", entryList.get(0).getDn() > // .getName()); > // connection.close(); > } -- This message was sent by Atlassian JIRA (v6.2#6252)