Package org.apache.directory.api.ldap.model.message.controls

Examples of org.apache.directory.api.ldap.model.message.controls.PagedResults


        connection.bind( "uid=admin,ou=system", "secret" );

        SearchControls controls = new SearchControls();
        controls.setCountLimit( ( int ) LdapServer.NO_SIZE_LIMIT );
        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
        PagedResults pagedSearchControl = new PagedResultsDecorator( codec );
        pagedSearchControl.setSize( 3 );

        // Loop over all the elements
        int loop = 0;
        List<Entry> results = new ArrayList<Entry>();
        boolean hasUnwillingToPerform = false;

        while ( true )
        {
            loop++;

            EntryCursor cursor = null;

            try
            {
                SearchRequest searchRequest = new SearchRequestImpl();
                searchRequest.setBase( new Dn( "ou=system" ) );
                searchRequest.setFilter( "(ObjectClass=*)" );
                searchRequest.setScope( SearchScope.SUBTREE );
                searchRequest.addAttributes( "*" );
                searchRequest.addControl( pagedSearchControl );

                cursor = new EntryCursorImpl( connection.search( searchRequest ) );

                int i = 0;

                while ( cursor.next() )
                {
                    Entry result = cursor.get();
                    results.add( result );
                    ++i;
                }

                SearchResultDone result = cursor.getSearchResultDone();
                pagedSearchControl = ( PagedResults ) result.getControl( PagedResults.OID );

                if ( result.getLdapResult().getResultCode() == ResultCodeEnum.UNWILLING_TO_PERFORM )
                {
                    hasUnwillingToPerform = true;
                    break;
                }
            }
            finally
            {
                if ( cursor != null )
                {
                    cursor.close();
                }
            }

            // Now read the next ones
            assertEquals( 0, pagedSearchControl.getSize() );

            // check if this is over
            byte[] cookie = pagedSearchControl.getCookie();

            if ( Strings.isEmpty( cookie ) )
            {
                // If so, exit the loop
                break;
            }

            // Prepare the next iteration, sending a bad cookie
            pagedSearchControl.setCookie( "test".getBytes( "UTF-8" ) );
            pagedSearchControl.setSize( 3 );
        }

        assertTrue( hasUnwillingToPerform );

        // Cleanup the session
