16

I have the following...

Context aContext = = new InitialContext(settings);
aContext.lookup("java:comp/env/DB2_DB");

Also tried...

aContext.lookup("DB2_DB");

web.xml

<resource-ref>
    <description>
    </description>
    <res-ref-name>DB2_DB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Application</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
    <mapped-name>DB2_DB</mapped-name>
</resource-ref>

then in my ibm-web-bnd.xml...

<resource-ref name="DB2_DB" binding-name="jdbc/DB2DB" />

In Websphere I see the binding name in resources>JDBC>Data Sources

But when I run my application I see...

Caused by: javax.naming.NameNotFoundException: Context: Node04Cell/nodes/Node04/servers/server1, name: DB2_DB: First component in name DB2_DB not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]^M

This is a port project from WAS6-8.5

Jackie
  • 21,969
  • 32
  • 147
  • 289

3 Answers3

17

Well, this question is quite old, and I see that there's no accepted answer yet, so.

Here is what really happens:

  1. Your code executes a JNDI lookup to java:comp/env/DB2_DB.
  2. WebSphere uses the WAS-proprietary deployment descriptor (ibm-web-bnd.xml) to "translate" the application binding DB2_DB into a real name in the WebSphere JNDI tree (jdbc/DB2DB).
  3. WebSphere looks up jdbc/DB2DB and returning it to the caller.

You are getting a NameNotFoundException on the first lookup - the lookup of java:comp/env/DB2_DB. The problem is not with finding jdbc/DB2DB; it's with finding DB2_DB inside your component's environment.

Your deployment descriptor looks OK to me, so I'm guessing that the reason for your problem is this:

Context aContext = new InitialContext(settings);

You are constructing an InitialContext instance by providing a Hashtable. The Hashtable is often useful when you need to provide special parameters for the construction, but you must know when to use it and when to avoid it. Code that runs inside a JavaEE container and needs simple access to the container's JNDI tree rarely, if ever, should provide any Hashtable to the InitialContext constructor.

I wouldn't be surprised if those settings that you're passing into InitialContext contain, for example, a PROVIDER_URL key instructing the lookup to happen on some distant foreign JNDI tree.

So, I would start by scrapping that parameter:

Context aContext = new InitialContext();

And then give it another shot.

If that still fails, use WebSphere's dumpNamespace utility to get a clear picture of WebSphere's JNDI tree.

Isaac
  • 16,458
  • 5
  • 57
  • 81
0

I'm not sure what the ibm-web-bnd.xml does, however you could try two things.

First you can try doing a global lookup. Try:

aContext.lookup("jdbc/DB2DB");

I assume the datasource is named "jdbc/DB2DB" withing the datasource configuration.

Otherwise you should check if the datasource is mapped in your application. I guess the ibm-web-bnd.xml should when set up properly do that mapping.

Community
  • 1
  • 1
Udo Held
  • 12,314
  • 11
  • 67
  • 93
  • ibm-web-bnd.xml is a mapping from a local resource name to a JNDI reference within the container. – Jackie Apr 13 '13 at 17:51
0

Dump the namespace and find the jndi under target you want to find. If it is not found, update corbaloc URL to the one as given in the target. Because the look up was working in my local but not working in a clustered environment. I dumped the namespace and identified the corbaloc URL. Then used that corbaloc URL in the SIT environment.

Example: JMS_HOST was corbaloc::localhost:2809/NameServiceServerRoot in local but in clustered enviroment it was JMS_HOST=corbaloc::ABC-DEF-XYZ:9810/NameServiceServerRoot

This solved my issue.

Kuppusamy
  • 65
  • 1
  • 6