[jboss-cvs] JBossAS SVN: r60456 - trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 8 22:04:56 EST 2007
Author: remy.maucherat at jboss.com
Date: 2007-02-08 22:04:56 -0500 (Thu, 08 Feb 2007)
New Revision: 60456
Modified:
trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployment2.java
Log:
- Address some timing issues when creating the ENC (which needs to be created before starting the listeners).
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployment2.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployment2.java 2007-02-09 01:40:02 UTC (rev 60455)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployment2.java 2007-02-09 03:04:56 UTC (rev 60456)
@@ -46,6 +46,8 @@
import javax.naming.InitialContext;
import javax.naming.LinkRef;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Loader;
import org.apache.catalina.core.StandardContext;
@@ -191,16 +193,12 @@
{
log.debug("No " + CONTEXT_CONFIG_FILE + " in " + url, e);
}
-
- if (injectionContainer != null)
- {
- context.setAnnotationProcessor(injectionContainer);
- }
VFSDirContext resources = new VFSDirContext();
resources.setVirtualFile(webApp.getDeploymentUnit().getFile(""));
context.setResources(resources);
+ context.setAnnotationProcessor(injectionContainer);
context.setDocBase(url.getFile());
context.setConfigFile(ctxConfig);
context.setDefaultContextXml("context.xml");
@@ -288,6 +286,7 @@
// Set listener
context.setConfigClass("org.jboss.web.tomcat.tc6.deployers.JBossContextConfig");
+ context.addLifecycleListener(new EncListener(loader, webLoader, metaData));
// Pass the metadata to the RunAsListener via a thread local
RunAsListener.metaDataLocal.set(metaData);
@@ -297,16 +296,9 @@
{
// Init the container; this will also start it
context.init();
-
- // make the context class loader known to the WebMetaData, ws4ee needs it
- // to instanciate service endpoint pojos that live in this webapp
- Loader ctxLoader = context.getLoader();
- metaData.setContextLoader(ctxLoader.getClassLoader());
-
// Start it
context.start();
// Build the ENC
-
}
finally
{
@@ -315,62 +307,6 @@
JBossContextConfig.metaDataShared.set(null);
}
- if (injectionContainer == null)
- super.processEnc(webLoader.getClassLoader(), webApp);
- else
- {
- Thread currentThread = Thread.currentThread();
- ClassLoader currentLoader = loader;
- try
- {
- // Create a java:comp/env environment unique for the web application
- log.debug("Creating ENC using ClassLoader: " + loader);
- ClassLoader parent = loader.getParent();
- while (parent != null)
- {
- log.debug(".." + parent);
- parent = parent.getParent();
- }
- // TODO: The enc should be an input?
- currentThread.setContextClassLoader(webLoader.getClassLoader());
- metaData.setENCLoader(webLoader.getClassLoader());
- InitialContext iniCtx = new InitialContext();
- Context envCtx = (Context) iniCtx.lookup("java:comp");
- // Add ORB/UserTransaction
- ORB orb = null;
- try
- {
- ObjectName ORB_NAME = new ObjectName("jboss:service=CorbaORB");
- orb = (ORB) server.getAttribute(ORB_NAME, "ORB");
- // Bind the orb
- if (orb != null)
- {
- NonSerializableFactory.rebind(envCtx, "ORB", orb);
- log.debug("Bound java:comp/ORB");
- }
- }
- catch (Throwable t)
- {
- log.debug("Unable to retrieve orb" + t.toString());
- }
-
- // TODO: injection, Add a link to the global transaction manager
- envCtx.bind("UserTransaction", new LinkRef("UserTransaction"));
- log.debug("Linked java:comp/UserTransaction to JNDI name: UserTransaction");
- envCtx = envCtx.createSubcontext("env");
- injectionContainer.populateEnc(webLoader.getClassLoader());
- // TODO: this should be bindings in the metadata
- currentThread.setContextClassLoader(webLoader.getClassLoader());
- String securityDomain = metaData.getSecurityDomain();
- log.debug("linkSecurityDomain");
- linkSecurityDomain(securityDomain, envCtx);
- }
- finally
- {
- currentThread.setContextClassLoader(currentLoader);
- }
- }
-
// Clustering
if (metaData.getDistributable())
{
@@ -474,7 +410,92 @@
log.debug("Initialized: " + webApp + " " + objectName);
}
+
+ public class EncListener implements LifecycleListener {
+
+ protected ClassLoader loader = null;
+ protected Loader webLoader = null;
+ protected WebMetaData metaData = null;
+ public EncListener(ClassLoader loader, Loader webLoader, WebMetaData metaData) {
+ this.loader = loader;
+ this.webLoader = webLoader;
+ this.metaData = metaData;
+ }
+
+ public void lifecycleEvent(LifecycleEvent event) {
+ if (event.getType().equals(StandardContext.AFTER_START_EVENT)) {
+
+ // make the context class loader known to the WebMetaData, ws4ee needs it
+ // to instanciate service endpoint pojos that live in this webapp
+ metaData.setContextLoader(webLoader.getClassLoader());
+
+ Thread currentThread = Thread.currentThread();
+ ClassLoader currentLoader = currentThread.getContextClassLoader();
+ try
+ {
+ // Create a java:comp/env environment unique for the web application
+ log.debug("Creating ENC using ClassLoader: " + loader);
+ ClassLoader parent = loader.getParent();
+ while (parent != null)
+ {
+ log.debug(".." + parent);
+ parent = parent.getParent();
+ }
+ // TODO: The enc should be an input?
+ currentThread.setContextClassLoader(webLoader.getClassLoader());
+ metaData.setENCLoader(webLoader.getClassLoader());
+ InitialContext iniCtx = new InitialContext();
+ Context envCtx = (Context) iniCtx.lookup("java:comp");
+ // Add ORB/UserTransaction
+ ORB orb = null;
+ try
+ {
+ ObjectName ORB_NAME = new ObjectName("jboss:service=CorbaORB");
+ orb = (ORB) server.getAttribute(ORB_NAME, "ORB");
+ // Bind the orb
+ if (orb != null)
+ {
+ NonSerializableFactory.rebind(envCtx, "ORB", orb);
+ log.debug("Bound java:comp/ORB");
+ }
+ }
+ catch (Throwable t)
+ {
+ log.debug("Unable to retrieve orb", t);
+ }
+
+ // TODO: injection, Add a link to the global transaction manager
+ envCtx.bind("UserTransaction", new LinkRef("UserTransaction"));
+ log.debug("Linked java:comp/UserTransaction to JNDI name: UserTransaction");
+ envCtx = envCtx.createSubcontext("env");
+ injectionContainer.populateEnc(webLoader.getClassLoader());
+ // TODO: this should be bindings in the metadata
+ currentThread.setContextClassLoader(webLoader.getClassLoader());
+ String securityDomain = metaData.getSecurityDomain();
+ log.debug("linkSecurityDomain");
+ linkSecurityDomain(securityDomain, envCtx);
+ }
+ catch (Throwable t)
+ {
+ log.error("ENC setup failed", t);
+ }
+ finally
+ {
+ currentThread.setContextClassLoader(currentLoader);
+ }
+
+ log.debug("injectionContainer enabled and processing beginning");
+ // we need to do this because the classloader is initialize by the web container and
+ // the injection container needs the classloader so that it can build up Injectors and ENC populators
+ injectionContainer.setClassLoader(webLoader.getClassLoader());
+ injectionContainer.processMetadata();
+
+ }
+ }
+
+ }
+
public Loader getWebLoader(DeploymentUnit unit, ClassLoader loader, URL url)
throws MalformedURLException
{
More information about the jboss-cvs-commits
mailing list