JNDI Naming
1 Prerequisites
We need to configure JNDI environment properties and Reference binding with the eXo container standard mechanism.
The Naming service covers:
- Configuring the current Naming Context Factory implemented as an ExoContainer Component org.exoplatform.services.naming.InitialContextInitializer.
- Binding Objects (References) to the current Context using org.exoplatform.services.naming.BindReferencePlugin component plugin.
2 How it works
Make sure you understand the
Java Naming and Directory InterfaceTM (JNDI) concepts before using this service.
2.1 JNDI System property initialization
After the start time the Context Initializer (
org.exoplatform.services.naming.InitialContextInitializer) traverses all initial parameters (that concern the Naming Context) configured in
default-properties and
mandatory-properties (see Configuration examples) and:
- for default-properties checks if this property is already set as a System property (System.getProperty(name)) and sets this property if it's not found. Using those properties is recommended with a third party Naming service provider.
- for mandatory-properties it just sets the property without checking
Standard JNDI properties:
- java.naming.factory.initial
- java.naming.provider.url
and others (see JNDI docs)
2.2 JNDI reference binding
Another responsibility of Context Initializer (
org.exoplatform.services.naming.InitialContextInitializer) is binding of preconfigured references to the naming context. For this purpose it uses a standard eXo component plugin mechanism and in particular the
org.exoplatform.services.naming.BindReferencePlugin component plugin. The configuration of this plugin includes three mandatory value parameters:
- bind-name - the name of binding reference
- class-name - the type of binding reference
- factory - the object factory type
And also
ref-addresses property parameter with a set of references' properties.
(see Configuration examples)
Context Initializer uses those parameters to bind the neccessary reference automatically.
3 Configuration examples
The InitialContextInitializer configuration example:
<component>
<type>org.exoplatform.services.naming.InitialContextInitializer</type>
<init-params>
<properties-param>
<name>default-properties</name>
<description>Default initial context properties</description>
<property name="java.naming.factory.initial" value="org.exoplatform.services.naming.SimpleContextFactory"/>
</properties-param>
<properties-param>
<name>mandatory-properties</name>
<description>Mandatory initial context properties</description>
<property name="java.naming.provider.url" value="rmi://localhost:9999"/>
</properties-param>
</init-params>
</component>
The BindReferencePlugin component plugin configuration example (for JDBC datasource):
<component-plugins>
<component-plugin>
<name>bind.datasource</name>
<set-method>addPlugin</set-method>
<type>org.exoplatform.services.naming.BindReferencePlugin</type>
<init-params>
<value-param>
<name>bind-name</name>
<value>jdbcjcr</value>
</value-param>
<value-param>
<name>class-name</name>
<value>javax.sql.DataSource</value>
</value-param>
<value-param>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</value-param>
<properties-param>
<name>ref-addresses</name>
<description>ref-addresses</description>
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:file:target/temp/data/portal"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</properties-param>
</init-params>
</component-plugin>
4 Recommendations for Application Developers
- SimpleContextFactory is created for testing purposes only, do not use it for production.
- In J2EE environment use Naming Factory objects provided with the Application Server.