You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by David Blevins <da...@visi.com> on 2008/04/27 20:50:36 UTC

Re: DataSource Injection using Eclipse 3.3.2, Tomcat 6 with embedded OpenEJB (EJB3) To Mysql 5

On Apr 27, 2008, at 10:50 AM, Braam Botes wrote:

> Thank you David,
>
> This will really help. I think that this should be one of the  
> threads on jabble as I searched the web and there is not a lot of  
> info on the embedded openEJB.

Great.  I'm Cc'ing the list so this will get archived.

> I have another question: Why is the datasource set in the  
> openejb.xml in the Tomcat conf dir not loaded into the context, and  
> then just looked up as part of "java:openejb"?
> Should the settings in the openejb.xml not be loaded automatically  
> in the embedded openejb?

My guess is that when you run your unit tests via Eclipse, it starts a  
completely new java vm and runs the tests in it, so it's not picking  
up anything from Tomcat at all (including the embedded OpenEJB).  If  
Eclipse were to run the unit tests against the VM where Tomcat is  
running, then everything in Tomcat would be available to your unit test.

Given that won't run your unit tests in your Tomcat vm, you have two  
choices.

You could have your unit tests connect remotely to Tomcat (w/embedded  
OpenEJB) and lookup the beans via their remote interfaces and test  
them that way. (see the "remote client/tomcat" section for connection  
details http://openejb.apache.org/3.0/clients.html).

Or you could run your unit tests with the EJBs and OpenEJB embedded in  
your test vm, which you are doing now.

> Thank you for the help!

You're welcome!  Hope we can get things working in a way you like.

> Just to bring it to your attention: I did the examle "ejb-examples"  
> and ran the "JNDIDupm" function. The outcome was:
>
> Note the errors. "ERROR: Name server.xml is not bound in this  
> Context" (this could also be documented maybe for the embedded  
> openEJB)

Thanks.  Dain might have some info on what is intended to happen with  
those server.xml links in the context.xml.

-David

