Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 1516 invoked from network); 4 Feb 2007 23:20:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Feb 2007 23:20:29 -0000 Received: (qmail 83479 invoked by uid 500); 4 Feb 2007 23:20:34 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 83446 invoked by uid 500); 4 Feb 2007 23:20:34 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 83431 invoked by uid 500); 4 Feb 2007 23:20:34 -0000 Delivered-To: apmail-incubator-directory-cvs@incubator.apache.org Received: (qmail 83427 invoked by uid 99); 4 Feb 2007 23:20:34 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Feb 2007 15:20:34 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS X-Spam-Check-By: apache.org Received: from [140.211.11.130] (HELO eos.apache.org) (140.211.11.130) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Feb 2007 15:20:26 -0800 Received: from eos.apache.osuosl.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id 162995A1CF for ; Sun, 4 Feb 2007 23:20:06 +0000 (GMT) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Apache Wiki To: directory-cvs@incubator.apache.org Date: Sun, 04 Feb 2007 23:20:05 -0000 Message-ID: <20070204232005.16024.26747@eos.apache.osuosl.org> Subject: [Directory Wiki] Update of "NamingHome" by CKoppelt X-Virus-Checked: Checked by ClamAV on apache.org Dear Wiki user, You have subscribed to a wiki page or wiki category on "Directory Wiki" for change notification. The following page has been changed by CKoppelt: http://wiki.apache.org/directory/NamingHome The comment on the change is: moved to http://cwiki.apache.org/DIRxSBOX/naming.html ------------------------------------------------------------------------------ + deleted - = 0.8 Setup = - The 0.8 code is focussed on supporting the java:comp/env namespace for web applications running inside a container. The Selector``Context and Context``Bindings classes enable multiple different naming contexts to be set up and bound to threads and classloaders. In tomcat, where the code originated, JNDI resources can be configured "globally" or at the web app level. Global naming resources are made available to individual web apps via resource links. - == Some details == - *The Context``Bindings class maintains hashtables linking external names with Naming``Context instances, as well as threads and classloaders. - *The javaURL``Context``Factory implements get``Initial``Context as follows: Check to see if the current thread or classloader is bound. If so, return a new Selector``Context; otherwise return a shared, writable Naming``Context maintained in a static member. - *The Selector``Context locates bound contexts and delegates JNDI operations to them. It uses its getBoundContext method to retrieve the appropriate context from Context``Bindings. If the Selector``Context is created as an initial context and get``Bound``Context does not find a context bound to the calling thread/classloader, it creates a new Naming``Context and binds the caller to it. - - = XML Configurator = - The Xml``Configurator was introduced to enable applications running outside of a J2EE container to load resource references and environment properties into a JNDI context. The current setup loads just one "unbound" context, rooted by default at "java:comp/env." Users can initialize contexts with different roots by supplying a value for the name attribute of the context element in the config file. The javaURL``Context``Factory is used by the Xml``Configurator, so by default it creates a shared, global, writable context. - A basic use case is to allow code that makes use of tomcat-managed JNDI to run outside of tomcat. Modifying the configurator dtd and initialization to support global resources and resource links will do this, but only for a single "global" context, which makes the whole concept less meaningful. - - = Proposal to clean up the current setup and to support federation and links across contexts = - *Extend the Xml``Configurator to support (multiple) named contexts and modify Naming``Context``to look for context names in the environment and either create new named contexts with these names or return the named context from Context``Bindings. For backward compatibility, map the empty name to a shared, writable context rooted at "java:comp/env." - COMPLETED - *Add a "base" attribute to the context element to play the role that the name attribute is now playing -- i.e., to specify the root name relative to which all of the child entries are named. I see no need for nested context elements, since subcontexts are created implicitly based on the names of context child elements. - COMPLETED - *Add support for "jndi urls" -- i.e., urls of the form "jndi:global/config/host" or even "jndi:app1/java:comp/env", where the first component of the name following the "jndi:" scheme identifier is the name of a named context. So, "jndi:global/config/host" refers to the entry named by "config/host" in the context named "global" in Context``Bindings. To do this, add a jndi``URLContext``Factory sourcing Selector``JNDIContext instances, where Selector``JNDIContext extends and works like Selector``Context, but overrides get``Bound``Context to locate the bound context by name, rather than calling thread or classloader. - COMPLETED - *Per Roland's suggestion, add a "link" context child element which will insert a link to another named context, with links resolved using {{{(new InitialContext(env)).lookup(link)}}} as Naming``Context does now, but with the name of the other context embedded in the link, as a jndi URL. Then "global naming resources" can be made available using a context named "global" or "root" or whatever the user likes. - *Also per Roland's suggestion, either create a server.xml + web.xml -> naming config converter or support these config formats directly. - - Then to support federation: - - *Allow urls as "base" names in Xml``Configurator context elements and add a "factory" attribute to allow the context factory to be specified/overridden. Then contexts backed by directory servers can be named and accessed via Context``Bindings as above and links can be inserted in in-memory contexts to enable federation between in-memory and ldap-backed naming contexts. Note that this will work for contexts set up using the apis directly, as long as they include the names of external contexts in links. The implicit names used by tomcat will continue to be supported so tomcat's global naming resources links will continue to work. - - == Examples == - - === Single, global in-memory namespace, rooted at "java:comp/env." No difference from current config or behavior === - {{{ - - - - - factory - org.apache.commons.dbcp.BasicDataSourceFactory - - - driverClassName - org.hsqldb.jdbcDriver - - - url - jdbc:hsqldb:target/hsqldb - - - username - sa - - - password - - - - - - - Context ctx = new InitialContext(); - Context env = (Context) ctx.lookup("java:comp/env); - String host = (String) env.lookup("config/host"); - DataSource ds = (DataSource) env.lookup("jdbc/pool");}}} - - === Multiple in-memory contexts, with links === - {{{ - - - - driverClassName - org.hsqldb.jdbcDriver - - - url - jdbc:hsqldb:target/hsqldb - - - username - sa - - - password - - - - - - - - - - - Hashtable env = new Hashtable(); - env.put(NamingContextFactory.NAME, "app1"); - Context ctx = new InitialContext(env); - Context envCtx = (Context) ctx.lookup("java:comp/env"); - Integer port = (Integer) envCtx.lookup("port"); - DataSource ds = (DataSource) envCtx.lookup("datasource"); //follows link }}} - - === Links to remote ldap-backed context inserted into default global in-memory context === - {{{ - - - ... - - - - - - Context ctx = new InitialContext(); - Context env = (Context) ctx.lookup("java:comp/env); - String host = (String) env.lookup("config/host");}}} - or even - - {{{DirContext dirContext = (DirContext) ctx.lookup("config");}}} -