-
15. Re: EJB 3.0 and env-entry injection
bdecoste Dec 8, 2005 1:18 PM (in response to czertik)I've just committed changes that will be included in EJB RC4 to enable the following, per the spec:
@Resource int maxExemptions = 4;
<env-entry>
<env-entry-name>maxExemptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>15</env-entry-value>
</env-entry> -
16. Re: EJB 3.0 and env-entry injection
bdecoste Dec 8, 2005 3:30 PM (in response to czertik)I just confirmed that the injection for the following scenario works properly. Please post exactly what is going wrong when you use <injection-target>. Thanks
int minExceptions = 1;
<env-entry>
<env-entry-name>minExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>5</env-entry-value>
<injection-target>
<injection-target-class>org.jboss.ejb3.test.enventry.TestEnvEntryBean</injection-target-class>
<injection-target-name>minExceptions</injection-target-name>
</injection-target>
</env-entry> -
17. Re: EJB 3.0 and env-entry injection
jagthedrummer Dec 8, 2005 5:17 PM (in response to czertik)"bdecoste" wrote:
I just confirmed that the injection for the following scenario works properly. Please post exactly what is going wrong when you use <injection-target>. Thanks
As I said before the only details that seem to be available on this is that my parameter just does not get set. The log file shows that Jboss sees my ejb-jar.xml file, but there's only the one line about it. It doesn't report an error or throw an exception or anything. Nothing.
I've posted the full ejb-jar.xml file that I've tried using to see if I could get some pointers on what I'm doing wrong, but I don't seem to be getting any help there. (That's the last comment on page 1 of this tread, by the way.)
I've also asked if someone could please post a FULL (as in the whole thing) ejb-jar.xml file which is working so that I can look at it and figure it out myself. If you have one that is working would you please post the entire thing? Please? Pretty please?
Maybe I just have the <env-entry> stuff in the wrong place in the file. I just don't know. I've checked the Sun specs on it and based on that and the few examples I've seen I think I have everything in the right place. But then again the Sun spec doesn't mention anything about <injection-target> so maybe what I need is something different than the spec.
So again, there is no more info I can really give you on this unless you can tell me what I need to do to get it. With no errors being thrown that leads me to belive that I'm awfully close. I'd really love to see the full ejb-jar.xml of a working example. I'm sure I could figure it out from there.
Thanks,
Jeremy -
18. Re: EJB 3.0 and env-entry injection
jameswoodward Dec 9, 2005 11:31 AM (in response to czertik)When do you plan to release RC4?
-
19. Re: EJB 3.0 and env-entry injection
jagthedrummer Dec 20, 2005 4:02 PM (in response to czertik)So does no one actually have this working, or just can no one be bothered to post the full working configuration?
Jeremy -
20. Re: EJB 3.0 and env-entry injection
bdecoste Dec 22, 2005 2:37 PM (in response to czertik)If you download the entire source from CVS (jboss-head), there are examples in the ejb3 JUnit tests. Take a look at the enventry test. Here is an example bean and ejb-jar.xml
@Stateless(name="TestEnvEntry")
@Remote(TestEnvEntry.class)
@RemoteBinding(jndiBinding="TestEnvEntry")
public class TestEnvEntryBean
implements TestEnvEntry
{
private static final Logger log = Logger.getLogger(TestEnvEntryBean.class);
@Resource(name="maxExceptions") private int maxExceptions = 4;
@Resource private int numExceptions = 3;
private int minExceptions = 1;
public int getMaxExceptions()
{
return maxExceptions;
}
public int getNumExceptions()
{
return numExceptions;
}
public int getMinExceptions()
{
return minExceptions;
}
}
<ejb-jar>
<display-name>EnvEntry Tests</display-name>
<enterprise-beans>
<ejb-name>TestEnvEntry</ejb-name>
<env-entry>
<env-entry-name>maxExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>15</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>minExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>5</env-entry-value>
<injection-target>
<injection-target-class>org.jboss.ejb3.test.enventry.TestEnvEntryBean</injection-target-class>
<injection-target-name>minExceptions</injection-target-name>
</injection-target>
</env-entry>
<env-entry>
<env-entry-name>org.jboss.ejb3.test.enventry.TestEnvEntryBean/numExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>10</env-entry-value>
</env-entry>
<ejb-name>ExtendedTestEnvEntry</ejb-name>
<env-entry>
<env-entry-name>maxExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>14</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>minExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>6</env-entry-value>
<injection-target>
<injection-target-class>org.jboss.ejb3.test.enventry.ExtendedTestEnvEntryBean</injection-target-class>
<injection-target-name>minExceptions</injection-target-name>
</injection-target>
</env-entry>
<env-entry>
<env-entry-name>org.jboss.ejb3.test.enventry.ExtendedTestEnvEntryBean/numExceptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>11</env-entry-value>
</env-entry>
</enterprise-beans>
</ejb-jar> -
21. Re: EJB 3.0 and env-entry injection
seanulyate Jul 25, 2006 9:39 AM (in response to czertik)I thought I was having a similar problem to Jeremy. In the end I found that it was my own fault. I had packaged my ejb-xml file in 'meta-inf' folder (lower case). I tried using upper case, 'META-INF', and it worked fine. It's quite a novice mistake to make but sure I'm not the only one who has made it so hopefully this post will benefit someone else.
-
22. Re: EJB 3.0 and env-entry injection
itty06 Nov 22, 2006 12:42 AM (in response to czertik)Here is an example.
All three work but I have shown the first 2 in this example
ejb-jar.xml
ejb-jar.xml<?xml version="1.0" encoding="UTF-8"?> <ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee ../../../testapp/ejb-jar_3_0.xsd "> <enterprise-beans> <session> <ejb-name>com.suresh.ejb.test.HelloBean</ejb-name> <remote>com.suresh.ejb.test.Hello</remote> <ejb-class>com.suresh.ejb.test.HelloBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> <env-entry> <env-entry-name>com.suresh.ejb.test.HelloBean/urls</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>@ldap.url@</env-entry-value> </env-entry> <env-entry> <env-entry-name>username</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>@user.name@</env-entry-value> </env-entry> <env-entry> <env-entry-name>password</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>what</env-entry-value> </env-entry> <env-entry> <env-entry-name>com.suresh.ejb.test.HelloBean/location</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>Australia</env-entry-value> </env-entry> <resource-ref> <res-ref-name>jdbc/user</res-ref-name> <res-type>javax.sql.Datasource</res-type> <res-auth>Container</res-auth> <mapped-name>java:UserDB</mapped-name> </resource-ref> </session> </enterprise-beans> </ejb-jar>
package com.suresh.ejb.test; import java.sql.Connection; import java.sql.ResultSet; import javax.annotation.Resource; import javax.naming.Context; import javax.naming.InitialContext; import javax.sql.DataSource; import com.suresh.ejb.test.Hello; @javax.ejb.Stateless(name="com.suresh.ejb.test.HelloBean") @javax.ejb.TransactionAttribute (value=javax.ejb.TransactionAttributeType.SUPPORTS) @javax.annotation.Resource(name="jdbc/user", type=DataSource.class, authenticationType=javax.annotation.Resource.AuthenticationType.CONTAINER, mappedName="java:UserDB") public class HelloBean implements Hello { @Resource private String urls; @Resource(name="username") private String provider; @Resource(name="password") private String pwd; @Resource private String location; public String greet() { return urls + " " + location + " " + pwd + " " + provider + " at " + greet1(); } //example of datasource public String greet1() { String data = null; Connection c = null; try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("java:comp.ejb3/env/jdbc/user"); ResultSet rs = ds.getConnection().createStatement().executeQuery("select sysdate from dual"); while (rs.next()) { data = rs.getString(1); } } catch (Exception e) { System.err.println(e); e.printStackTrace(); } finally { try { c.close(); } catch (Exception e) { } } return data; } }
Hello.javapackage comsuresh.ejb.test; import javax.ejb.Remote; @Remote public interface Hello { public String greet(); }
Ran with 4.0.4GA + EJB RC9 -
23. Re: EJB 3.0 and env-entry injection
jahlborn Dec 4, 2006 9:23 AM (in response to czertik)I don't know if anyone noticed, but the original problem case was using a Service bean, not a Stateless bean. I'm also using Service beans and running into the exact same problem: there does not seem to be any way to provide external configuration for them. If anyone has a working example for Service beans, I'd love to see it.
thanks,
-james -
24. Re: EJB 3.0 and env-entry injection
jahlborn Dec 4, 2006 9:41 AM (in response to czertik)At this point, I pretty convinced this is not currently possible, so I've filed a feature request:
http://jira.jboss.com/jira/browse/EJBTHREE-801[/url]