Ich habe Probleme, die VLV-Kontrolle zu funktionieren. Ich benutze ApacheDS 2.0.0 und rede mit Java JNDI mit ldapbp-1.0.jar von Sun. Bei der Abfrage sagt der Server, dass er die VLV-Kontrolle unterstützt. Ich bekomme keine Fehler, aber ich richte die Suchvorgänge ein und erhalte alle Ergebnisse statt einer Teilmenge. Ich habe eine neue ApacheDS-Instanz eingerichtet und sie hat 10 Benutzer. Ich bekomme immer alle 10 in den Ergebnissen.LDAP VirtualListView kann nicht funktionieren
Ich bekomme auch eine SortierungResponseControl zurück und nie ein VirtualListViewResponseControl.
Ich habe viele Beispiele gesehen und ich mache im Wesentlichen, was sie sind. Dieses Codebeispiel nahm ich wörtlich und änderte nur die Verbindungsinformationen und Suchkriterien und ich bekomme immer noch das gleiche Problem. Post from LDAP Pro forum
Einige der Parameter I für die VirtualListViewControl versucht haben, sind:
new VirtualListViewControl(1, 0, 0, 19, Control.CRITICAL); // original - gets all
new VirtualListViewControl(1, 10, 1, 2, Control.CRITICAL); // target offset -gets all
new VirtualListViewControl(20, 3, Control.CRITICAL); // target percentage - gets all
new VirtualListViewControl("Tryit4", 3, Control.CRITICAL); // target value, view size - gets all
new VirtualListViewControl("Tryit4", 2, 1, Control.CRITICAL); // target value, before count, after count
ich etwas falsch zu machen müssen, aber ich kann nicht sehen, was es ist. Jede Hilfe wäre willkommen. Danke
Leider funktioniert der Link nicht. Es hat für mich getan. Hier ist das Codebeispiel, das ich verwende, das immer ein SortierungResponseControl und alle LDAP-Einträge zurückgibt.
/**
*
* VLVJndiClient.java
* Sample code to demostrate how Virtual List View (VLV) Control works.
* Note:
* 1) Note: JNDI Boost package is required for this example to run.
* 2) VLV Control MUST be used in conjunction with Sort Control.
* Otherwise, you will be braced by: [LDAP: error code 60 - VLV Control]
* 3) SunOne Directory Server supports VLV & Microsoft supports VLV since AD2003
*
*/
import java.util.Hashtable;
import java.io.*;
import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.ldap.*;
import com.sun.jndi.ldap.ctl.VirtualListViewControl;
import com.sun.jndi.ldap.ctl.VirtualListViewResponseControl;
import com.sun.jndi.ldap.ctl.SortControl;
public class VLVJndiClientShort
{
static final String VLV_CONTROL_OID = "2.16.840.1.113730.3.4.9";
public static void main(String[] args) throws IOException
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://172.16.2.23:10389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
env.put(Context.SECURITY_CREDENTIALS, "test");
try {
/* Create initial context with no connection request controls */
LdapContext ctx = new InitialLdapContext(env, null);
/* Query the server to see if the VLV Control is supported */
if (!isVLVControlSupported(ctx)){
System.out.println(
"The server does not support Virtual List View (VLV) Control.");
System.exit(1);
}
/* Sort Control is required for VLV to work */
SortControl sctl = new SortControl(
new String[]{"cn"}, // sort by cn
Control.CRITICAL
);
/* VLV that returns the first 20 answers 0 to 19 changed 19 to 2 */
VirtualListViewControl vctl =
// new VirtualListViewControl(1, 0, 0, 19, Control.CRITICAL); // original - gets all
// new VirtualListViewControl(1, 10, 1, 2, Control.CRITICAL); // target offset, list size, before count, after count, criticality - gets all
// new VirtualListViewControl(20, 3, Control.CRITICAL); // target percentage, view size, criticality - gets all
// new VirtualListViewControl("Tryit4", 3, Control.CRITICAL); // target value, view size, criticality - gets all
new VirtualListViewControl("Tryit4", 2, 1, Control.CRITICAL); // target value, before count, after count, criticality
/* Set context's request controls */
ctx.setRequestControls(new Control[]{sctl, vctl}); // returns only a sorted control but no VLV control
/* Perform search */
NamingEnumeration answer =
ctx.search("dc=mir3,dc=example,dc=com", "(objectclass=*)", null);
/* Enumerate search results */
while (answer.hasMore()) {
SearchResult si = (SearchResult)answer.next();
System.out.println(si.getName());
}
/* examine the response controls (if any) */
printControls(ctx.getResponseControls());
ctx.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
static void printControls(Control[] controls)
{
if(controls == null){
System.out.println("No response controls");
return;
}
for(int j = 0; j < controls.length; j++) {
if(controls[j] instanceof SortResponseControl){
SortResponseControl src = (SortResponseControl)controls[j];
if (src.isSorted()) {
System.out.println("Sorted-Search completed successfully");
} else {
System.out.println(
"Sorted-Search did not complete successfully: error (" +
src.getResultCode() + ") on attribute '" +
src.getAttributeID() + "'");
}
}else if(controls[j] instanceof VirtualListViewResponseControl){
VirtualListViewResponseControl vlv =
(VirtualListViewResponseControl)controls[j];
if (vlv.getResultCode() == 0) {
System.out.println("Sorted-View completed successfully");
System.out.println("TargetOffset: " + vlv.getTargetOffset());
System.out.println("ListSize: " + vlv.getListSize());
} else {
System.out.println("Sorted-View did not complete successfully: "
+ vlv.getResultCode());
}
} else {
System.out.println("Received control: "+ controls[j].getID());
}
}
}
/**
* Is VLV Control supported?
*
* Query the rootDSE object to find out if VLV Control
* is supported.
*/
static boolean isVLVControlSupported(LdapContext ctx)
throws NamingException
{
SearchControls ctl = new SearchControls();
ctl.setReturningAttributes(new String[]{"supportedControl"});
ctl.setSearchScope(SearchControls.OBJECT_SCOPE);
/* search for the rootDSE object */
NamingEnumeration results = ctx.search("", "(objectClass=*)", ctl);
while(results.hasMore()){
SearchResult entry = (SearchResult)results.next();
NamingEnumeration attrs = entry.getAttributes().getAll();
while (attrs.hasMore()){
Attribute attr = (Attribute)attrs.next();
NamingEnumeration vals = attr.getAll();
while (vals.hasMore()){
String value = (String) vals.next();
if (value.equals(VLV_CONTROL_OID))
return true;
}
}
}
return false;
}
}
Link funktioniert nicht, und auf jeden Fall muss der Code hier veröffentlicht werden. – EJP
Entschuldigung. Habe gerade den Code hinzugefügt. – eightmd