View Full Code Here


     * Manage the abandoned Paged Search (when paged size = 0). We have to
     * remove the cookie and its associated cursor from the session.
     */
    private SearchResultDone abandonPagedSearch( LdapSession session, SearchRequest req ) throws Exception
    {
        PagedResults pagedSearchControl = ( PagedResults ) req.getControls().get( PagedResults.OID );
        byte[] cookie = pagedSearchControl.getCookie();

        if ( !Strings.isEmpty( cookie ) )
        {
            // If the cookie is not null, we have to destroy the associated
            // cursor stored into the session (if any)
            int cookieValue = pagedSearchControl.getCookieValue();
            PagedSearchContext psCookie = session.removePagedSearchContext( cookieValue );
            pagedSearchControl.setCookie( psCookie.getCookie() );
            pagedSearchControl.setSize( 0 );
            pagedSearchControl.setCritical( true );

            // Close the cursor
            Cursor<Entry> cursor = psCookie.getCursor();

            if ( cursor != null )
            {
                cursor.close();
            }
        }
        else
        {
            pagedSearchControl.setSize( 0 );
            pagedSearchControl.setCritical( true );
        }

        // and return
        // DO NOT WRITE THE RESPONSE - JUST RETURN IT
        LdapResult ldapResult = req.getResultResponse().getLdapResult();
View Full Code Here

     * Manage the abandoned Paged Search (when paged size = 0). We have to
     * remove the cookie and its associated cursor from the session.
     */
    private SearchResultDone abandonPagedSearch( LdapSession session, SearchRequest req ) throws Exception
    {
        PagedResults pagedSearchControl = ( PagedResults ) req.getControls().get( PagedResults.OID );
        byte[] cookie = pagedSearchControl.getCookie();

        if ( !Strings.isEmpty( cookie ) )
        {
            // If the cookie is not null, we have to destroy the associated
            // cursor stored into the session (if any)
            int cookieValue = pagedSearchControl.getCookieValue();
            PagedSearchContext psCookie = session.removePagedSearchContext( cookieValue );
            pagedSearchControl.setCookie( psCookie.getCookie() );
            pagedSearchControl.setSize( 0 );
            pagedSearchControl.setCritical( true );

            // Close the cursor
            EntryFilteringCursor cursor = psCookie.getCursor();

            if ( cursor != null )
            {
                cursor.close();
            }
        }
        else
        {
            pagedSearchControl.setSize( 0 );
            pagedSearchControl.setCritical( true );
        }

        // and return
        // DO NOT WRITE THE RESPONSE - JUST RETURN IT
        LdapResult ldapResult = req.getResultResponse().getLdapResult();
View Full Code Here

     * Manage the abandoned Paged Search (when paged size = 0). We have to
     * remove the cookie and its associated cursor from the session.
     */
    private SearchResultDone abandonPagedSearch( LdapSession session, SearchRequest req ) throws Exception
    {
        PagedResults pagedSearchControl = ( PagedResults ) req.getControls().get( PagedResults.OID );
        byte[] cookie = pagedSearchControl.getCookie();

        if ( !Strings.isEmpty( cookie ) )
        {
            // If the cookie is not null, we have to destroy the associated
            // cursor stored into the session (if any)
            int cookieValue = pagedSearchControl.getCookieValue();
            PagedSearchContext psCookie = session.removePagedSearchContext( cookieValue );
            pagedSearchControl.setCookie( psCookie.getCookie() );
            pagedSearchControl.setSize( 0 );
            pagedSearchControl.setCritical( true );

            // Close the cursor
            EntryFilteringCursor cursor = psCookie.getCursor();

            if ( cursor != null )
            {
                cursor.close();
            }
        }
        else
        {
            pagedSearchControl.setSize( 0 );
            pagedSearchControl.setCritical( true );
        }

        // and return
        // DO NOT WRITE THE RESPONSE - JUST RETURN IT
        LdapResult ldapResult = req.getResultResponse().getLdapResult();
View Full Code Here

        } );
        bb.flip();

        PagedResultsDecorator decorator = new PagedResultsDecorator( codec );

        PagedResults pagedSearch = ( PagedResults ) decorator.decode( bb.array() );

        assertEquals( 32, pagedSearch.getSize() );
        assertTrue( Arrays.equals( Strings.getBytesUtf8( "test" ),
            pagedSearch.getCookie() ) );

        bb.flip();

        PagedResultsDecorator ctrl = new PagedResultsDecorator( codec );
        ctrl.setSize( 32 );
View Full Code Here

        } );
        bb.flip();

        PagedResultsDecorator decorator = new PagedResultsDecorator( codec );

        PagedResults pagedSearch = ( PagedResults ) decorator.decode( bb.array() );

        assertEquals( Integer.MAX_VALUE, pagedSearch.getSize() );
        assertTrue( Arrays.equals( Strings.getBytesUtf8( "test" ),
            pagedSearch.getCookie() ) );

        bb.flip();

        PagedResultsDecorator ctrl = new PagedResultsDecorator( codec );
        ctrl.setSize( -1 );
View Full Code Here

        } );
        bb.flip();

        PagedResultsDecorator decorator = new PagedResultsDecorator( codec );

        PagedResults pagedSearch = ( PagedResults ) decorator.decode( bb.array() );

        assertEquals( 32, pagedSearch.getSize() );
        assertNull( pagedSearch.getCookie() );

        PagedResultsDecorator ctrl = new PagedResultsDecorator( codec );
        ctrl.setSize( 32 );
        ctrl.setCookie( null );
