• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reference lookup problem

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a web module which uses a jar file added in Web-INF/lib folder. This jar file has a utility class written by us, which is used by our application to get DB connection.
This class is a simple one which does a lookup for the datasource, fetches the connection and returns it to the caller for use.
Everything works fine, except that we are getting following 'Informational' message in Websphere SystemOut.log file :
J2CA0122I: Resource reference jdbc/DSPPP could not be located, so default values of the following are used: [Resource-ref settings]

res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
res-resolution-control: 999 (undefined)

I read in lot of articles (thanks to you guys) that a local reference should be used instead of directly looking up for the datasource name. So i followed this:
1. Created a Resouce Reference (datasource) in web.xml pointing to the JNDI Name : jdbc/DSPPP (jndi name of the datasource).
2. Used this Resource reference in the code to do lookup :
Properties p = new Properties();
//get local jndicontext
p.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory" );
p.put("com.ibm.websphere.naming.jndicache.cacheobject", "none");
javax.naming.Context jndiContext = new InitialContext(p);
DataSource ds = (DataSource) jndiContext .lookup ("java:comp/env/datasource");
Connection con = ds.getConnection();

The above code is in the Utility class i mentioned above, which is packaged in Jar and put under Web-INF/lib folder of web module.

Problem is : Seems like local reference created in web module is not visible to this utility jar. We get following error :
method.javax.naming.NameNotFoundException: Name "comp/env/datasource" not found in context "java:".

PS : If i put the above code in one of the class, directly under javasource of web module or in the JSP, it works beautifully, without logging the annoying Informational message.

So is there anybody who can give me some pointers about :
1. What is the way to access reference created in web.xml in the utility class added as a jar in web module?
2. Is there any other way of coding to get rid of this message?
3. if nothing works, is there any setting in Websphere server, tweaking which we can supress the 'informational messages' in log files.

thanks a bunch.
Shikhar
 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you are doing(your utility jar) is creating a thiing (data resource) which is already provided by your J2EE server.

Follow your WebSphere server documentation or WSAD help in the data source section.
 
shikhar singh
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response Edy,
My main aim is to remove the Information messages getting logged in the log files as mentioned in my original message.

As per my understanding the utility jar is not creating a datasource but instead using the Name Space Binding to get the reference to the Datasource created by J2ee Server, to create the DB connection. may be i am wrong in my understanding.

It works perfectly, If I do a direct lookup for the Datasource. But that results in the following informational message:
J2CA0122I: Resource reference jdbc/DSPPP could not be located, so default values of the following are used: [Resource-ref settings]

res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
res-resolution-control: 999 (undefined)

I read a lot about this topic to resolve this issue. IBM docs says that depending on the place where Datasource need to be used, local resource reference should be created (in web.xml or ejb deployment descriptor)and binded to the actual datasource JNDI name.
This approach will remove the above annoying messages.

I did the same thing only to find that this approach does not work if the class performing the datasource lookup is in a jar under WEB-INF/lib. in another words the local resource refernce seem to be not visible to this class.

It will be very helpful if somebody can answer atleast one of the following question:
1. How to do the lookup to the local reference created in web module from a class which is in a Jar under Web-INF/lib?
2. How to configure the websphere server to supress the informational messages in the Log file.

Thanks a lot.
shikhar
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I have the same problem. Can any one explain ?
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic