Application Client and ENC in AS7.1
wolfgangknauf Feb 14, 2012 2:15 PMHi,
I try to find out how a JNDI lookup in an application client might work, when the EJB is not looked up in global JNDI, but in the Environment Naming Context (ENC).
Unfortunately the application client tutorial at https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI ends before this information ;-).
In JBoss 6 and before, I had to to those steps (I already tried to port it to AS7, so e.g. the JNDI name is no longer AS6 style):
Declare the ejb ref in "application-client.xml":
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<application-client id="Application-client_ID" version="6"
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 http://java.sun.com/xml/ns/javaee/application-client_6.xsd">
...
<ejb-ref>
<ejb-ref-name>ejb/GeometricModel</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote</remote>
</ejb-ref>
</application-client>
{code}
Connect the EJB ref to a JNDI name in "jboss-client.xml":
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-client PUBLIC
"-//JBoss//DTD Application Client 5.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd">
<jboss-client>
<jndi-name>StatelessClient</jndi-name>
<ejb-ref>
<ejb-ref-name>ejb/GeometricModel</ejb-ref-name>
<jndi-name>ejb:Stateless/StatelessEJB/GeometricModelBean!de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote</jndi-name>
</ejb-ref>
</jboss-client>
{code}
Perform a lookup... Following are a few fragments, which all don't work (besides the lookup in global JNDI):
{code}
Properties props = new Properties();
props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
InitialContext initialContext = new InitialContext(props);
Object objRemote = initialContext.lookup("java:comp/env/ejb/GeometricModel");
//Object objRemote = initialContext.lookup("ejb/GeometricModel");
//Object objRemote = initialContext.lookup("ejb:Stateless/StatelessEJB/GeometricModelBean!de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote");
//GeometricModelRemote geometricModel = (GeometricModelRemote) PortableRemoteObject.narrow(objRemote, GeometricModelRemote.class);
GeometricModelRemote geometricModel = (GeometricModelRemote) objRemote;
{code}
All lookups (besides the global lookup) result in this exception:
{code}
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 de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelApplicationClient.main(GeometricModelApplicationClient.java:49)
{code}
Is the ENC supported in AS7 for application clients? If yes: what is necessary to use it ;-)?
Best regards
Wolfgang