go to  ForumEasy.com   
LdapPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  OperationNotSupportedException
 
Subject: OperationNotSupportedException
Author: SteveHB
In response to: LDAP Search Paged Results Control JNDI Client
Posted on: 09/06/2006 01:14:14 PM

If you run the above client against LDAP servers which do not support Paged Results Control, most likely you are going to get error message similar like this.

javax.naming.OperationNotSupportedException from SunOne Directory Server:

javax.naming.OperationNotSupportedException: [LDAP: error code 12 - Unavailable Critical Extension];
remaining name 'dc=mydomain,dc=com'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3045)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2931)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2737)
at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1808)
at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1731)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:368)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:338)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:321)
at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:248)



 

> On 09/06/2006 12:57:01 PM SteveHB wrote:


The following example shows how a client performs Paged Results Control to interact with server.

/**
 * 
 * PagedResultsControlJndiClient.java
 * Sample code to demostrate how Paged Results Control works.
 * 
 */
 
import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.ldap.*;

import java.util.Hashtable;

public class PagedResultsControlJndiClient 
{
	
  static final String  PAGED_RESULT_CONTROL_OID = "1.2.840.113556.1.4.319";
    
  public static void main(String[] args)
  {
    Hashtable env = new Hashtable();
        
    env.put(Context.INITIAL_CONTEXT_FACTORY, 
                    "com.sun.jndi.ldap.LdapCtxFactory");
        
    // Note: Active Directory Server supports Paged Results Control 
    //       SunOne does not supports Paged Results Control but it supports 
    //       Virtual List View Control instead.
    env.put(Context.PROVIDER_URL, "ldap://myAD.mydomain.com:389");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "administrator@mydomain.com");
    env.put(Context.SECURITY_CREDENTIALS, "mypassword");
        
    try{
    	
      /* Open an LDAP connection for the provided principal and credentials */
      LdapContext ctx = new InitialLdapContext(env, null);
      System.out.println("Initial binding done!");
            
      /* Query the server to see if the paged result control is supported */ 
      if(!isPagedResultControlSupported(ctx)){
         System.out.println("The server does not support Paged Results Control.");
         System.exit(1);
      }

      /* Activate paged results */
      int pageSize = 5;
      byte[] cookie = null;
      int total;
	        
      ctx.setRequestControls(
              new Control[]{new PagedResultsControl(pageSize, Control.CRITICAL)});
      System.out.println("Paged control set!");

      int count = 0;
      while(true){
        count++;
        System.err.println("Search loop count = " + count);
                    
        SearchControls ctls = new SearchControls();
        ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
        ctls.setCountLimit(0);
        // Perform the search
        NamingEnumeration results = ctx.search("dc=mydomain,dc=com", 
                                               "(objectclass=*)", ctls);
	            
        try{
          // Iterate over a batch of search results
          while (results != null && results.hasMore()) {
              // Display an entry
              SearchResult entry = (SearchResult)results.next();
              System.out.println("entryDN=" + entry.getName());
          }
        }catch(Exception pe){
          System.out.println(pe.toString());  // Patial Result Exception
        }
	            
        // Examine the paged results control response 
        Control[] controls = ctx.getResponseControls();
        if(controls!=null){
          for(int k = 0; k<controls.length; k++){
            if(controls[k] instanceof PagedResultsResponseControl){
              PagedResultsResponseControl prrc = 
                       (PagedResultsResponseControl)controls[k];
              total = prrc.getResultSize();
              cookie = prrc.getCookie();
            }else{
              // Handle other response controls (if any)
            }
          }
        }
	
        if(cookie==null)
          break;
	            
         // Re-activate paged results
         ctx.setRequestControls(new Control[]{
             new PagedResultsControl(pageSize, cookie, Control.CRITICAL)});
       }
	
       // Close the LDAP association
       ctx.close();
     }catch (Exception e){
       e.printStackTrace();
     }
  }

  /**
   * Is paged result control supported?
   *
   * Query the rootDSE object to find out if the paged result control
   * is supported.
   */
  static boolean isPagedResultControlSupported(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(PAGED_RESULT_CONTROL_OID))
           return true;
        }
      }
    }
    return false;
  }

}



The above code has been tested against Active Directory 2000 and 2003.





References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.