>
> env=
>   env/context.xml=
>   env/context.xml/environment=ContextString
>   env/context.xml/resource=[ResourceBean ContextResource]
>   env/context.xml/resource-link=ERROR: Name server.xml is not bound  
> in this Context
>   env/jpa- 
> example 
> =org.apache.openjpa.persistence.EntityManagerFactoryImpl@15b25a1
>   env/org.superbiz.servlet.AnnotatedServlet=
>   env/org.superbiz.servlet.AnnotatedServlet/ 
> ds=org.apache.openejb.resource.jdbc.BasicManagedDataSource@1038b78
>   env/org.superbiz.servlet.AnnotatedServlet/ 
> localEJB 
> = 
> proxy 
> = 
> org.superbiz.servlet.AnnotatedEJBLocal;deployment=AnnotatedEJB;pk=null
>   env/org.superbiz.servlet.AnnotatedServlet/ 
> remoteEJB 
> = 
> proxy 
> = 
> org 
> .superbiz.servlet.AnnotatedEJBRemote;deployment=AnnotatedEJB;pk=null
>   env/org.superbiz.servlet.RunAsServlet=
>   env/org.superbiz.servlet.RunAsServlet/ 
> secureEJBLocal 
> = 
> proxy=org.superbiz.servlet.SecureEJBLocal;deployment=SecureEJB;pk=null
>   env/org.superbiz.servlet.SecureServlet=
>   env/org.superbiz.servlet.SecureServlet/ 
> secureEJBLocal 
> = 
> proxy=org.superbiz.servlet.SecureEJBLocal;deployment=SecureEJB;pk=null
>   env/org.superbiz.servlet.WebserviceServlet=
>   env/org.superbiz.servlet.WebserviceServlet/ 
> helloEjb=org.apache.cxf.jaxws.JaxWsClientProxy@1d1b44b
>   env/org.superbiz.servlet.WebserviceServlet/ 
> helloPojo=org.apache.cxf.jaxws.JaxWsClientProxy@d0726d
>   env/web.xml=
>   env/web.xml/Data  
> Source=org.apache.openejb.resource.jdbc.BasicManagedDataSource@1038b78
>   env/web.xml/ 
> EjbRemote 
> = 
> proxy 
> = 
> org 
> .superbiz.servlet.AnnotatedEJBRemote;deployment=AnnotatedEJB;pk=null
>   env/web.xml/ 
> EjLocal 
> = 
> proxy 
> = 
> org.superbiz.servlet.AnnotatedEJBLocal;deployment=AnnotatedEJB;pk=null
>   env/web.xml/env-entry=WebValue
>   env/web.xml/ 
> PersistenceContext 
> =org.apache.openejb.persistence.JtaEntityManager@1b9a2fd
>   env/web.xml/ 
> PersistenceUnit 
> =org.apache.openjpa.persistence.EntityManagerFactoryImpl@15b25a1
>   env/web.xml/Queue=queue://web.xml/Queue
>   env/web.xml/resource-env-ref=[ResourceBean ContextResourceEnvRef]
>   env/web.xml/resource-link=ERROR: Name server.xml is not bound in  
> this Context
>   env/web.xml/resource-ref=[ResourceBean ContextResourceRef]
>   HandleDelegate=ERROR: No HandleDelegate registered with the  
> OpenEJB system
>   ORB=ERROR: No ORB registered with the OpenEJB system
>
>
>
> On Fri, Apr 25, 2008 at 9:10 PM, David Blevins  
> <da...@visi.com> wrote:
>
> On Apr 25, 2008, at 6:44 AM, botes.braam@gmail.com wrote:
>
> Hallo,
>
> I am using the provided example: "injection-of-datasource"
>
> It works when I use the existing Unit test and replace the driver as  
> follows:
>       Properties p = new Properties();
>       p.put(Context.INITIAL_CONTEXT_FACTORY,  
> "org.apache.openejb.client.LocalInitialContextFactory");
>       p.put("movieDatabase", "new://Resource?type=DataSource");
>       p.put("movieDatabase.JdbcDriver", "com.mysql.jdbc.Driver");
>       p.put("movieDatabase.JdbcUrl", "jdbc:mysql://localhost/test");
>       p.put("movieDatabase.username", "root");
>       p.put("movieDatabase.password", "root");
>
> But when I insert the DataSource into the openejb.xml file in the  
> Tomcat 6/conf dir. The DataSource injection does not work.
>
> [...]
> Unit test code is then changed to:
>       Properties p = new Properties();
>       p.put(Context.INITIAL_CONTEXT_FACTORY,  
> "org.apache.openejb.client.LocalInitialContextFactory");
>
>       Context context = new InitialContext(p);
>
>       Movies movies = (Movies) context.lookup("MoviesLocal");
>
> You can set the location of your Tomcat/conf/openejb.xml if you'd  
> like the unit test to use it.
>
>      Properties p = new Properties();
>      p.put(Context.INITIAL_CONTEXT_FACTORY,  
> "org.apache.openejb.client.LocalInitialContextFactory");
>      p.put("openejb.configuration", "C:\\Work\\Java\\path-to- 
> tomcat-6\\conf\\openejb.xml"
>      Context context = new InitialContext(p);
>
> As a side note if, the two properties above can be set via system  
> properties as well which if you're using Maven can be set in your  
> pom.xml and left out of the test if you like:
>
>  <build>
>    <plugins>
>      <plugin>
>        <groupId>org.apache.maven.plugins</groupId>
>        <artifactId>maven-surefire-plugin</artifactId>
>        <configuration>
>          <systemProperties>
>            <property>
>              <name>java.naming.factory.initial</name>
>               
> <value>org.apache.openejb.client.LocalInitialContextFactory</value>
>            </property>
>            <property>
>              <name>openejb.configuration</name>
>              <value>C:\Work\Java\path-to-tomcat-6\conf\openejb.xml</ 
> value>
>            </property>
>          </systemProperties>
>        </configuration>
>      </plugin>
>    </plugins>
>  </build>
>
> Then your test code would look like this:
>
>      Context context = new InitialContext();
>      Movies movies = (Movies) context.lookup("MoviesLocal");
>
> Some options for you.
>
> -David
>
>