directory-api mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Murawski <stm...@gmail.com>
Subject ClassCast Exception with Paging
Date Wed, 04 Dec 2013 12:06:53 GMT
Hi,

I followed this example to set-up paging for my project:
http://markmail.org/message/43qjepg6shvfvqud

This results in my following code:

PagedResults pagedSearchControl = new PagedResultsDecorator(
                    connection.getCodecService());
            pagedSearchControl.setSize(300);

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

            //inspired by http://markmail.org/message/43qjepg6shvfvqud
            while (true) {
                EntryCursor cursor = null;

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

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

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

                    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, sending a bad cookie
                pagedSearchControl.setCookie("test".getBytes("UTF-8"));
                pagedSearchControl.setSize(300);
            }

Unfortunately I get the following ClassCast-Exception, and don't know how
to proceed further.

java.lang.ClassCastException:
org.apache.directory.api.ldap.codec.BasicControlDecorator cannot be cast to
org.apache.directory.api.ldap.model.message.controls.PagedResults

for:

                    pagedSearchControl = (PagedResults) result
                            .getControl(PagedResults.OID);

I use the following dependency:
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-all</artifactId>
<version>1.0.0-M20</version>
</dependency>

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