Jndi Lookups
Jndi Lookups
Jndi Lookups
A developer has a choice of two types of lookups (direct and indirect) for
obtaining a J2C connection factory or a JDBC datasource when there is a need
to access an Enterprise Information System (EIS) resource such as CICS, IMS,
or DB2.
The first type uses a specific JNDI name in the context lookup and is called a
“direct lookup”. This type of lookup will obtain a connection factory or datasource
if and only if a factory or datasource with that JNDI name already exists in the
WebSphere configuration. A direct lookup is ok for development and unit testing
but is not appropriate for production. The primary reason is that when the
application is installed in a production environment, the JNDI name used by the
developer is not exposed during the deployment process. The application
Deployer is not able to select which connection factory or datasource in the
production environment is to be used and the WebSphere Administrator must
ensure a resource with the JNDI name specified by the developer is defined to
enable the application to run. Both of these issues are highly problematic in a
production environment.
To give the application’s Deployer the ability to select which connection factory or
datasource is to be used by the application, the developer needs to use an
“indirect lookup” in the context lookup. An indirect lookup is specified by using
the string “java:comp/env” as a prefix for the resource name (which is not
necessarily the same as the JNDI name), for an example see Figure 1 –
Resource Reference in a Deployment Descriptor. When the developer uses this
prefix, a context lookup will look for a resource reference with that name in the
global name space. The resource reference information provides the JNDI name
of the connection factory or datasource (as well as other connection parameters
such as Authentication type and Sharing scope). In a test environment the JNDI
name provided in the resource reference will be used to locate a connection
factory or datasource in the test environment’s WebSphere configuration (see
Figure 2 - J2C Connection Factory). In a production environment the presence
of a resource reference in the EAR allows the Deployer to specify which resource
is to be used, (see Figure 3 Mapping Resource References During Deployment)
and the relationship between the resource reference and the JNDI name
specified by the Deployer maintained in the name space.
Not only is the use of an indirect lookup recommended because of being a best
practice since it gives more control over connection management properties
(authentication and sharing scope) specified in a resource reference and allows
the Deployer to select which J2C connection factory is to be used, it is
recommended because the usage of direct lookups for J2C connection factories
has been deprecated in Version 6 of WebSphere (see Scenario 5).
© 2006, IBM Advanced Technical Support Techdocs - Washington Systems Center Version 1/15/2006
http://www.ibm.com/support/Techdocs
TD102945 Using JNDI Lookups of J2C Connection Factories and JDBC Datasources in WebSphere Applications Page 1 of 8
Using JNDI Lookups of J2C Connection Factories and
JDBC Datasources in WebSphere Applications
+
In this example the developer uses the resource reference name of ‘IMS’ to
obtain an IMS J2C connection factory in an indirect lookup.
Also please note that the concepts described here also apply to obtaining CICS
J2C connection factories as well as JDBC datasources.
© 2006, IBM Advanced Technical Support Techdocs - Washington Systems Center Version 1/15/2006
http://www.ibm.com/support/Techdocs
TD102945 Using JNDI Lookups of J2C Connection Factories and JDBC Datasources in WebSphere Applications Page 2 of 8
Using JNDI Lookups of J2C Connection Factories and
JDBC Datasources in WebSphere Applications
© 2006, IBM Advanced Technical Support Techdocs - Washington Systems Center Version 1/15/2006
http://www.ibm.com/support/Techdocs
TD102945 Using JNDI Lookups of J2C Connection Factories and JDBC Datasources in WebSphere Applications Page 3 of 8
Using JNDI Lookups of J2C Connection Factories and
JDBC Datasources in WebSphere Applications
The Deployer has selected a J2C connection factory with a JNDI name of
eis/IMSLocal rather than the original resource reference JNDI name of
eis/IMSRemote for any resource references to IMS.
Note to EGL developers, the EGL location property in the callLink member provides
the J2C connection factory lookup string when remoteComType is set to CICSJ2C.
© 2006, IBM Advanced Technical Support Techdocs - Washington Systems Center Version 1/15/2006
http://www.ibm.com/support/Techdocs
TD102945 Using JNDI Lookups of J2C Connection Factories and JDBC Datasources in WebSphere Applications Page 4 of 8
Using JNDI Lookups of J2C Connection Factories and
JDBC Datasources in WebSphere Applications
Now lets look at various scenarios and see how this actually works using
Rational Application Developer test environment when accessing IMS.
The indirect lookup of IMS locates a resource reference by this name (see Figure
1 – Resource Reference in Deployment Descriptor). The resource reference has
a JNDI Name of eis/IMSRemote. The J2C connection factory IMSRemote has
a matching JNDI name (see Figure 2 - J2C Connection Factory) and this
connection factory is used to successfully access IMS
This scenario demonstrates what happens when using an indirect lookup without
having a resource reference with that name in the deployment descriptor.
javax.resource.cci.ConnectionFactory cf =
(ConnectionFactory)ctx.lookup("java:comp/env/myIMS");
The indirect lookup of myIMS for a resource reference by this name fails with a
NameNotFoundException exception since there is no resource reference with
this name in the deployment descriptor (see messages below)
© 2006, IBM Advanced Technical Support Techdocs - Washington Systems Center Version 1/15/2006
http://www.ibm.com/support/Techdocs
TD102945 Using JNDI Lookups of J2C Connection Factories and JDBC Datasources in WebSphere Applications Page 5 of 8
Using JNDI Lookups of J2C Connection Factories and
JDBC Datasources in WebSphere Applications
Scenario 3: Indirect Lookup-Resource-Ref with an invalid JNDI Name
Now lets assume the EAR has a resource reference as configured in Figure 1 but
that a J2C connection with a JNDI name of eis/IMSRemote does not exist in the
WebSphere configuration.
javax.resource.cci.ConnectionFactory cf =
(ConnectionFactory)ctx.lookup("java:comp/env/IMS");
NMSV0605W: A Reference object looked up from the context "java:" with the name
"comp/env/IMS" was sent to the JNDI Naming Manager and an exception resulted.
Reference data follows:
Reference Factory Class Name: com.ibm.ws.util.ResRefJndiLookupObjectFactory
Reference Factory Class Location URLs: <null>
Reference Class Name: java.lang.Object
Type: ResRefJndiLookupInfo
Content: com.ibm.ws.util.ResRefJndiLookupInfo@77039111 ResRefJndiLookupInfo: Look
up Name="IMS";JndiLookupInfo: jndiName="eis/IMSRemote"; providerURL="";
initialContextFactory=""
© 2006, IBM Advanced Technical Support Techdocs - Washington Systems Center Version 1/15/2006
http://www.ibm.com/support/Techdocs
TD102945 Using JNDI Lookups of J2C Connection Factories and JDBC Datasources in WebSphere Applications Page 6 of 8
Using JNDI Lookups of J2C Connection Factories and
JDBC Datasources in WebSphere Applications
Scenario 4: Direct Lookup-No JNDI name match with a J2C CF
In this scenario the developer does a direct lookup when there is no J2C
connection factory with this JNDI name in the WebSphere configuration.
javax.resource.cci.ConnectionFactory cf =
(ConnectionFactory)ctx.lookup("eis/IMSRemote");
javax.naming.NameNotFoundException: Context:
rigelNode01Cell/nodes/rigelNode01/servers/server1, name: eis/IMSRemote: First
component in name IMSRemote not found. Root exception is
org.omg.CosNaming.NamingContextPackage.NotFound:
IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
In this scenario the developer does a direct lookup. There is a J2C connection
factory with this JNDI name in the WebSphere configuration.
javax.resource.cci.ConnectionFactory cf =
(ConnectionFactory)ctx.lookup("eis/IMSRemote");
© 2006, IBM Advanced Technical Support Techdocs - Washington Systems Center Version 1/15/2006
http://www.ibm.com/support/Techdocs
TD102945 Using JNDI Lookups of J2C Connection Factories and JDBC Datasources in WebSphere Applications Page 7 of 8
Using JNDI Lookups of J2C Connection Factories and
JDBC Datasources in WebSphere Applications
J2CA0294W: Deprecated usage of direct JNDI lookup of resource
eis/IMSRemote. The following default values are used: [Resource-ref
settings]
res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
loginConfigurationName: null
loginConfigProperties: null
[Other attributes]
Summary
© 2006, IBM Advanced Technical Support Techdocs - Washington Systems Center Version 1/15/2006
http://www.ibm.com/support/Techdocs
TD102945 Using JNDI Lookups of J2C Connection Factories and JDBC Datasources in WebSphere Applications Page 8 of 8