go to  ForumEasy.com   
LdapPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  AD--javax.naming.OperationNotSupportedException
 
Subject: AD--javax.naming.OperationNotSupportedException
Author: SteveHB
In response to: Code Example
Posted on: 06/07/2007 03:29:40 PM

If some thing goes wrong, e.g. unrecognized attribute sorting key or maching rule, running the above code against Active Directory would bring back the following:


javax.naming.OperationNotSupportedException: [LDAP: error code 12 - 00000057: LdapErr: DSID-0C09068F, comment: Error processing control, data 0, vece]; remaining name 'ou=people,dc=mydomain,dc=com'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3065)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2951)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2758)
at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1812)
at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1735)
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 06/07/2007 01:22:21 PM SteveHB wrote:


/**
 * 
 * SortControlJndiClient.java
 * Sample code to demonstrate how Sort Control works.
 * 
 */
 
import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.ldap.*;

import java.util.Hashtable;

public class SortControlJndiClient 
{
	
  static final String  SORT_CONTROL_OID = "1.2.840.113556.1.4.473";
    
  public static void main(String[] args)
  {
    Hashtable env = new Hashtable();
        
    env.put(Context.INITIAL_CONTEXT_FACTORY, 
                    "com.sun.jndi.ldap.LdapCtxFactory");
        
    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 sort control is supported */ 
      if(!isSortControlSupported(ctx)){
         System.out.println("The server does not support Sort Control.");
         System.exit(1);
      }

      
      // Activate Sorting: A list of people sorted by: 
      //     ascending family name and descending given name
      SortKey[] sk = new SortKey[2];
      sk[0] = new SortKey("sn"); // ascending 
      sk[1] = new SortKey("givenName", false, null); // descending
	        
      ctx.setRequestControls(
              new Control[]{new SortControl(sk, Control.CRITICAL)});

      SearchControls ctls = new SearchControls();
      ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
      ctls.setCountLimit(0);

      // Perform the search
      NamingEnumeration results = ctx.search("ou=people,dc=mydomain,dc=com", 
                                           "(objectclass=*)", ctls);
      // Iterate over the search results
      while (results != null && results.hasMore()) {
          // Display an entry
          SearchResult entry = (SearchResult)results.next();
          System.out.println("entryDN=" + entry.getName());
          /* other output here */
      }
	            
      // Examine the sort control response 
      Control[] controls = ctx.getResponseControls();
      if(controls!=null){
        for(int k = 0; k<controls.length; k++){
          if(controls[k] instanceof SortResponseControl){
            SortResponseControl src = 
                     (SortResponseControl)controls[k];
            if(!src.isSorted()){
              throw src.getException();
            }
          }else{
            // Handle other response controls (if any)
          }
        }
      }
	
      // Close the LDAP association
      ctx.close();

    }catch (Exception e){
      e.printStackTrace();
    }
  }

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

}




References:

 


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