tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Karalus <andreas.kara...@googlemail.com>
Subject Re: Configure datasource to work with JBoss style lookups?
Date Thu, 02 Oct 2008 14:37:23 GMT

I already had the same issue discussed here:
http://www.nabble.com/Bind-Datasource-to-specific-jndi-name-td19391707.html

I haven't found a really "sexy" solution at this time, my workarounds are
using a ServiceLocator to do the lookups. I have to change all of my code,
replacing InitialContext.lookup(..) with ServiceLocator.lookup(..)  

The service locator decides if it should do the lookups openejb or jboss
style by inspecting the system property java.naming.factory.initial. 

@OpenEJB developer
Maybe this could be a feature request? Shuld I raise a JIRA issue on it? 
Especially: java:/TransactionManager, java:/MyDataSource,
java:/UserTransaction

regards,
andreas



Mangan wrote:
> 
> Hi!
> 
> I recentally started using OpenEJB for doing unit testing with JUnit. I've
> got it to work for everything I've tried so far but now I've run into some
> problems: 
> 
> When trying to unit test a method, that in a lower layer uses a database
> connection, I get an error. 
> 
> java.lang.NoClassDefFoundError: org/jnp/server/NamingServer
> 	at
> org.jboss.naming.java.javaURLContextFactory.<clinit>(javaURLContextFactory.java:52)
> 	at java.lang.Class.forName0(Native Method)
> 	at java.lang.Class.forName(Class.java:242)
> 	at
> com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:50)
> 	at
> com.sun.naming.internal.ResourceManager.getFactory(ResourceManager.java:371)
> 	at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:575)
> 	at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:533)
> 	at
> javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:279)
> 	at javax.naming.InitialContext.lookup(InitialContext.java:351)
> 	at se.ports.dev.utils.Utils.getConnection(Utils.java:118)
> 	at
> se.ports.dev.domainprocess.common.utils.DPUtils.getRegapp4Zones(DPUtils.java:147) 
> <<-- Here is the call to the database
> 	at
> se.ports.dev.domainprocess.ownertransfer.complete.EppOwnerTransferCompleteHandler.handlesOrder(EppOwnerTransferCompleteHandler.java:39)
> 	at
> test.se.ports.dev.domainprocess.ownertransfer.complete.OwnerTransferCompleteTest.testEppHandler(OwnerTransferCompleteTest.java:92)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> 	at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> 	at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> 	at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> 	at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> 	at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> 	at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
> 	at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
> 	at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
> 	at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> 	at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> 	at com.intellij.rt.junit4.Junit4ClassSuite.run(Junit4ClassSuite.java:99)
> 	at
> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
> 
> Code for lookup:
> try{
> 	InitialContext ctx = new InitialContext();
> 	DataSource ds = (DataSource) ctx.lookup( "java:/MyDataSource");
> 	return ds.getConnection();
> }
> // If we arn't in a JBoss context, 
> catch ( NamingException ne){
> 	throw new RuntimeException("NamingException while getting a JDBC
> connection");
> }
> 
> This does not suprise me because I've read some posts about problems when
> using a JBoss-style lookup on datasources ("java:/DataSourceName"). In my
> inital tests I've got the datasource configured in the open-ejb.xml and
> the connection to work via annotations. So I know my datasource works. I
> would gladly change my datasource lookups in the future when using JBoss
> (if it's possible) but the projekt I'm working on now is huge so that's
> not really an option.
> 
> Is there some way to setup the datasource to be able to use JBoss-style
> lookups?
> 
> Or, am I mistaken in my assumption that this have anything to do with the
> datasource lookup?
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Configure-datasource-to-work-with-JBoss-style-lookups--tp19720947p19780578.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Mime
View raw message