You are viewing a plain text version of this content. The canonical link for it is here.
Posted to api@directory.apache.org by Stefan Murawski <st...@gmail.com> on 2013/12/04 13:06:53 UTC
ClassCast Exception with Paging
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>
Re: ClassCast Exception with Paging
Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 12/4/13 4:38 PM, Daniel Fisher a écrit :
> On Wed, Dec 4, 2013 at 7:06 AM, Stefan Murawski <st...@gmail.com> wrote:
>> 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);
>>
> Try adding: System.setProperty(StandaloneLdapApiService.CONTROLS_LIST,
> PagedResultsFactory.class.getName());
> at the top of your code.
> I recall seeing CastClassExceptions if the ApiService doesn't know
> about the control.
This is something we have to fix...
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com
Re: ClassCast Exception with Paging
Posted by Stefan Murawski <st...@gmail.com>.
Thanks!
This helped.
And also removing the line
pagedSearchControl.setCookie("test".getBytes("UTF-8"));
which broke the process.
2013/12/4 Daniel Fisher <df...@vt.edu>
> On Wed, Dec 4, 2013 at 7:06 AM, Stefan Murawski <st...@gmail.com> wrote:
> > 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);
> >
>
> Try adding: System.setProperty(StandaloneLdapApiService.CONTROLS_LIST,
> PagedResultsFactory.class.getName());
> at the top of your code.
> I recall seeing CastClassExceptions if the ApiService doesn't know
> about the control.
>
> --Daniel Fisher
>
Re: ClassCast Exception with Paging
Posted by Daniel Fisher <df...@vt.edu>.
On Wed, Dec 4, 2013 at 7:06 AM, Stefan Murawski <st...@gmail.com> wrote:
> 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);
>
Try adding: System.setProperty(StandaloneLdapApiService.CONTROLS_LIST,
PagedResultsFactory.class.getName());
at the top of your code.
I recall seeing CastClassExceptions if the ApiService doesn't know
about the control.
--Daniel Fisher