User: starksm
Date: 01/05/24 00:07:35
Modified: src/main/org/jboss/web Tag: Branch_2_2
AbstractWebContainer.java
Log:
Update to use a callback mechanism for creating the JNDI env to ensure
that load on startup servlets work correctly
Revision Changes Path
No revision
No revision
1.3.2.2 +74 -47 jboss/src/main/org/jboss/web/AbstractWebContainer.java
Index: AbstractWebContainer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/web/AbstractWebContainer.java,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -r1.3.2.1 -r1.3.2.2
--- AbstractWebContainer.java 2001/05/23 02:41:10 1.3.2.1
+++ AbstractWebContainer.java 2001/05/24 07:07:35 1.3.2.2
@@ -13,10 +13,7 @@
import org.w3c.dom.Element;
-import org.apache.log4j.Category;
-
import org.jboss.ejb.DeploymentException;
-import org.jboss.logging.Logger;
import org.jboss.metadata.EjbRefMetaData;
import org.jboss.metadata.EnvEntryMetaData;
import org.jboss.metadata.ResourceRefMetaData;
@@ -36,7 +33,7 @@
- ejb-ref
- security-domain
-Subclasses need to implement the {@link #performDeploy(String, String)
performDeploy()}
+Subclasses need to implement the {@link #performDeploy(String, String,
WebDescriptorParser) performDeploy()}
and {@link #performUndeploy(String) performUndeploy()} methods to perform the
container specific steps and return the web application info required by the
AbstractWebContainer class.
@@ -114,18 +111,39 @@
@see org.jboss.security.SecurityAssociation;
@author [EMAIL PROTECTED]
-@version $Revision: 1.3.2.1 $
+@version $Revision: 1.3.2.2 $
*/
public abstract class AbstractWebContainer extends ServiceMBeanSupport implements
AbstractWebContainerMBean
{
- /** The "WebContainer" log4j category instance available for logging related
- to WebContainer events.
- */
- //public static final Category category = Category.getInstance("WebContainer");
+ public static interface WebDescriptorParser
+ {
+ /** This method is called as part of subclass performDeploy() method
implementations
+ to parse the web-app.xml and jboss-web.xml deployment descriptors from a
+ war deployment. The method creates the ENC(java:comp/env) env-entry,
+ resource-ref, & ejb-ref element values. The creation of the env-entry
+ values does not require a jboss-web.xml descriptor. The creation of the
+ resource-ref and ejb-ref elements does require a jboss-web.xml
descriptor
+ for the JNDI name of the deployed resources/EJBs.
+
+ Because the ENC context is private to the web application, the web
+ application class loader is used to identify the ENC. The class loader
+ is used because each war typically requires a unique class loader to
+ isolate the web application classes/resources. This means that the
+ ClassLoader passed to this method must be the thread context ClassLoader
+ seen by the server/jsp pages during init/destroy/service/etc. method
+ invocations if these methods interace with the JNDI ENC context.
+
+ @param loader, the ClassLoader for the web application. May not be null.
+ @param webApp, the root element of thw web-app.xml descriptor. May not be
null.
+ @param jbossWeb, the root element of thw jboss-web.xml descriptor. May be
null
+ to indicate that no jboss-web.xml descriptor exists.
+ */
+ public void parseWebAppDescriptors(ClassLoader loader, Element webApp,
Element jbossWeb) throws Exception;
+ }
+
/** A mapping of deployed warUrl strings to the WebApplication object */
protected HashMap deploymentMap = new HashMap();
-
public AbstractWebContainer()
{
}
@@ -135,13 +153,18 @@
perform the container specific deployment steps and registers the
returned WebApplication in the deployment map. The steps performed are:
- WebApplication warInfo = performDeploy(ctxPath, warUrl);
+ WebDescriptorParser webAppParser = ...;
+ WebApplication warInfo = performDeploy(ctxPath, warUrl, webAppParser);
ClassLoader loader = warInfo.getClassLoader();
Element webApp = warInfo.getWebApp();
Element jbossWeb = warInfo.getJbossWeb();
- parseWebAppDescriptors(loader, webApp, jbossWeb);
deploymentMap.put(warUrl, warInfo);
+ The subclass performDeploy() implementation needs to invoke
+ webAppParser.parseWebAppDescriptors(loader, webApp, jbossWeb) to have the
+ JNDI java:comp/env namespace setup before any web app component can access
+ this namespace.
+
@param ctxPath, The context-root element value from the J2EE
application/module/web application.xml descriptor. This may be null
if war was is not being deployed as part of an enterprise application.
@@ -151,11 +174,11 @@
{
try
{
- WebApplication warInfo = performDeploy(ctxPath, warUrl);
+ WebDescriptorParser webAppParser = new DescriptorParser();
+ WebApplication warInfo = performDeploy(ctxPath, warUrl, webAppParser);
ClassLoader loader = warInfo.getClassLoader();
Element webApp = warInfo.getWebApp();
Element jbossWeb = warInfo.getJbossWeb();
- parseWebAppDescriptors(loader, webApp, jbossWeb);
deploymentMap.put(warUrl, warInfo);
}
catch(DeploymentException e)
@@ -164,21 +187,26 @@
}
catch(Exception e)
{
+ e.printStackTrace();
throw new DeploymentException("Error during deploy", e);
}
}
- /** The method called by the deploy() method that must be overriden by
- subclasses to perform the web container specific deployment steps.
+ /** This method is called by the deploy() method template and must be overriden
by
+ subclasses to perform the web container specific deployment steps.
@param ctxPath, The context-root element value from the J2EE
application/module/web application.xml descriptor. This may be null
if war was is not being deployed as part of an enterprise application.
@param warUrl, The string for the URL of the web application war.
+ @param webAppParser, The callback interface the web container should use to
+ setup the web app JNDI environment for use by the web app components. This
+ needs to be invoked after the web app class loader is known, but before
+ and web app components attempt to access the java:comp/env JNDI namespace.
@return WebApplication, the web application information required by the
- AbstractWebContainer class to setup the JNDI ENC and track the war
- deployment status.
+ AbstractWebContainer class to track the war deployment status.
*/
- protected abstract WebApplication performDeploy(String ctxPath, String warUrl)
throws Exception;
+ protected abstract WebApplication performDeploy(String ctxPath, String warUrl,
+ WebDescriptorParser webAppParser) throws Exception;
/** A template pattern implementation of the undeploy() method. This method
calls the {@link #performUndeploy(String) performUndeploy()} method to
@@ -229,30 +257,17 @@
return deploymentMap.values().iterator();
}
- /** This method is called as part of the deploy() method template to
- parse the web-app.xml and jboss-web.xml deployment descriptors from a
- war deployment. The method creates the ENC(java:comp/env) env-entry,
- resource-ref, & ejb-ref element values. The creation of the env-entry
- values does not require a jboss-web.xml descriptor. The creation of the
- resource-ref and ejb-ref elements does require a jboss-web.xml descriptor
- for the JNDI name of the deployed resources/EJBs.
-
- Because the ENC context is private to the web application, the web
- application class loader is used to identify the ENC. The class loader
- is used because each war typically requires a unique class loader to
- isolate the web application classes/resources. This means that the
- ClassLoader passed to this method must be the thread context ClassLoader
- seen by the server/jsp pages during init/destroy/service/etc. method
- invocations if these methods interace with the JNDI ENC context.
+ /** This method is invoked from within subclass performDeploy() method
+ implementations when they invoke WebDescriptorParser.parseWebAppDescriptors().
@param loader, the ClassLoader for the web application. May not be null.
@param webApp, the root element of thw web-app.xml descriptor. May not be null.
@param jbossWeb, the root element of thw jboss-web.xml descriptor. May be null
to indicate that no jboss-web.xml descriptor exists.
*/
- private void parseWebAppDescriptors(ClassLoader loader, Element webApp, Element
jbossWeb) throws Exception
+ protected void parseWebAppDescriptors(ClassLoader loader, Element webApp,
Element jbossWeb) throws Exception
{
- Logger.debug("AbstractWebContainer.parseWebAppDescriptors, Begin");
+ System.out.println("AbstractWebContainer.parseWebAppDescriptors, Begin");
WebMetaData metaData = new WebMetaData();
metaData.importXml(webApp);
if( jbossWeb != null )
@@ -274,18 +289,18 @@
}
Iterator envEntries = metaData.getEnvironmentEntries();
- Logger.debug("addEnvEntries");
+ System.out.println("addEnvEntries");
addEnvEntries(envEntries, envCtx);
Iterator resourceRefs = metaData.getResourceReferences();
- Logger.debug("linkResourceRefs");
+ System.out.println("linkResourceRefs");
linkResourceRefs(resourceRefs, envCtx);
Iterator ejbRefs = metaData.getEjbReferences();
- Logger.debug("linkEjbRefs");
+ System.out.println("linkEjbRefs");
linkEjbRefs(ejbRefs, envCtx);
String securityDomain = metaData.getSecurityDomain();
- Logger.debug("linkSecurityDomain");
+ System.out.println("linkSecurityDomain");
linkSecurityDomain(securityDomain, envCtx);
- Logger.debug("AbstractWebContainer.parseWebAppDescriptors, End");
+ System.out.println("AbstractWebContainer.parseWebAppDescriptors, End");
}
protected void addEnvEntries(Iterator envEntries, Context envCtx)
@@ -294,7 +309,7 @@
while( envEntries.hasNext() )
{
EnvEntryMetaData entry = (EnvEntryMetaData) envEntries.next();
- Logger.debug("Binding env-entry: "+entry.getName()+" of type:
"+entry.getType()+" to value:"+entry.getValue());
+ System.out.println("Binding env-entry: "+entry.getName()+" of type:
"+entry.getType()+" to value:"+entry.getValue());
EnvEntryMetaData.bindEnvEntry(envCtx, entry);
}
}
@@ -311,7 +326,7 @@
{
try
{
- Logger.debug("Binding '"+refName+"' to URL: "+resourceName);
+ System.out.println("Binding '"+refName+"' to URL:
"+resourceName);
URL url = new URL(resourceName);
Util.bind(envCtx, refName, url);
}
@@ -322,7 +337,7 @@
}
else
{
- Logger.debug("Linking '"+refName+"' to JNDI name: "+resourceName);
+ System.out.println("Linking '"+refName+"' to JNDI name:
"+resourceName);
Util.bind(envCtx, refName, new LinkRef(resourceName));
}
}
@@ -339,7 +354,7 @@
String linkName = ejb.getLink();
if( jndiName == null )
jndiName = linkName;
- Logger.debug("Linking ejb-ref: "+name+" to JNDI name: "+jndiName);
+ System.out.println("Linking ejb-ref: "+name+" to JNDI name: "+jndiName);
if( jndiName == null )
throw new NamingException("ejb-ref: "+name+", expected jndi-name
in jboss-web.xml");
Util.bind(envCtx, name, new LinkRef(jndiName));
@@ -360,16 +375,28 @@
{
if( securityDomain == null )
{
- Logger.debug("Binding security/securityMgr to NullSecurityManager");
+ System.out.println("Binding security/securityMgr to
NullSecurityManager");
Object securityMgr = new NullSecurityManager(securityDomain);
Util.bind(envCtx, "security/securityMgr", securityMgr);
Util.bind(envCtx, "security/realmMapping", securityMgr);
}
else
{
- Logger.debug("Linking security/securityMgr to JNDI name:
"+securityDomain);
+ System.out.println("Linking security/securityMgr to JNDI name:
"+securityDomain);
Util.bind(envCtx, "security/securityMgr", new LinkRef(securityDomain));
Util.bind(envCtx, "security/realmMapping", new LinkRef(securityDomain));
}
}
+
+ /** An inner class that maps the WebDescriptorParser.parseWebAppDescriptors()
+ onto the protected parseWebAppDescriptors() AbstractWebContainer method.
+ */
+ private class DescriptorParser implements WebDescriptorParser
+ {
+ public void parseWebAppDescriptors(ClassLoader loader, Element webApp,
Element jbossWeb) throws Exception
+ {
+ AbstractWebContainer.this.parseWebAppDescriptors(loader, webApp,
jbossWeb);
+ }
+ }
+
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development