<ejb-link> problem - multiple deployments getting wires cros
macamat Nov 23, 2003 2:40 AMHi forum,
This is my first post - I am relatively new to JBoss and have managed to solve all previous problems by searching through these forums, but I have finally hit a snag. This will take some explaining though -
I have developed a Struts/EJB application which acts as a blog/photo journal site, running on JBoss 3.2.1 on WinXP (for now). It works nicely. However, I am trying to deploy this application multiple times onto the same JBoss instance; the idea is to give my friends their own independent blog sites etc on my server.
So to make this work I have configured my ant build so that the following properties of the application are modified before deployment:
a) application.xml is modified so that the context root is different
b) The datasource property of the element within the ant task is modified to point to a different datasource.
c) All references to EJBs (only local references are used) have their context modified to include the application name, to avoid JNDI context clashes. This is done using an ant task.
So for example:
ejb/SequenceGenerator
becomes
ejb/foo/SequenceGenerator
in one deployment and
ejb/bar/SequenceGenerator
in another.
d) The ear and jar files are named uniquely
e) The web.xml file of my .war deployment has its <ejb-local-ref> elements modified so that the <ejb-ref-name> properties match c) and the <ejb-link> properties match d).
If I run my script twice with different application names I end up with two .ear files which look something like this:
foo.ear
+ foo.jar (EJB module)
+ photoserver.war (Struts module)
bar.ear
+ bar.jar (EJB module)
+ photoserver.war (Struts module)
All communication between the struts module and the ejb module is through local references to stateless session beans.
Either of these applications work fine when deployed by themselves. However when I deploy them both, the second deployed application will fail as its struts module will retrieve a session bean from the first deployment's EJB module instead of its own - this will eventually end in the following exception (in the case of deploying foo first, then deploying bar, and attempting to access bar):
Note that the message in the exception - 'foo not bound' - is the name of the first deployed application, when it is the second (bar) that I am trying to access.
12:01:35,450 ERROR [STDERR] Caught a NamingException
12:01:35,450 ERROR [STDERR] javax.naming.NameNotFoundException: foo not bound
12:01:35,460 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
12:01:35,460 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
12:01:35,460 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
12:01:35,460 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
12:01:35,460 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:256)
12:01:35,460 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:256)
12:01:35,460 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:492)
12:01:35,460 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:606)
12:01:35,460 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
12:01:35,460 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:347)
12:01:35,460 ERROR [STDERR] at com.macamat.photoserver.ejb.AdminFacadeBean.getPersistentPropertyHome(AdminFacadeBean.java:589)
12:01:35,460 ERROR [STDERR] at com.macamat.photoserver.ejb.AdminFacadeBean.incrementNumericProperty(AdminFacadeBean.java:269)
12:01:35,460 ERROR [STDERR] at com.macamat.photoserver.ejb.AdminFacadeBean.incrementHomepageRequests(AdminFacadeBean.java:216)
12:01:35,460 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...etc...
I have tested and shown that this exception occurs in the Session Bean in the FOO deployment, so the communication between the struts and EJB modules is definitely getting its wires crossed.
Below are two copies of my web.xml file, one for foo and one for bar - as far as I can tell there should be no misunderstanding. I didn't think that I would need to use jboss-web.xml - anyone have any ideas?
Thanks in advance,
- Mat
ps. Tried to attach these files but the attach+post button wasn't working...
--------------------
web.xml for FOO
--------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>foo application</display-name>
<!-- Action Servlet Configuration -->
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
<!-- Struts Tag Library Descriptors -->
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
<ejb-local-ref>
<ejb-ref-name>ejb/foo/DirectoryFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.macamat.photoserver.ejb.DirectoryFacadeHome</local-home>
com.macamat.photoserver.ejb.DirectoryFacade
<ejb-link>foo.jar#DirectoryFacade</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/foo/AdminFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.macamat.photoserver.ejb.AdminFacadeHome</local-home>
com.macamat.photoserver.ejb.AdminFacade
<ejb-link>foo.jar#AdminFacade</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/foo/ImageFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.macamat.photoserver.ejb.ImageFacadeHome</local-home>
com.macamat.photoserver.ejb.ImageFacade
<ejb-link>foo.jar#ImageFacade</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/foo/JournalFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.macamat.photoserver.ejb.JournalFacadeHome</local-home>
com.macamat.photoserver.ejb.JournalFacade
<ejb-link>foo.jar#JournalFacade</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/foo/GuestbookFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.macamat.photoserver.ejb.GuestbookFacadeHome</local-home>
com.macamat.photoserver.ejb.GuestbookFacade
<ejb-link>foo.jar#GuestbookFacade</ejb-link>
</ejb-local-ref>
</web-app>
--------------------
web.xml for BAR
--------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>bar application</display-name>
<!-- Action Servlet Configuration -->
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
<!-- Struts Tag Library Descriptors -->
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
<ejb-local-ref>
<ejb-ref-name>ejb/bar/DirectoryFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.macamat.photoserver.ejb.DirectoryFacadeHome</local-home>
com.macamat.photoserver.ejb.DirectoryFacade
<ejb-link>bar.jar#DirectoryFacade</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/bar/AdminFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.macamat.photoserver.ejb.AdminFacadeHome</local-home>
com.macamat.photoserver.ejb.AdminFacade
<ejb-link>bar.jar#AdminFacade</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/bar/ImageFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.macamat.photoserver.ejb.ImageFacadeHome</local-home>
com.macamat.photoserver.ejb.ImageFacade
<ejb-link>bar.jar#ImageFacade</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/bar/JournalFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.macamat.photoserver.ejb.JournalFacadeHome</local-home>
com.macamat.photoserver.ejb.JournalFacade
<ejb-link>bar.jar#JournalFacade</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/bar/GuestbookFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.macamat.photoserver.ejb.GuestbookFacadeHome</local-home>
com.macamat.photoserver.ejb.GuestbookFacade
<ejb-link>bar.jar#GuestbookFacade</ejb-link>
</ejb-local-ref>
</web-app>