Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Gemini/Naming/Documentation/JNDI Clients"

(JNDI Clients)
(JNDI Clients)
Line 3: Line 3:
 
A JNDI Client, in the context of Gemini Naming, is usually a piece of code that consumes JNDI services.  This can typically take one of two forms:
 
A JNDI Client, in the context of Gemini Naming, is usually a piece of code that consumes JNDI services.  This can typically take one of two forms:
  
#JNDI Services - A JNDI Client can use the services defined in the "JNDI Services" Chapter of the OSGi Enterprise Specification, v4.2, in order to obtain JNDI providers.  
+
*'''JNDI Services''' - A JNDI Client can use the services defined in the "JNDI Services" Chapter of the OSGi Enterprise Specification, v4.2, in order to obtain JNDI providers.  
  
 
The following is an example of a JNDI Services client using the JNDIContextManager service to create a JNDI Context instance:
 
The following is an example of a JNDI Services client using the JNDIContextManager service to create a JNDI Context instance:
Line 20: Line 20:
 
</pre>
 
</pre>
  
#"Traditional" JNDI Access - A JNDI Client can use the javax.naming.InitialContext() constructor in order to gain access to the naming service.  These clients typically follow the pattern of Java EE clients that create an InitialContext, and use that instance to interact with the naming system.
+
*'''"Traditional" JNDI Access''' - A JNDI Client can use the javax.naming.InitialContext() constructor in order to gain access to the naming service.  These clients typically follow the pattern of Java EE clients that create an InitialContext, and use that instance to interact with the naming system.
  
  

Revision as of 13:12, 23 November 2011

JNDI Clients

A JNDI Client, in the context of Gemini Naming, is usually a piece of code that consumes JNDI services. This can typically take one of two forms:

  • JNDI Services - A JNDI Client can use the services defined in the "JNDI Services" Chapter of the OSGi Enterprise Specification, v4.2, in order to obtain JNDI providers.

The following is an example of a JNDI Services client using the JNDIContextManager service to create a JNDI Context instance:

    // obtain JNDIContextManager service
    ServiceReference serviceReference = 
	bundleContext.getServiceReference("org.osgi.service.jndi.JNDIContextManager");
    JNDIContextManager contextManager = (JNDIContextManager)
        getContext().getService(serviceReference);
		
    // create a context with the default environment setup
    Context initialContext = contextManager.newInitialContext();

    // JNDI Client can now access the naming system with the Context instance...
  • "Traditional" JNDI Access - A JNDI Client can use the javax.naming.InitialContext() constructor in order to gain access to the naming service. These clients typically follow the pattern of Java EE clients that create an InitialContext, and use that instance to interact with the naming system.


The following is an example of a JNDI Client that uses the standard JNDI API in order to create the javax.naming.InitialContext instance used to interact with the naming system:

    Hashtable environment = new Hashtable();
    environment.put(Context.INITIAL_CONTEXT_FACTORY, 
		    "com.sun.jndi.rmi.registry.RegistryContextFactory");
    environment.put("osgi.service.jndi.bundleContext", bundleContext);
		
    // verify that context can be created without any errors
    Context context = null;
    try {
        context = new InitialContext(environment);
  
        // JNDI Client can now access the naming system with the Context instance...
    } finally {
        context.close();
    }

Back to the top