Return-Path: X-Original-To: apmail-directory-api-archive@minotaur.apache.org Delivered-To: apmail-directory-api-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F1FA41087C for ; Wed, 12 Mar 2014 22:01:47 +0000 (UTC) Received: (qmail 72815 invoked by uid 500); 12 Mar 2014 22:01:47 -0000 Delivered-To: apmail-directory-api-archive@directory.apache.org Received: (qmail 72788 invoked by uid 500); 12 Mar 2014 22:01:47 -0000 Mailing-List: contact api-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: api@directory.apache.org Delivered-To: mailing list api@directory.apache.org Received: (qmail 72780 invoked by uid 99); 12 Mar 2014 22:01:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Mar 2014 22:01:46 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [209.85.160.169] (HELO mail-yk0-f169.google.com) (209.85.160.169) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Mar 2014 22:01:41 +0000 Received: by mail-yk0-f169.google.com with SMTP id 142so419132ykq.0 for ; Wed, 12 Mar 2014 15:01:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=DKBYfCWQqZZhAtveAQgYyAItdWGl3slgHjJ/f//b6UA=; b=JEWpME+4K7L/Tp5uByy4f4mdvSBocyFnb4oMwOZXxQUYnmXNWg6lYmqGFIdko2zx4U sP6wTwP9Lk7lzaqlmw52BMprpQdH4dgTd+gGSPA5j/lZ2kkTNosiGc3whCpbKBb99Dlf L2HelbYGkh9dAOT277oQ+250iGoshxNB5Ki29tcKP+Fy0+2h1rxSJvnuhR0ohs4OXNY0 kJAOEp6pDXTMV7EkRrrtkHQxLJ8ZabqLIbXhD5yrAh+E6kzkfGCdgmp/Uyl15Qgne4yt QKhVDPZwuhoq0/bgkhWkgyw2Jn50Fr/LhfFp4ipDm9YZOn6KssJeRmV9e98KYjKE3Uc6 qXrA== X-Gm-Message-State: ALoCoQmszwehfBwRELEz7P08FyBCFdSgHItBy+b8Bk0Bt/+bk9aZPDDzQgp7EK2h9TXl3hHmrrH6 MIME-Version: 1.0 X-Received: by 10.236.201.77 with SMTP id a53mr23123084yho.104.1394661679689; Wed, 12 Mar 2014 15:01:19 -0700 (PDT) Received: by 10.170.86.7 with HTTP; Wed, 12 Mar 2014 15:01:19 -0700 (PDT) In-Reply-To: References: Date: Wed, 12 Mar 2014 18:01:19 -0400 Message-ID: Subject: Re: java.lang.ClassCastException when doing paginated search From: Gabriel Albano To: api@directory.apache.org Content-Type: multipart/alternative; boundary=089e0160b5b600206b04f46ffa1d X-Virus-Checked: Checked by ClamAV on apache.org --089e0160b5b600206b04f46ffa1d Content-Type: text/plain; charset=ISO-8859-1 That did it. Switching to M21 next. Thanks! On Wed, Mar 12, 2014 at 10:43 AM, Kiran Ayyagari wrote: > On Wed, Mar 12, 2014 at 8:10 PM, Gabriel Albano > 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 results = new ArrayList(); > > 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 > --089e0160b5b600206b04f46ffa1d--