directory-api mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gabriel Albano <gabriel.alb...@pilixo.com>
Subject Re: java.lang.ClassCastException when doing paginated search
Date Wed, 12 Mar 2014 22:01:19 GMT
That did it.  Switching to M21 next.

Thanks!


On Wed, Mar 12, 2014 at 10:43 AM, Kiran Ayyagari <kayyagari@apache.org>wrote:

> On Wed, Mar 12, 2014 at 8:10 PM, Gabriel Albano
> <gabriel.albano@pilixo.com>wrote:
>
> > Hi, I have followed the instructions from a thread reporting the same
> issue
> > (
> >
> >
> http://mail-archives.apache.org/mod_mbox/directory-api/201312.mbox/%3CCAPmZGnw%2B7jMiACgxc14DMg-Ss-2JY%3Db-9j8Euxb8iJ%2BC1sb%3DXQ%40mail.gmail.com%3E
> > )
> > but I am still getting the ClassCastException error.
> >
> > Using 2.0.0-M15 server and 1.0.0.-M20 api.  This is the code:
> >
> >         connection = new LdapNetworkConnection("localhost", 10389);
> >         connection.setTimeOut(0);
> >         connection.bind();
> >
> >
> >
> >
> System.setProperty(StandaloneLdapApiService.CONTROLS_LIST,PagedResultsFactory.class.getName());
> >
> > you need to set this before creating the LdapNetworkConnection
> or try using M21 (was just released) in this version you don't need to set
> this property
>
> >         PagedResults pagedSearchControl = new PagedResultsDecorator(
> >                 connection.getCodecService());
> >         pagedSearchControl.setSize(300);
> >
> >         // Loop over all the elements
> >         List<Entry> results = new ArrayList<Entry>();
> >         boolean hasUnwillingToPerform = false;
> >
> >         Integer p = 0;
> >         while (true) {
> >             EntryCursor cursor = null;
> >
> >             try {
> >                 SearchRequest searchRequest = new SearchRequestImpl();
> >                 searchRequest.setBase(new
> Dn("ou=organizations,dc=test"));
> >                 searchRequest.setFilter("(objectclass=device)");
> >                 searchRequest.setScope(SearchScope.SUBTREE);
> >                 searchRequest.addAttributes("*");
> >                 searchRequest.addControl(pagedSearchControl);
> >                 searchRequest.setSizeLimit(10000);
> >
> >                 cursor = new EntryCursorImpl(
> >                         connection.search(searchRequest));
> >
> >                 while (cursor.next()) {
> >                     Entry result = cursor.get();
> >                     results.add(result);
> >                 }
> >                 p++;
> >                 System.out.println("PAGE: " + p.toString());
> >                 System.out.println("TOTAL of Results: " +
> results.size());
> >
> >                 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();
> >                 }
> >             }
> >
> >             // check if this is over
> >             byte[] cookie = pagedSearchControl.getCookie();
> >
> >             if (Strings.isEmpty(cookie)) {
> >                 // If so, exit the loop
> >                 break;
> >             }
> >
> >             // Prepare the next iteration
> >             pagedSearchControl.setSize(300);
> >         }
> >
> >         if (hasUnwillingToPerform) {
> >             throw new IllegalStateException("AD can't handle paging");
> >         }
> >
> >         // Cleanup the session
> >         connection.unBind();
> >         connection.close();
> >
> >
> > I have checked the system properties at run time and I see this:
> >
> >
> apacheds.controls=org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsFactory
> >
> > Still getting "Exception in thread "main" java.lang.ClassCastException:
> > org.apache.directory.api.ldap.codec.BasicControlDecorator cannot be cast
> to
> > org.apache.directory.api.ldap.model.message.controls.PagedResults
> >
> > I appreciate any help.
> >
> > Thanks,
> > Gabriel
> >
>
>
>
> --
> Kiran Ayyagari
> http://keydap.com
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message