Description
The 'jndi' service provides an "umbrella" API and uniform configuration for any native JNDI implementation.
This service provides implementation for some well-known JNDI usage patterns.
Note that the JNDI kernel service does not implement the JNDI SPI directly but rather provides a vendor-independent
configuration and access API, as well as additional utility methods on top of Context APIs. This, among other things,
greatly benefits code portability with the ability to redeploy code utilizing the 'jndi' service with different
underlying JNDI implementations with no code changes.
Top
Configuration
Configuration of the service is specified in the xtier_jndi.xml xTier configuration file.
This file follows the standard xTier service configuration pattern and is illustrated by the following
complete example of these object definition:
| 1 |  | <xtier-jndi> |
| 2 |  | <region name="examples"> |
| 3 |  | <!-- |
| 4 |  | |
| 5 |  | |
| 6 |  | --> |
| 7 |  | <authoritative>true</authoritative> |
| 8 |  | |
| 9 |  | <!-- |
| 10 |  | |
| 11 |  | |
| 12 |  | --> |
| 13 |  | <batchsize>50</batchsize> |
| 14 |  | |
| 15 |  | <!-- |
| 16 |  | |
| 17 |  | |
| 18 |  | --> |
| 19 |  | <dns-url>dns://somehost/wiz.com</dns-url> |
| 20 |  | |
| 21 |  | <!----> |
| 22 |  | <init-context-factory> |
| 23 |  | com.sun.jndi.rmi.registry.RegistryContextFactory |
| 24 |  | </init-context-factory> |
| 25 |  | |
| 26 |  | <!-- |
| 27 |  | |
| 28 |  | --> |
| 29 |  | <language>en:de:ru</language> |
| 30 |  | |
| 31 |  | <!----> |
| 32 |  | <obj-factories> |
| 33 |  | com.foo.someFactory:com.foo.anotherFactory |
| 34 |  | </obj-factories> |
| 35 |  | |
| 36 |  | <!----> |
| 37 |  | <provider-url>rmi://localhost:1099</provider-url> |
| 38 |  | |
| 39 |  | <!-- |
| 40 |  | |
| 41 |  | |
| 42 |  | --> |
| 43 |  | <referral>follow</referral> |
| 44 |  | |
| 45 |  | <!-- |
| 46 |  | |
| 47 |  | |
| 48 |  | --> |
| 49 |  | <authentication>simple</authentication> |
| 50 |  | |
| 51 |  | <!-- |
| 52 |  | |
| 53 |  | |
| 54 |  | |
| 55 |  | --> |
| 56 |  | <credentials>777</credentials> |
| 57 |  | |
| 58 |  | <!----> |
| 59 |  | <protocol>ssl</protocol> |
| 60 |  | |
| 61 |  | <!-- |
| 62 |  | |
| 63 |  | --> |
| 64 |  | <factories>com.foo.stateFactory</factories> |
| 65 |  | |
| 66 |  | <!-- |
| 67 |  | |
| 68 |  | |
| 69 |  | --> |
| 70 |  | <url-pkg-prefixes>com.foo</url-pkg-prefixes> |
| 71 |  | </region> |
| 72 |  | </xtier-jndi> |
Formal specification for this configuration file can be found in the xtier_jndi.dtd DTD file in
the ${XTIER_ROOT}/config/dtd folder. The following table provides explanations for the configuration elements:
| authentication |
Corresponds to Context.SECURITY_AUTHENTICATION. |
| authoritative |
Corresponds to Context.AUTHORITATIVE. |
| batchsize |
Corresponds to Context.BATCHSIZE. |
| credentials |
Corresponds to Context.SECURITY_PRINCIPAL. |
| dns-url |
Corresponds to Context.DNS_URL. |
| factories |
Corresponds to Context.STATE_FACTORIES. |
| init-context-factory |
Corresponds to Context.INITIAL_CONTEXT_FACTORY. |
| language |
Corresponds to Context.LANGUAGE. |
| obj-factories |
Corresponds to Context.OBJECT_FACTORIES. |
| protocol |
Corresponds to Context.SECURITY_PROTOCOL. |
| provider-url |
Corresponds to Context.PROVIDER_URL. |
| referral |
Corresponds to Context.REFERRAL. |
| url-pkg-prefixes |
Corresponds to Context.URL_PKG_PREFIXES. |
Top
Examples
The usage of the 'jndi' service follows the standard pattern of using an xTier service:
you need to obtain an instance of the xTier kernel that serves as a service registry.
Once you have the xTier kernel you can get an instance of any service, in our case the 'jndi' service.
| 1 |  | |
| 2 |  | XtierKernel xtier = XtierKernel.getInstance(); |
| 3 |  | |
| 4 |  | |
| 5 |  | JndiService jndi = xtier.jndi(); |
| 6 |  | |
| 7 |  | InitialContext ctx = jndi.getInitialContext(); |
| 8 |  | |
| 9 |  | Hashtable env = ctx.getEnvironment(); |
| 10 |  | |
| 11 |  | |
| 12 |  | for (Enumeration enum = env.keys(); enum.hasMoreElements() == true;) { |
| 13 |  | Object key = enum.nextElement(); |
| 14 |  | |
| 15 |  | System.out.println(key + " = " + env.get(key)); |
| 16 |  | } |
| 17 |  | |
| 18 |  | try { |
| 19 |  | jndi.bindEx(JNDI_NAME, new RefObj(), true); |
| 20 |  | |
| 21 |  | jndi.unbindEx(JNDI_NAME); |
| 22 |  | } |
| 23 |  | catch (NamingException e) { |
| 24 |  | |
| 25 |  | } |
| 26 |  | |
| 27 |  | |
| 28 |  | xtier.stop(); |
Note also that every utility method comes in four versions:
- Method that takes Context and JNDI name as a String
- Method that does not take Context and takes JNDI name as a String
- Method that takes Context and JNDI name as a Name
- Method that does not take Context and takes JNDI name as a Name
Download xTier for full examples and documentation.
Top
|