4 Replies Latest reply on Aug 28, 2002 6:38 AM by Binoy Shah

    jndiView MBean doesnt work with ExternalContext

    Binoy Shah Newbie

      OLD EXTERNAL LDAP CONFIG for JBOSS Version 2.4.4

      --------------
      jboss.jcml
      --------------

      <!-- Bind a remote LDAP server -->

      external/ldap/practiceit
      sscldap.conf
      javax.naming.ldap.InitialLdapContext
      true


      OLD EXTERNAL LDAP CONFIG for JBOSS Version 2.4.4
      --------------
      sscldap.conf
      --------------
      java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
      java.naming.provider.url=ldap://206.135.232.178:389/dc=practiceit,dc=net
      java.naming.security.principal=cn=SystemManager,dc=practiceit,dc=net
      java.naming.security.authentication=simple
      java.naming.security.credentials=secretpass


      ****************************************************
      WORKING JAVA CODE FOR JNDI ACCESS for Version 2.4.4
      ****************************************************

      public String search(String name)
      {
      String bId ="";
      try
      {
      /* Create an environment for the initial directory context.*/
      /* Create the initial directory context. */
      DirContext drctx = new InitialDirContext(getInitialLdapContext().getEnvironment());;
      /* Set up and perform the search. Find all matching in ou=name. */
      String base = "o=PracticeVeterinary";
      String filter = "(ou="+name+")";
      SearchControls constraints = new SearchControls();
      constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
      NamingEnumeration results = drctx.search(base,filter,constraints);
      /* Print the search results. */
      if (!results.hasMore())
      {
      System.out.println("Nothing found.");
      }
      else
      {
      while (results.hasMore())
      {
      SearchResult sr = (SearchResult) results.next();
      Attributes attrs = sr.getAttributes();
      if (attrs == null)
      {
      System.out.println("No attributes");
      }
      else
      {
      /* For each attribute of the entry.
      find a custom entry called bid */
      Attribute bIdCtx = attrs.get("bid");
      bId = (String)bIdCtx.get(0);
      }
      }
      }
      }
      catch (NamingException e)
      {
      /* Handle any name/directory exceptions. */
      }//catch
      catch (Exception e)
      {
      /* Handle any other types of exceptions. */
      }//catch
      return bId;
      }
      public Context getInitialLdapContext() throws NamingException
      {
      String ldapCtxString = "external/ldap/practiceit";
      InitialContext initCtx = new InitialContext();
      Context ldapCtx = (Context)initCtx.lookup(ldapCtxString);
      return ldapCtx;
      }


      JBOSS 3.0.1 SETTINGS

      ------------------
      jboss-service.xml
      ------------------

      <!-- Added for creating external JNDI Reference to LDAP server -->

      external/ldap/practiceit
      /conf/sscldap.conf
      javax.naming.ldap.InitialLdapContext
      true


      ---------------------------------
      sscldap.conf file in conf folder
      ---------------------------------

      java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
      java.naming.provider.url=ldap://192.9.200.5:389/dc=practiceit,dc=net
      java.naming.security.principal=cn=SystemManager,dc=practiceit,dc=net
      java.naming.security.authentication=simple
      java.naming.security.credential=secretpass

      Once i add this reference and start the server the jndiView MBean doesnt work
      [B]
      If i invoke the list() function with (false) it just hangs and after around 20 minutes it
      gives out of memory error ( have put 512 M stack)[/B]

      [U]The list function works fine if i remove the externalContext configuration[/U]

      The java code too gives an exception "Not a DirContext" upon execution