directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Lecharny (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (DIRAPI-178) How to use Apache Directory API to do persistent search
Date Thu, 06 Nov 2014 01:10:34 GMT

    [ https://issues.apache.org/jira/browse/DIRAPI-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13931491#comment-13931491
] 

Emmanuel Lecharny edited comment on DIRAPI-178 at 11/6/14 1:10 AM:
-------------------------------------------------------------------

And none of SunOne and RedHat server works with your implementation ?

Btw here is a code sample, as provided by Kiran :

{code}

    public void testPsearchMove() throws Exception
    {
        LdapNetworkConnection connection = new LdapNetworkConnection( "localhost", ldapServer.getPort()
);
        connection.bind( "uid=admin,ou=system", "secret" );
        
        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( BASE ) );
        sr.setFilter( "(objectClass=*)" );
        sr.setScope( SearchScope.SUBTREE );
        
        PersistentSearch ps = new PersistentSearchImpl();
        ps.setChangesOnly( true );
        ps.setReturnECs( true );
        ps.setCritical( true );
        
        sr.addControl( ps );
        
        final SearchCursor cursor = connection.search( sr );
        
        final List<Entry> entryList = new ArrayList<Entry>();
        
        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();
        
        connection.move( newOu.getDn(), newOu.getDn().getParent().getParent() );
        Thread.sleep( 1000 );
        assertFalse( entryList.isEmpty() );
        assertEquals( 1, entryList.size() );
        assertEquals( "uid=persist,ou=system", entryList.get( 0 ).getDn().getName() );
        
        connection.close();
    }

{code}


was (Author: elecharny):
And none of SunOne and RedHat server works with your implementation ?

Btw here is a code sample, as provided by Kiran :

{code}
    public void testPsearchMove() throws Exception
    {
        LdapNetworkConnection connection = new LdapNetworkConnection( "localhost", ldapServer.getPort()
);
        connection.bind( "uid=admin,ou=system", "secret" );
        
        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( BASE ) );
        sr.setFilter( "(objectClass=*)" );
        sr.setScope( SearchScope.SUBTREE );
        
        PersistentSearch ps = new PersistentSearchImpl();
        ps.setChangesOnly( true );
        ps.setReturnECs( true );
        ps.setCritical( true );
        
        sr.addControl( ps );
        
        final SearchCursor cursor = connection.search( sr );
        
        final List<Entry> entryList = new ArrayList<Entry>();
        
        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();
        
        connection.move( newOu.getDn(), newOu.getDn().getParent().getParent() );
        Thread.sleep( 1000 );
        assertFalse( entryList.isEmpty() );
        assertEquals( 1, entryList.size() );
        assertEquals( "uid=persist,ou=system", entryList.get( 0 ).getDn().getName() );
        
        connection.close();
    }

{ code}

> 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.
> {code}
> @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<Entry> entryList = new ArrayList<Entry>();
> 		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();
> 	}
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message