-
1. Re: Using ejb-ref to mantain old JNDI bindings in code
sfcoy Nov 1, 2012 6:57 PM (in response to mylos78)An ejb-ref-name, indeed any *-ref-name is a name in the ENC (environment naming context).
If you declare:
{code:xml}<ejb-ref-name>ejb/TelcoInfo</ejb-ref-name>{code}
then in code you must:
{code:java}return (TelcoInfo) context.lookup("java:comp/env/ejb/TelcoInfo");{code}
ie. There is always an implicit "java:comp/env/".
For what it's worth, this is always one of the first steps I perform in a code migration. I ensure that JNDI lookups are using ENC names everywhere and verify correct operation on the original source platform. JNDI ENC lookups are 100% portable across server versions and vendors.
In your case, these ENC names would be mapped to their true global names in the jboss.xml file (on JBoss 4). You will need to subsequently convert your jboss.xml file to the equivalent jboss-ejb3.xml file.
Finally, if your EJBs are all running inside the same Java VM, you can do away with the jndiProperties.
There's more information available in AS71 EJB 3 Reference Guide.
-
2. Re: Using ejb-ref to mantain old JNDI bindings in code
mylos78 Nov 2, 2012 3:01 AM (in response to sfcoy)Thanks for your reply Stephen,
I've tried looking up the EJB with:
return (TelcoInfo) context.lookup("java:comp/env/ejb/TelcoInfo");
however it produced the same error. Also tried with
return (TelcoInfo) context.lookup("java:global/ejb/TelcoInfo");
with no luck.
Finally, by setting the JNDI binding via configuration file didn't help too....
<bindings>
<lookup name="ejb/TelcoInfo" lookup="ejb:/telecom//TelcoInfoBean!com.telco.ejb.TelcoInfo"/>
</bindings>
I don't know what else I could try :-(
Thanks
Mylos
-
3. Re: Using ejb-ref to mantain old JNDI bindings in code
jaikiran Nov 2, 2012 3:04 AM (in response to mylos78)Which exact version of JBoss AS7? Where is that lookup being done? Please post the entire exception stacktrace.
-
4. Re: Using ejb-ref to mantain old JNDI bindings in code
mylos78 Nov 2, 2012 3:43 AM (in response to jaikiran)Hello,
so the release I'm using is 7.1.1 final release and the stacktrace available on the client is
Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.telcosuite.ejbclient.RemoteEJBClient.lookupInfoEJB(RemoteEJBClient.java:144)
The line 144 of RemoteEJBClient is
return (TelcoInfo) context.lookup("java:comp/env/ejb/TelcoInfo");
Thanks
Mylos
-
5. Re: Using ejb-ref to mantain old JNDI bindings in code
nickarls Nov 2, 2012 3:53 AM (in response to mylos78)What do you stick in jndiProperties at
final Context context = new InitialContext(jndiProperties);
?
-
6. Re: Using ejb-ref to mantain old JNDI bindings in code
sfcoy Nov 2, 2012 4:06 AM (in response to mylos78)This won't work without a correctly set up jboss-ejb3.xml file:
{code:xml}
<?xml version="1.0"?>
<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1"
impl-version="2.0">
<enterprise-beans>
<session>
<ejb-name>TelcoInfo</ejb-name>
<ejb-ref>
<ejb-ref-name>ejb/TelcoInfo</ejb-ref-name>
<jndi-name>ejb:/telecom//TelcoInfoBean!com.telco.ejb.TelcoInfo</jndi-name>
</ejb-ref>
</session>
</enterprise-beans>
</jboss:ejb-jar>
{code}
-
7. Re: Using ejb-ref to mantain old JNDI bindings in code
jaikiran Nov 2, 2012 4:16 AM (in response to mylos78)You really mean a standalone remote client, from where this lookup is happening? The ENC namespace (java:comp) is only visible to the component in which you have configured that ejb-ref and it isn't visible outside of it, let alone a remote standalone client.
-
8. Re: Using ejb-ref to mantain old JNDI bindings in code
mylos78 Nov 2, 2012 4:55 AM (in response to nickarls)@Nicklas
Here's my initial context lookup:
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
-
9. Re: Using ejb-ref to mantain old JNDI bindings in code
mylos78 Nov 2, 2012 5:00 AM (in response to sfcoy)@Stephen
Thanks, however I'm afraid the jboss-ejb3.xml you posted is not supported.
I've got some exceptions
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBA
S014551: <session-type> not specified for ejb TelcoInfo. This must be present in ejb-jar.xml
Once adding the session-type attribute
Caused by: java.lang.IllegalArgumentException: JBAS011084: componentClassName is null
So, I've ended up with:
<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="urn:clustering:1.0"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1" impl-version="2.0">
<enterprise-beans>
<session>
<session-type>Stateless</session-type>
<ejb-name>TelcoInfo</ejb-name>
<ejb-class>com.telco.ejb.TelcoInfoBean</ejb-class>
<ejb-ref>
<ejb-ref-name>ejb/TelcoInfo</ejb-ref-name>
<jndi-name>ejb:/telecom//TelcoInfoBean!com.telco.ejb.TelcoInfo</jndi-name>
<lookup-name>ejb:/telecom//TelcoInfoBean!com.telco.ejb.TelcoInfo</lookup-name>
</ejb-ref>
</session>
</enterprise-beans>
</jboss:ejb-jar>
However the issue stayed the same :-(
-
10. Re: Using ejb-ref to mantain old JNDI bindings in code
sfcoy Nov 6, 2012 10:36 PM (in response to mylos78)Can we clarify where your EJBs are deployed and where the client code is deployed please.
Also, reading the above again I've realized that the ejb-refs are self referencing? That's probably not what you intended. An ejb-ref is a reference from within the declaring enterprise bean to a different enterprise bean.
-
11. Re: Using ejb-ref to mantain old JNDI bindings in code
baseaditi Jan 16, 2015 5:18 AM (in response to sfcoy)so there has any other way to manage JNDI binding from JBOSS5 to Jboss7?
Please let me know.