You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by amber <am...@hotmail.fr> on 2013/10/29 15:56:11 UTC
resource-ref settings within openEJB
Hi,
I got a external resource (string to define a path); All work fine for my
project (@resource injection) and the resource is declared into the
ejb-jar.xml :
<resource-ref>
<res-ref-name>thepath</res-ref-name>
<res-type>java.lang.String</res-type>
</resource-ref>
Resource value is set into server configuration. Nice.
But my junit test won't work because openEjb just can't find the resource's
value... How can I set it from openEJB (embeded or openejb.xml) and how ?
thx!
--
View this message in context: http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: resource-ref settings within openEJB
Posted by Romain Manni-Bucau <rm...@gmail.com>.
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
<enterprise-beans>
<session>
<ejb-name>Course</ejb-name>
<env-entry>
<env-entry-name>thepath</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>mytestpath</env-entry-value>
</env-entry>
</session>
</enterprise-beans>
</ejb-jar>
works,
about the resource not sure it would work for string but in unit test
you can configure it through properties (new://Resource?....) - common
for datasources for instance
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2013/10/30 amber <am...@hotmail.fr>:
> Here the sample cdi-basic modified like I do for my project :
> - adding cdi-basic\src\main\resources\META-INF\ejb-jar.xml with resource-ref
> declaration
> - adding cdi-basic\src\test\resources\META-INF\ejb-jar.xml with env-entry
> declaration
>
> same error
>
> thx to point me on my mistake :)
>
>
> cdi-basic-resource-ref-err.zip
> <http://openejb.979440.n4.nabble.com/file/n4665814/cdi-basic-resource-ref-err.zip>
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781p4665814.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: resource-ref settings within openEJB
Posted by amber <am...@hotmail.fr>.
I found the right way to do :
- p.setProperty("openejb.altdd.prefix", "test-")
- rename the ejb-jar.xml (the one with env-entry located in /src/test/...)
to test-ejb-jar.xml and move it to \src\main\resources\META-INF\
Why openEJB can't find the file from src/test/.. ?
(I remember doing the same thing for persistence.xml file)
thx
--
View this message in context: http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781p4665817.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: resource-ref settings within openEJB
Posted by amber <am...@hotmail.fr>.
Here the sample cdi-basic modified like I do for my project :
- adding cdi-basic\src\main\resources\META-INF\ejb-jar.xml with resource-ref
declaration
- adding cdi-basic\src\test\resources\META-INF\ejb-jar.xml with env-entry
declaration
same error
thx to point me on my mistake :)
cdi-basic-resource-ref-err.zip
<http://openejb.979440.n4.nabble.com/file/n4665814/cdi-basic-resource-ref-err.zip>
--
View this message in context: http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781p4665814.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: resource-ref settings within openEJB
Posted by amber <am...@hotmail.fr>.
Hi Romain,
yes it's what I am doing now
(just having a test file into main/src is not maven friendly ^^)
anyway thank you for helping me !
--
View this message in context: http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781p4665852.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: resource-ref settings within openEJB
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Ok, I got the issue about StringProducer: String type. Env-entry types
are not supported this way but all other types should work.
So <resource-ref> sounds wrong with type String.
That said add in src/main/resources/META-INF/test.ejb-jar.xml:
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
<enterprise-beans>
<session>
<ejb-name>Course</ejb-name>
<env-entry>
<env-entry-name>myresource</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>/home/rmannibucau</env-entry-value>
</env-entry>
</session>
</enterprise-beans>
</ejb-jar>
and starting the container with:
Properties p = new Properties();
p.put(DeploymentLoader.OPENEJB_ALTDD_PREFIX, "test");
container = EJBContainer.createEJBContainer(p);
works
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2013/10/31 amber <am...@hotmail.fr>:
> Hi Romain,
>
> I've try the solution with properties set, but can't get it working.
>
> I've build a new sample in attachment that is near my target (having a
> external String resource set into the application server settings)
>
> thx cdi-basic-inject-resource.zip
> <http://openejb.979440.n4.nabble.com/file/n4665849/cdi-basic-inject-resource.zip>
> for your patience ^^
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781p4665849.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: resource-ref settings within openEJB
Posted by amber <am...@hotmail.fr>.
Hi Romain,
I've try the solution with properties set, but can't get it working.
I've build a new sample in attachment that is near my target (having a
external String resource set into the application server settings)
thx cdi-basic-inject-resource.zip
<http://openejb.979440.n4.nabble.com/file/n4665849/cdi-basic-inject-resource.zip>
for your patience ^^
--
View this message in context: http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781p4665849.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: resource-ref settings within openEJB
Posted by Romain Manni-Bucau <rm...@gmail.com>.
String are not resources. You can set it without config this way:
public class StringResource {
public String create() {return "foo";}
}
Then in container properties set:
resourceid=new://Resource?type=java.lang.String&class-name=StringResource&factory-name=create
About test ejbjar it is seen but in your sample name was wrong + test part
of a maven build is another ejbmodule than main part
Le 31 oct. 2013 02:27, "amber" <am...@hotmail.fr> a écrit :
> Hi romain,
>
> just build with snapshot : same error.
>
> Something I don't understand :
>
> I have a ejb-jar.xml into \src\main\resources\META-INF with the
> resource-ref
> declaration :
> <resource-ref>
> <res-ref-name>thepath</res-ref-name>
> <res-type>java.lang.String</res-type>
> </resource-ref>
>
>
> For tests purpose I need to set the value for this reference (at runtime
> the
> value is set into standalone.xml jboss configuration file so it s working
> fine )
>
> How the value can be set with another ejb-jar.xml file into
> \src\test\resources\META-INF but this time with ?? :
>
> <env-entry-name>thepath</env-entry-name>
> <env-entry-type>java.lang.String</env-entry-type>
> <env-entry-value>the_testing_path</env-entry-value>
>
> Is there a conflict with the ejb-jar.xml defined into
> \src\main\resources\META-INF ?
>
> I guess I missed something...
>
> ps : will try to do a sample
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781p4665807.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: resource-ref settings within openEJB
Posted by amber <am...@hotmail.fr>.
Hi romain,
just build with snapshot : same error.
Something I don't understand :
I have a ejb-jar.xml into \src\main\resources\META-INF with the resource-ref
declaration :
<resource-ref>
<res-ref-name>thepath</res-ref-name>
<res-type>java.lang.String</res-type>
</resource-ref>
For tests purpose I need to set the value for this reference (at runtime the
value is set into standalone.xml jboss configuration file so it s working
fine )
How the value can be set with another ejb-jar.xml file into
\src\test\resources\META-INF but this time with ?? :
<env-entry-name>thepath</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>the_testing_path</env-entry-value>
Is there a conflict with the ejb-jar.xml defined into
\src\main\resources\META-INF ?
I guess I missed something...
ps : will try to do a sample
--
View this message in context: http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781p4665807.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: resource-ref settings within openEJB
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi
did you try with our snapshot (4.6.0-SNAPSHOT)?
can you reproduce it in a shareable sample?
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2013/10/30 amber <am...@hotmail.fr>:
> Hi Romain,
>
> I've try many ways to set the value of the resource, but always got the
> error :
>
> org.apache.openejb.OpenEjbContainer$InitializationException:
> java.lang.NullPointerException: name cannot be null
> at
> org.apache.openejb.OpenEjbContainer$Provider.createEJBContainer(OpenEjbContainer.java:419)
> at
> javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:56)
> at fr.myfooTest.start(ServiceFooTest.java:109)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: java.lang.NullPointerException: name cannot be null
> at
> org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:83)
> at
> org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:73)
> at
> org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:2155)
> at
> org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:1721)
> at
> org.apache.openejb.config.AnnotationDeployer.deploy(AnnotationDeployer.java:342)
> at
> org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:338)
> at
> rg.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:827)
> at
> org.apache.openejb.OpenEjbContainer$Provider.createEJBContainer(OpenEjbContainer.java:371)
> ... 18 more
>
> I've try to put ejb-jar.xml into src/test/java with :
>
> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.1"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
> <enterprise-beans>
> <session>
> <ejb-name>ServiceFoo</ejb-name>
> <env-entry>
> <env-entry-name>thepath</env-entry-name>
> <env-entry-type>java.lang.String</env-entry-type>
> <env-entry-value>the_testing_path</env-entry-value>
> </env-entry>
> </session>
> </enterprise-beans>
> </ejb-jar>
>
>
> As I use the openejb.altdd.prefix property set to test-, tried to put a
> test-ejb-jar.xml into src/resources/ ... same
>
>
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781p4665804.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: resource-ref settings within openEJB
Posted by amber <am...@hotmail.fr>.
Hi Romain,
I've try many ways to set the value of the resource, but always got the
error :
org.apache.openejb.OpenEjbContainer$InitializationException:
java.lang.NullPointerException: name cannot be null
at
org.apache.openejb.OpenEjbContainer$Provider.createEJBContainer(OpenEjbContainer.java:419)
at
javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:56)
at fr.myfooTest.start(ServiceFooTest.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException: name cannot be null
at
org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:83)
at
org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:73)
at
org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:2155)
at
org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:1721)
at
org.apache.openejb.config.AnnotationDeployer.deploy(AnnotationDeployer.java:342)
at
org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:338)
at
rg.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:827)
at
org.apache.openejb.OpenEjbContainer$Provider.createEJBContainer(OpenEjbContainer.java:371)
... 18 more
I've try to put ejb-jar.xml into src/test/java with :
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
<enterprise-beans>
<session>
<ejb-name>ServiceFoo</ejb-name>
<env-entry>
<env-entry-name>thepath</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>the_testing_path</env-entry-value>
</env-entry>
</session>
</enterprise-beans>
</ejb-jar>
As I use the openejb.altdd.prefix property set to test-, tried to put a
test-ejb-jar.xml into src/resources/ ... same
--
View this message in context: http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781p4665804.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: resource-ref settings within openEJB
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi
META-INF/ejb-jar.xml of the module should work in embedded mode or
META-INF/env-entries.properties would too.
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2013/10/29 amber <am...@hotmail.fr>:
> Hi,
>
> I got a external resource (string to define a path); All work fine for my
> project (@resource injection) and the resource is declared into the
> ejb-jar.xml :
> <resource-ref>
> <res-ref-name>thepath</res-ref-name>
> <res-type>java.lang.String</res-type>
> </resource-ref>
>
> Resource value is set into server configuration. Nice.
>
> But my junit test won't work because openEjb just can't find the resource's
> value... How can I set it from openEJB (embeded or openejb.xml) and how ?
>
> thx!
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/resource-ref-settings-within-openEJB-tp4665781.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.