Java 在ApacheCamelLDAP组件中分页结果

Java 在ApacheCamelLDAP组件中分页结果,java,ldap,apache-camel,Java,Ldap,Apache Camel,我需要从LDAP获取几个条目(>1000个用户)。文档()说有一个页面大小选项 页面大小 “指定时,ldap模块使用分页来检索所有结果(大多数ldap服务器在一个查询中检索1000多个条目时会引发异常)。要使用此功能,必须将LdapContext(DirContext的子类)作为ldapServerBean传入(否则会引发异常)” 这是什么意思?如何传入LdapContext以及如何遍历页面?有人能给我一个简单的例子,其中许多条目是从LDAP中获取的吗?除了指定pageSize参数之外,您可能无

我需要从LDAP获取几个条目(>1000个用户)。文档()说有一个页面大小选项

页面大小
“指定时,ldap模块使用分页来检索所有结果(大多数ldap服务器在一个查询中检索1000多个条目时会引发异常)。要使用此功能,必须将LdapContext(DirContext的子类)作为ldapServerBean传入(否则会引发异常)”


这是什么意思?如何传入LdapContext以及如何遍历页面?有人能给我一个简单的例子,其中许多条目是从LDAP中获取的吗?

除了指定
pageSize
参数之外,您可能无需做其他事情。描述澄清了一个您可能不会遇到的小问题

ldap
组件不仅限于从
LdapContext
读取,它还可以使用
DirContext
的实例(超级接口)。除了设置
pageSize
之外,使用此超级界面的实例也可以。如果遵循Camel文档中的示例,您将看到它使用
com.sun.jndi.ldap.LdapCtxFactory
作为上下文bean的工厂。此类构建实现
LdapContext
的对象,因此
pageSize
参数应该可以工作

例如,您可以简单地将参数添加到URI中

Collection<?> results = (Collection<?>) (template
  .sendBody(
    "ldap:ldapserver?base=ou=mygroup,ou=groups,ou=system&pageSize=1000",
    "(member=uid=huntc,ou=users,ou=system)"));
收集结果=(收集)(模板) .sendBody( “ldap:ldapserver?base=ou=mygroup,ou=groups,ou=system&pageSize=1000”, “(member=uid=huntc,ou=users,ou=system)”);
您的问题已经很老了,但是一个答案也可以帮助其他人,因为Camel的LDAP端点还不清楚。下面是一个工作示例:

<bean id="ldapServerBean" class="javax.naming.ldap.InitialLdapContext" scope="prototype">
<constructor-arg>
    <props>
        <prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop>
        <prop key="java.naming.provider.url">${ldap.url}</prop>
        <prop key="java.naming.security.authentication">simple</prop>
        <prop key="java.naming.security.principal">${ldap.user}</prop>
        <prop key="java.naming.security.credentials">${ldap.password}</prop>
    </props>
</constructor-arg>
<constructor-arg>
    <null />
</constructor-arg>
</bean>

com.sun.jndi.ldap.ldapctx工厂
${ldap.url}
易于理解的
${ldap.user}
${ldap.password}
路线:

<route id="LDAP" autoStartup="{{route.autoStartup}}">
    <from uri="quartz2://ldapTimer?cron={{scheduler.cron}}"/>
    <setBody><simple>{{ldap.filter}}</simple></setBody>
    <to uri="ldap:ldapServerBean?base={{ldap.base}}&amp;scope={{ldap.scope}}&amp;returnedAttributes={{ldap.returnedAttributes}}&amp;pageSize={{ldap.pageSize}}"/>
    <log loggingLevel="INFO" message="LDAP Result: ${body}"/>
    <to ...>
</route>

{{ldap.filter}
通过这种方式,您可以使用路由中作为参数提供的pageSize,并能够从LDAP服务器检索1000多条记录