Hi,
After reading the document provided in the
http://www.amitysolutions.com.au/documents/JBossTomcatJNDI-technote.pdf
I am not sure that is the easiest way to locate any EJBs from a web container. I tried
the following approach but having some problem when try to lookup the EJBs.
Here is what I do to get the EJBs from tomcat:
1) use the InitialContext to get the ENC variable that were declared in the web.xml
file. For example,
<env-entry>
| <env-entry-name>
| AppServerIPAddr1
| </env-entry-name>
| <env-entry-value>localhost</env-entry-value>
| <env-entry-type>java.lang.String</env-entry-type>
| </env-entry>
|
| <env-entry>
| <env-entry-name>
| AppServerIPAddr1PortNumber
| </env-entry-name>
| <env-entry-value>1099</env-entry-value>
| <env-entry-type>java.lang.String</env-entry-type>
| </env-entry>
| <env-entry>
| <description>INITIAL CONTEXT FACTORY</description>
| <env-entry-name>initialContextFactory</env-entry-name>
|
<env-entry-value>org.jnp.interfaces.NamingContextFactory</env-entry-value>
| <env-entry-type>java.lang.String</env-entry-type>
| </env-entry>
|
| <env-entry>
| <env-entry-name>
| urlPackagePrefixes
| </env-entry-name>
| <env-entry-value>
| org.jboss.naming:org.jnp.interfaces
| </env-entry-value>
| <env-entry-type>java.lang.String</env-entry-type>
| </env-entry>
|
| <ejb-ref>
| <description>Reference to UserController Bean</description>
| <ejb-ref-name>ejb/refToUserControllerBean</ejb-ref-name>
| <ejb-ref-type>Session</ejb-ref-type>
| <home>
|
com.wlwa.Infra.BusinessLogic.SessionBeans.Controller.UserControllerRemoteHome
| </home>
| <remote>
|
com.wlwa.Infra.BusinessLogic.SessionBeans.Controller.UserControllerRemote
| </remote>
| <ejb-link>UserControllerBean</ejb-link>
| </ejb-ref>
|
InitialContext ctx = new InitialContext();
applicationServer1IPAddress = (String) ctx.lookUp("AppServerIPAddr1");
applicationServer1PortNumber = (String) ctx.lookUp("AppServerIPAddr1PortNumber");
urlPackagePrefixes = (String) ctx.lookUp("urlPackagePrefixes");
initialContextFactory = (String) ctx.lookUp("initialContextFactory");
2) Now when I got all information to create a properties object to be used when create
the new InitialContext object for lookup the EJBs outside of the tomcat space.
String url = "jnp://" + applicationServer1IPAddress + ":" +
applicationServer1PortNumber;
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
props.setProperty(Context.URL_PKG_PREFIXES, urlPackagePrefixes);
props.setProperty(Context.PROVIDER_URL, url);
InitialContext remoteCtx = new InitialContext(props);
3) Now I have a IinitailContext object that point to the Jboss JNDI service at port
1099. Then I use the following code to access the EJB home object:
...
try {
anEJBHome = (EJBHome) PortableRemoteObject.narrow
(ctx.lookup("java:comp/env/ejb/refToUserControllerBean"), aHomeClass);
} catch (ClassCastException classCastEx) {
throw new EJBHomeFactoryException(classCastEx);
} catch (NamingException namingEx) {
throw new EJBHomeFactoryException(namingEx);
}
Here is the ejb declaration for the bean in ejb-jar.xml
<enterprise-beans>
| <session>
| <display-name>User Access Controller Session
Bean</display-name>
| <ejb-name>UserControllerBean</ejb-name>
| <home>
|
com.wlwa.Infra.BusinessLogic.SessionBeans.Controller.UserControllerRemoteHome
| </home>
| <remote>
|
com.wlwa.Infra.BusinessLogic.SessionBeans.Controller.UserControllerRemote
| </remote>
| <ejb-class>
|
com.wlwa.Infra.BusinessLogic.SessionBeans.Controller.UserControllerEJB
| </ejb-class>
| <session-type>Stateless</session-type>
| <transaction-type>Container</transaction-type>
| </session>
| </enterprise-beans>
Here is the declaration in jboss.xml
<jboss>
| <enterprise-beans>
| <session>
| <ejb-name>UserControllerBean</ejb-name>
| <jndi-name>UserControllerBeanJNDI</jndi-name>
| <resource-ref>
| <res-ref-name>jdbc/AlertDB</res-ref-name>
| <jndi-name>java:/jdbc/AlertDB</jndi-name>
| </resource-ref>
| </session>
| ......
| <enterprise-beans>
| <jboss>
The UserControllerBean was packaged under a jar file named
InfraSessionBeansControllerModule.jar in an ear file named MyApp.ear that was
deployed in Jboss server in the same box as the tomcat was running.
However, I got NamingException
org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
org.jnp.server.NamingServer.getObject(NamingServer.java:509)
org.jnp.server.NamingServer.lookup(NamingServer.java:253)
Did anyone have try this way to access to EJBs from the web container. Or this is
not a good way to lookup EJBs from the web container. Any comment or suggestion is
greatly appreciated.
Kam
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3837328#3837328
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3837328
-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
>From Windows to Linux, servers to mobile, InstallShield X is the one
installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user