View Full Code Here

        if ( !super.equals( o ) )
        {
            return false;
        }

        PagedResults otherControl = ( PagedResults ) o;

        return ( getSize() == otherControl.getSize() ) && Arrays.equals( getCookie(), otherControl.getCookie() );
    }
View Full Code Here

     * Manage the abandoned Paged Search (when paged size = 0). We have to
     * remove the cookie and its associated cursor from the session.
     */
    private SearchResultDone abandonPagedSearch( LdapSession session, SearchRequest req ) throws Exception
    {
        PagedResults pagedSearchControl = ( PagedResults ) req.getControls().get( PagedResults.OID );
        byte[] cookie = pagedSearchControl.getCookie();

        if ( !Strings.isEmpty( cookie ) )
        {
            // If the cookie is not null, we have to destroy the associated
            // cursor stored into the session (if any)
            int cookieValue = pagedSearchControl.getCookieValue();
            PagedSearchContext psCookie = session.removePagedSearchContext( cookieValue );
            pagedSearchControl.setCookie( psCookie.getCookie() );
            pagedSearchControl.setSize( 0 );
            pagedSearchControl.setCritical( true );

            // Close the cursor
            EntryFilteringCursor cursor = psCookie.getCursor();

            if ( cursor != null )
            {
                cursor.close();
            }
        }
        else
        {
            pagedSearchControl.setSize( 0 );
            pagedSearchControl.setCritical( true );
        }

        // and return
        // DO NOT WRITE THE RESPONSE - JUST RETURN IT
        LdapResult ldapResult = req.getResultResponse().getLdapResult();
View Full Code Here

        connection.bind( "uid=admin,ou=system", "secret" );
   
        SearchControls controls = new SearchControls();
        controls.setCountLimit( ( int ) LdapServer.NO_SIZE_LIMIT );
        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
        PagedResults pagedSearchControl = new PagedResultsDecorator( codec );
        pagedSearchControl.setSize( 3 );
   
        // Loop over all the elements
        int loop = 0;
        List<Entry> results = new ArrayList<Entry>();
        boolean hasUnwillingToPerform = false;
   
        while ( true )
        {
            loop++;
   
            EntryCursor cursor = null;
   
            try
            {
                SearchRequest searchRequest = new SearchRequestImpl();
                searchRequest.setBase( new Dn( "ou=system" ) );
                searchRequest.setFilter( "(ObjectClass=*)" );
                searchRequest.setScope( SearchScope.SUBTREE );
                searchRequest.addAttributes( "*" );
                searchRequest.addControl( pagedSearchControl );
   
                cursor = new EntryCursorImpl( connection.search( searchRequest ) );
   
                int i = 0;
   
                while ( cursor.next() )
                {
                    Entry result = cursor.get();
                    results.add( result );
                    ++i;
                }
   
                SearchResultDone result = cursor.getSearchResultDone();
                pagedSearchControl = ( PagedResults ) result.getControl( PagedResults.OID );
   
                if ( result.getLdapResult().getResultCode() == ResultCodeEnum.UNWILLING_TO_PERFORM )
                {
                    hasUnwillingToPerform = true;
                    break;
                }
            }
            finally
            {
                if ( cursor != null )
                {
                    cursor.close();
                }
            }
   
            // Now read the next ones
            assertEquals( 0, pagedSearchControl.getSize() );
   
            // check if this is over
            byte[] cookie = pagedSearchControl.getCookie();
   
            if ( Strings.isEmpty( cookie ) )
            {
                // If so, exit the loop
                break;
            }
   
            // Prepare the next iteration, sending a bad cookie
            pagedSearchControl.setCookie( "test".getBytes( "UTF-8" ) );
            pagedSearchControl.setSize( 3 );
        }
   
        assertTrue( hasUnwillingToPerform );
   
        // Cleanup the session
View Full Code Here

TOP

Related Classes of org.apache.directory.api.ldap.model.message.controls.PagedResults

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.