private boolean prepareNextPage(LdapContext ldapContext) throws Exception { Control[] responseControls = ldapContext.getResponseControls(); byte[] cookie = null; if (responseControls != null) { for (Control responseControl : responseControls) { if (responseControl instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl) responseControl; cookie = prrc.getCookie(); } } } if (cookie == null) { return false; } else { ldapContext.setRequestControls(new Control[]{new PagedResultsControl(pageSize, cookie, Control.CRITICAL)}); return true; } }
private List<SearchResult> pagedSearch(LdapContext ldapContext, String searchFilter) throws Exception { List<SearchResult> data = new ArrayList<SearchResult>(); log.trace("Using paged ldap search, pageSize={}", pageSize); Control[] requestControls = new Control[]{new PagedResultsControl(pageSize, Control.CRITICAL)}; ldapContext.setRequestControls(requestControls); do { List<SearchResult> pageResult = simpleSearch(ldapContext, searchFilter); data.addAll(pageResult); log.trace("Page returned {} entries", pageResult.size()); } while (prepareNextPage(ldapContext)); if (log.isDebugEnabled()) { log.debug("Found a total of {} entries for ldap filter {}", data.size(), searchFilter); } return data; }
private boolean supportsSearchResultPaging() throws ChaiUnavailableException, ChaiOperationException { final String enableSettingStr = this.getChaiConfiguration().getSetting( ChaiSetting.LDAP_SEARCH_PAGING_ENABLE ); if ( "auto".equalsIgnoreCase( enableSettingStr ) ) { if ( cachedPagingEnableSupport == null ) { final ChaiEntry rootDse = ChaiUtility.getRootDSE( this ); final Set<String> supportedControls = rootDse.readMultiStringAttribute( "supportedControl" ); cachedPagingEnableSupport = supportedControls.contains( PagedResultsControl.OID ); } return cachedPagingEnableSupport; } return Boolean.parseBoolean( enableSettingStr ); }
/** * Set the standard request controls */ private void setRequestControls(byte[] cookie) throws TranslatorException { List<Control> ctrl = new ArrayList<Control>(); SortKey[] keys = searchDetails.getSortKeys(); try { if (keys != null) { ctrl.add(new SortControl(keys, Control.NONCRITICAL)); } if (this.executionFactory.usePagination()) { ctrl.add(new PagedResultsControl(this.executionContext.getBatchSize(), cookie, Control.CRITICAL)); } if (!ctrl.isEmpty()) { this.ldapCtx.setRequestControls(ctrl.toArray(new Control[ctrl.size()])); LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Sort/pagination controls were created successfully."); //$NON-NLS-1$ } } catch (NamingException ne) { final String msg = LDAPPlugin.Util.getString("LDAPSyncQueryExecution.setControlsError") + //$NON-NLS-1$ " : "+ne.getExplanation(); //$NON-NLS-1$ throw new TranslatorException(ne, msg); } catch(IOException e) { throw new TranslatorException(e); } }
private byte[] getCookie(final LdapContext ctx) throws NamingException, IOException { byte[] cookie = null; // Examine the paged results control response final Control[] controls = ctx.getResponseControls(); if (controls != null) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof PagedResultsResponseControl) { final PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i]; cookie = prrc.getCookie(); } } } // Re-activate paged results ctx.setRequestControls(new Control[] { new PagedResultsControl(PAGE_SIZE, cookie, Control.CRITICAL) }); return cookie; }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsControl.PagedResultsControl(int, boolean)'</p> * <p>Here we are testing if this method constructs a control to set the number of entries to be returned per page of results.</p> * <p>The expected result is an instance of this class.</p> */ public void testPagedResultsControlIntBoolean001() { try { PagedResultsControl prc=new PagedResultsControl(0,false); assertNotNull(prc); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsControl.PagedResultsControl(int, boolean)'</p> * <p>Here we are testing if this method constructs a control to set the number of entries to be returned per page of results.</p> * <p>The expected result is an instance of this class.</p> */ public void testPagedResultsControlIntBoolean002() { try { PagedResultsControl prc=new PagedResultsControl(0,true); assertNotNull(prc); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsControl.PagedResultsControl(int, boolean)'</p> * <p>Here we are testing if this method constructs a control to set the number of entries to be returned per page of results.</p> * <p>The expected result is an instance of this class.</p> */ public void testPagedResultsControlIntBoolean003() { try { PagedResultsControl prc=new PagedResultsControl(100,false); assertNotNull(prc); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsControl.PagedResultsControl(int, boolean)'</p> * <p>Here we are testing if this method constructs a control to set the number of entries to be returned per page of results.</p> * <p>The expected result is an instance of this class.</p> */ public void testPagedResultsControlIntBoolean004() { try { PagedResultsControl prc=new PagedResultsControl(100,true); assertNotNull(prc); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsControl.PagedResultsControl(int, boolean)'</p> * <p>Here we are testing if this method constructs a control to set the number of entries to be returned per page of results.</p> * <p>The expected result is an instance of this class.</p> */ public void testPagedResultsControlIntBoolean005() { try { PagedResultsControl prc=new PagedResultsControl(1000000,false); assertNotNull(prc); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsControl.PagedResultsControl(int, boolean)'</p> * <p>Here we are testing if this method constructs a control to set the number of entries to be returned per page of results.</p> * <p>The expected result is an instance of this class.</p> */ public void testPagedResultsControlIntBoolean006() { try { PagedResultsControl prc=new PagedResultsControl(1000000,true); assertNotNull(prc); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsControl.PagedResultsControl(int, byte[], boolean)'</p> * <p>Here we are testing if this method constructs a control to set the number of entries to be returned per page of results.</p> * <p>The expected result is an instance of this class.</p> */ public void testPagedResultsControlIntByteArrayBoolean001() { try { PagedResultsControl prc=new PagedResultsControl(0,null,true); assertNotNull(prc); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsControl.PagedResultsControl(int, byte[], boolean)'</p> * <p>Here we are testing if this method constructs a control to set the number of entries to be returned per page of results.</p> * <p>The expected result is an instance of this class.</p> */ public void testPagedResultsControlIntByteArrayBoolean002() { try { PagedResultsControl prc=new PagedResultsControl(0,null,false); assertNotNull(prc); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsControl.PagedResultsControl(int, byte[], boolean)'</p> * <p>Here we are testing if this method constructs a control to set the number of entries to be returned per page of results.</p> * <p>The expected result is an instance of this class.</p> */ public void testPagedResultsControlIntByteArrayBoolean003() { try { byte[] by={10,10}; PagedResultsControl prc=new PagedResultsControl(10,by,true); assertNotNull(prc); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.PagedResultsControl.PagedResultsControl(int, byte[], boolean)'</p> * <p>Here we are testing if this method constructs a control to set the number of entries to be returned per page of results.</p> * <p>The expected result is an instance of this class.</p> */ public void testPagedResultsControlIntByteArrayBoolean004() { try { byte[] by={10,10}; PagedResultsControl prc=new PagedResultsControl(10,by,false); assertNotNull(prc); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.BasicControl.getEncodedValue()'</p> * <p>Here we are testing if this method returns retrieves the control's ASN.1 BER encoded value.</p> * <p>The expected result is a byte array representing the control's ASN.1 BER encoded value.</p> */ public void testGetEncodedValue001() { byte[] by={10,10}; try { PagedResultsControl prc=new PagedResultsControl(10,by,false); assertEquals("30 07 02 01 0a 04 02 0a 0a",toHexString(prc.getEncodedValue())); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.BasicControl.getEncodedValue()'</p> * <p>Here we are testing if this method returns retrieves the control's ASN.1 BER encoded value.</p> * <p>The expected result is a byte array representing the control's ASN.1 BER encoded value.</p> */ public void testGetEncodedValue002() { try { PagedResultsControl prc=new PagedResultsControl(0,null,false); assertEquals("30 05 02 01 00 04 00",toHexString(prc.getEncodedValue())); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.BasicControl.getEncodedValue()'</p> * <p>Here we are testing if this method returns retrieves the control's ASN.1 BER encoded value.</p> * <p>The expected result is a byte array representing the control's ASN.1 BER encoded value.</p> */ public void testGetEncodedValue003() { try { PagedResultsControl prc=new PagedResultsControl(0,null,true); assertEquals("30 05 02 01 00 04 00",toHexString(prc.getEncodedValue())); } catch (IOException e) { fail("Failed with:"+e); } }
/** * <p>Test method for 'javax.naming.ldap.BasicControl.getEncodedValue()'</p> * <p>Here we are testing if this method returns retrieves the control's ASN.1 BER encoded value.</p> * <p>The expected result is a byte array representing the control's ASN.1 BER encoded value.</p> */ public void testGetEncodedValue004() { byte[] by={1,10,20}; try { PagedResultsControl prc=new PagedResultsControl(0,by,false); assertEquals("30 08 02 01 00 04 03 01 0a 14",toHexString(prc.getEncodedValue())); } catch (IOException e) { fail("Failed with:"+e); } }
public void test_reconnect() throws Exception { Hashtable<Object, Object> env = new Hashtable<Object, Object>(); env .put("java.naming.ldap.control.connect", new Control[] { new PagedResultsControl(10, Control.NONCRITICAL) }); MockLdapClient client = new MockLdapClient(); context = new LdapContextImpl(client, env, "cn=test"); Control[] controls = context.getConnectControls(); assertNotNull(controls); Control c = controls[0]; assertTrue(c instanceof PagedResultsControl); assertEquals(Control.NONCRITICAL, ((PagedResultsControl) c).isCritical()); context.reconnect(new Control[] { new SortControl("", Control.NONCRITICAL) }); controls = context.getConnectControls(); assertNotNull(controls); assertEquals(1, controls.length); c = controls[0]; assertTrue(c instanceof SortControl); assertEquals(Control.NONCRITICAL, ((SortControl) c).isCritical()); context.reconnect(null); assertNull(context.getConnectControls()); }