• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access DataSource from stand alone Client

 
smitha rai
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gurus,

I have configured the datasource on WebSphere v5.0 Test Environment and trying to access it from the stand alone client (say, a JUnit test class) in a java project. When I execute the test class, I get the following error.

Appreciate your help and suggestions.

Smitha
==========================================================================
javax.naming.CommunicationException: A communication failure occurred while attempting to obtain an initial context with the provider URL: "iiop://localhost:2809". Make sure that any bootstrap address information in the URL is correct and that the target name server is running. A bootstrap address with no port specification defaults to port 2809. Possible causes other than an incorrect bootstrap address or unavailable name server include the network environment and workstation network configuration. Root exception is org.omg.CORBA.COMM_FAILURE: WRITE_ERROR_SEND_1 minor code: 49421050 completed: No
at com.ibm.ws.orbimpl.transport.HTTPOutputStream.write(Unknown Source)
at com.ibm.rmi.iiop.IIOPOutputStream.writeTo(IIOPOutputStream.java:283)
at com.ibm.rmi.iiop.Connection.send(Connection.java:1485)
at com.ibm.rmi.iiop.Connection._locate(Connection.java:265)
at com.ibm.rmi.iiop.Connection.locate(Connection.java:244)
at com.ibm.rmi.iiop.GIOPImpl.locate(GIOPImpl.java:184)
at com.ibm.rmi.corba.Corbaloc.locateUsingINS(Corbaloc.java:305)
at com.ibm.rmi.corba.Corbaloc.resolve(Corbaloc.java:367)
at com.ibm.rmi.corba.ORB.string_to_object(ORB.java:2941)
at com.ibm.ws.naming.util.WsnInitCtxFactory.stringToObject(WsnInitCtxFactory.java:1256)
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1107)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:679)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:607)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:482)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:112)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:422)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:143)
at javax.naming.InitialContext.lookup(InitialContext.java:359)
at org.kp.sql.helper.DataSourceUtil.initializeDataSource(DataSourceUtil.java:90)
at org.kp.sql.helper.DataSourceUtil.getDataSource(DataSourceUtil.java:61)
at org.kp.sql.helper.CommonDAO.retrieveListFromDB(CommonDAO.java:79)
at org.kp.message.dao.impl.MessageDAOImpl.retrieveMessage(MessageDAOImpl.java:89)
at org.kp.message.service.impl.MessageServiceImpl.retrieveMessages(MessageServiceImpl.java:258)
at org.kp.message.service.impl.MessageServiceImpl.findMessage(MessageServiceImpl.java:65)
at org.kp.message.util.MessageServiceUtil.getMessage(MessageServiceUtil.java:72)
at org.kp.message.test.TestMessageManager.main(TestMessageManager.java:10)
Exception in thread "P=801061 =0:CT"
===========================================================================

The following jars added in the classpath for the java project.
--------------------------------------------------------------
1. ivjejb35.jar
2. j2cImpl.jar
3. j2ee.jar
4. naming.jar
5. namingclient.jar
6. webcontainer.jar
7. j2c.properties
8. implfactory.properties

Following is the code I am using to get the DataSource:

private DataSource getDataSource(String jndiName) throws NamingException{
DataSource ds = null;
InitialContext context = null;
try {
Properties prop = new Properties();
prop.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
prop.put(javax.naming.Context.PROVIDER_URL, "iiop://localhost:2908");
context = new InitialContext(prop);
ds = (DataSource) javax.rmi.PortableRemoteObject.narrow(
context.lookup(jndiName),
DataSource.class);
} catch (ClassCastException ne) {
//Handle exception
}
return ds;
}
 
Ratan Kumar
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have access to the database?are you able to ping the database server?
 
smitha rai
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ratan,

Yes, I can access to the database. The database server is fine.

Smitha
 
Vijay Rmk
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The suggestions that i am giving , may be you would have already tried ...but if i were in your condition i would have tried it this way...

1.Try getting connection to db using driver manager from your standalone to make sure your business works
2) check the jdbc connection in webspehere admin console and make sure test connection works fine.
3)verify the bootstrap address of server.you can even try changing the 'local host to local ip address' - ideally shouldnt make a diff ,but at times it has worked with me ....
Error clearly states that it is not able to locate your server.Check wht kinda driver prop you have set in jdbc properties....
 
smitha rai
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vijay,

Yes, I could be able to establish the connection using the driver manager ang get the results.

No luck yet.

Smitha
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how to help you connect to JNDI from your stand-alone application, but here's how I do my JUnit Tests:

I have a single helper class with a getConnection method that is used for all data access. This class looks at the system parameter "mycompany.test", and if it's present, it gets the connection using the DriverManager. Otherwise, it gets the connection normally from the JNDI datasource.

Then, in my JUNIT tests, I make sure to set the "mycompany.test" system parameter in the setUp method.
 
smitha rai
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now the javax.naming.CommunicationException exception is gone when I add classes12.jar to the classpath. The new exception I see as below:

java.lang.NoClassDefFoundError: com/ibm/db2/jcc/DB2Wrapper
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:703)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:133)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:320)
at java.net.URLClassLoader.access$400(URLClassLoader.java:93)
at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:239)
at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code))
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:460)
at java.lang.ClassLoader.loadClass(ClassLoader.java:448)
at com.ibm.ws.rsadapter.ObjectCache.<init>(ObjectCache.java:58)
at com.ibm.ws.rsadapter.ObjectCache.<clinit>(ObjectCache.java:53)
at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.<clinit>(WSRdbManagedConnectionImpl.java:291)
at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.createManagedConnection(WSManagedConnectionFactoryImpl.java:532)
at com.ibm.ejs.j2c.poolmanager.FreePool.createManagedConnectionWithMCWrapper(FreePool.java:1226)
at com.ibm.ejs.j2c.poolmanager.FreePool.createOrWaitForConnection(FreePool.java:1032)
at com.ibm.ejs.j2c.poolmanager.PoolManager.reserve(PoolManager.java:1680)
at com.ibm.ejs.j2c.ConnectionManager.allocateMCWrapper(ConnectionManager.java:665)
at com.ibm.ejs.j2c.ConnectionManager.allocateConnection(ConnectionManager.java:453)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:215)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:190)

Any suggestions greatly appreciated.
 
Ratan Kumar
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your current error condition clearly says its a classpath(jar file) problem.

If you database is DB2 , try using db2jcc.jar
This jar file has the particular class which you are missing right now..
DB2Wrapper.class
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Smitha,
I would approach this differently depending on whether the test code or the code under test was trying to access the datasource. If it was just the test code, I would do what Merrill suggested.

When the code under test needs to access a datasource, I want it to use the real datasource. Since I am integration testing, I don't want to change the environment. The solution we have been using in WSAD5/RAD6 is to create an application client project and then run the test as an application client. This approach allows it access to the main JNDI including datasources and EJBs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic