[jboss-cvs] JBossAS SVN: r58433 - in trunk/tomcat/src/main/org/jboss/web/tomcat/tc6: . deployers
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Nov 15 23:14:59 EST 2006
Author: scott.stark at jboss.org
Date: 2006-11-15 23:14:57 -0500 (Wed, 15 Nov 2006)
New Revision: 58433
Modified:
trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/TomcatInjectionContainer.java
trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployer.java
trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployment.java
Log:
Restore the injection
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/TomcatInjectionContainer.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/TomcatInjectionContainer.java 2006-11-16 03:54:33 UTC (rev 58432)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/TomcatInjectionContainer.java 2006-11-16 04:14:57 UTC (rev 58433)
@@ -21,63 +21,57 @@
*/
package org.jboss.web.tomcat.tc6;
-import org.jboss.deployment.DeploymentInfo;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.apache.AnnotationProcessor;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
import org.jboss.ejb3.Container;
import org.jboss.ejb3.DependencyPolicy;
import org.jboss.ejb3.DeploymentScope;
import org.jboss.ejb3.JmxDependencyPolicy;
-import org.jboss.ejb3.JmxDeploymentScopeImpl;
import org.jboss.ejb3.enc.DeploymentPersistenceUnitResolver;
import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.injection.DependsHandler;
+import org.jboss.injection.EJBHandler;
import org.jboss.injection.EncInjector;
import org.jboss.injection.InjectionContainer;
-import org.jboss.injection.Injector;
import org.jboss.injection.InjectionHandler;
-import org.jboss.injection.EJBHandler;
-import org.jboss.injection.DependsHandler;
+import org.jboss.injection.InjectionUtil;
+import org.jboss.injection.Injector;
import org.jboss.injection.JndiInjectHandler;
import org.jboss.injection.PersistenceContextHandler;
import org.jboss.injection.PersistenceUnitHandler;
import org.jboss.injection.ResourceHandler;
import org.jboss.injection.WebServiceRefHandler;
-import org.jboss.injection.InjectionUtil;
import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+import org.jboss.metamodel.descriptor.Listener;
+import org.jboss.virtual.VirtualFile;
import org.jboss.web.WebApplication;
-import org.jboss.web.AbstractWebContainer;
-import org.jboss.web.metamodel.descriptor.WebDD;
-import org.jboss.web.metamodel.descriptor.WebDDObjectFactory;
+import org.jboss.web.metamodel.descriptor.Filter;
import org.jboss.web.metamodel.descriptor.JBossWebDDObjectFactory;
import org.jboss.web.metamodel.descriptor.Servlet;
-import org.jboss.web.metamodel.descriptor.Filter;
+import org.jboss.web.metamodel.descriptor.WebDD;
+import org.jboss.web.metamodel.descriptor.WebDDObjectFactory;
import org.jboss.xb.binding.JBossXBException;
-import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
-import org.jboss.metamodel.descriptor.Listener;
-import org.apache.AnnotationProcessor;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Collection;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.net.URL;
-
/**
* Comment
*
@@ -131,36 +125,18 @@
protected WarEjbResolver ejbResolver;
protected DependencyPolicy dependencyPolicy = new JmxDependencyPolicy();
protected Collection<InjectionHandler> handlers;
- protected DeploymentInfo di;
+ protected DeploymentUnit unit;
protected ClassLoader webLoader;
- protected AbstractWebContainer.WebDescriptorParser parser;
protected WebApplication appInfo;
- public TomcatInjectionContainer(AbstractWebContainer.WebDescriptorParser parser,
- WebApplication appInfo, DeploymentInfo di)
+ public TomcatInjectionContainer(WebApplication appInfo, DeploymentUnit unit)
{
- this.di = di;
+ this.unit = unit;
DeploymentScope deploymentScope = null;
- this.parser = parser;
this.appInfo = appInfo;
- if (di.parent != null)
- {
- if (di.parent.shortName.endsWith(".ear") || di.parent.shortName.endsWith(".ear/"))
- {
- synchronized (di.parent.context)
- {
- deploymentScope = (DeploymentScope) di.parent.context.get("EJB3_EAR_METADATA");
- if (deploymentScope == null)
- {
- deploymentScope = new JmxDeploymentScopeImpl(di.parent.shortName);
- di.parent.context.put("EJB3_EAR_METADATA", deploymentScope);
- }
- }
- }
- }
persistenceUnitResolver = new DeploymentPersistenceUnitResolver(persistenceUnitDeployments, deploymentScope, ejbContainers);
- ejbResolver = new WarEjbResolver(deploymentScope, di.shortName);
+ ejbResolver = new WarEjbResolver(deploymentScope, unit.getSimpleName());
}
public EnvironmentRefGroup getEnvironmentRefGroup()
@@ -223,7 +199,7 @@
}
}
- public void populateEnc()
+ public void populateEnc(ClassLoader loader)
{
for (EncInjector injector : encInjectors.values())
{
@@ -231,60 +207,32 @@
}
}
- private static InputStream[] getInputStreams(URL warURL)
+ private InputStream[] getInputStreams()
{
InputStream jbossWebIS = null;
InputStream webIS = null;
try
{
- // See if the warUrl is a directory
- File warDir = new File(warURL.getFile());
- if( warURL.getProtocol().equals("file") && warDir.isDirectory() == true )
- {
- File webDD = new File(warDir, "WEB-INF/web.xml");
- if( webDD.exists() == true )
- webIS = new FileInputStream(webDD);
- File jbossWebDD = new File(warDir, "WEB-INF/jboss-web.xml");
- if( jbossWebDD.exists() == true )
- jbossWebIS = new FileInputStream(jbossWebDD);
- }
- else
- {
- // First check for a WEB-INF/web.xml and a WEB-INF/jboss-web.xml
- InputStream warIS = warURL.openStream();
- java.util.zip.ZipInputStream zipIS = new java.util.zip.ZipInputStream(warIS);
- java.util.zip.ZipEntry entry;
- byte[] buffer = new byte[512];
- int bytes;
- while( (entry = zipIS.getNextEntry()) != null )
- {
- if( entry.getName().equals("WEB-INF/web.xml") )
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- while( (bytes = zipIS.read(buffer)) > 0 )
- {
- baos.write(buffer, 0, bytes);
- }
- webIS = new ByteArrayInputStream(baos.toByteArray());
- }
- else if( entry.getName().equals("WEB-INF/jboss-web.xml") )
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- while( (bytes = zipIS.read(buffer)) > 0 )
- {
- baos.write(buffer, 0, bytes);
- }
- jbossWebIS = new ByteArrayInputStream(baos.toByteArray());
- }
- }
- zipIS.close();
- }
+ VirtualFile webDD = unit.getMetaDataFile("web.xml");
+ if (webDD != null)
+ webIS = webDD.openStream();
}
catch (IOException e)
{
- throw new RuntimeException(e);
+ log.debug("Failed to find web.xml");
}
+ try
+ {
+ VirtualFile webDD = unit.getMetaDataFile("jboss-web.xml");
+ if (webDD != null)
+ jbossWebIS = webDD.openStream();
+ }
+ catch (IOException e)
+ {
+ log.debug("Failed to find jboss-web.xml");
+ }
+
InputStream[] streams = {webIS, jbossWebIS};
return streams;
}
@@ -299,9 +247,8 @@
*/
public void processMetadata()
{
- URL warURL = di.localUrl != null ? di.localUrl : di.url;
WebDD xml = null;
- InputStream[] streams = getInputStreams(warURL);
+ InputStream[] streams = getInputStreams();
if (streams[0] != null)
{
try
@@ -335,7 +282,8 @@
handlers.add(new WebServiceRefHandler());
ClassLoader old = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(getClassloader());
+ ClassLoader webLoader = getClassloader();
+ Thread.currentThread().setContextClassLoader(webLoader);
try
{
for (InjectionHandler handler : handlers) handler.loadXml(xml, this);
@@ -345,9 +293,11 @@
Servlet servlet = (Servlet)obj;
try
{
- if (servlet.getServletClass() == null) continue; // jsp
- if (resolvedClassInjections.containsKey(servlet.getServletClass())) continue;
- Class servletClass = getClassloader().loadClass(servlet.getServletClass());
+ if (servlet.getServletClass() == null)
+ continue; // jsp
+ if (resolvedClassInjections.containsKey(servlet.getServletClass()))
+ continue;
+ Class servletClass = webLoader.loadClass(servlet.getServletClass());
Map<AccessibleObject, Injector> tmp = InjectionUtil.processAnnotations(this, handlers, servletClass);
resolvedClassInjections.put(servlet.getServletClass(), tmp);
}
@@ -362,8 +312,9 @@
Filter filter = (Filter)obj;
try
{
- if (resolvedClassInjections.containsKey(filter.getFilterClass())) continue;
- Class servletClass = getClassloader().loadClass(filter.getFilterClass());
+ if (resolvedClassInjections.containsKey(filter.getFilterClass()))
+ continue;
+ Class servletClass = webLoader.loadClass(filter.getFilterClass());
Map<AccessibleObject, Injector> tmp = InjectionUtil.processAnnotations(this, handlers, servletClass);
resolvedClassInjections.put(filter.getFilterClass(), tmp);
}
@@ -377,8 +328,9 @@
Listener listener = (Listener)obj;
try
{
- if (resolvedClassInjections.containsKey(listener.getListenerClass())) continue;
- Class servletClass = getClassloader().loadClass(listener.getListenerClass());
+ if (resolvedClassInjections.containsKey(listener.getListenerClass()))
+ continue;
+ Class servletClass = webLoader.loadClass(listener.getListenerClass());
Map<AccessibleObject, Injector> tmp = InjectionUtil.processAnnotations(this, handlers, servletClass);
resolvedClassInjections.put(listener.getListenerClass(), tmp);
}
@@ -392,23 +344,6 @@
{
Thread.currentThread().setContextClassLoader(old);
}
-
- // We need to establish the JNDI ENC prior to the start
- // of the web container so that init on startup servlets are able
- // to interact with their ENC. We hook into the context lifecycle
- // events to be notified of the start of the
- // context as this occurs before the servlets are started.
- if (appInfo.getAppData() == null)
- {
- try
- {
- parser.parseWebAppDescriptors(getClassloader(), appInfo.getMetaData());
- }
- catch (Exception e)
- {
- throw new RuntimeException("failed to load ENC", e);
- }
- }
}
public Map<String, EncInjector> getEncInjectors()
@@ -430,7 +365,7 @@
public String getIdentifier()
{
- return di.shortName;
+ return unit.getSimpleName();
}
public String getDeploymentDescriptorType()
@@ -545,4 +480,4 @@
return dependencyPolicy;
}
-}
+}
\ No newline at end of file
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployer.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployer.java 2006-11-16 03:54:33 UTC (rev 58432)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployer.java 2006-11-16 04:14:57 UTC (rev 58433)
@@ -51,6 +51,7 @@
import org.jboss.web.deployers.AbstractWarDeployer;
import org.jboss.web.deployers.AbstractWarDeployment;
import org.jboss.web.tomcat.security.HttpServletRequestPolicyContextHandler;
+import org.jboss.web.tomcat.tc6.TomcatInjectionContainer;
import org.jboss.web.tomcat.tc6.session.SessionIDGenerator;
@@ -501,12 +502,12 @@
InitialContext ic = new InitialContext();
try
{
- ic.bind("TomcatAuthenticators", this.authenticators);
+ ic.bind("TomcatAuthenticators", this.authenticators);
}
catch(NamingException ne)
{
- if(log.isTraceEnabled())
- log.trace("Binding Authenticators to JNDI failed",ne);
+ if(log.isTraceEnabled())
+ log.trace("Binding Authenticators to JNDI failed",ne);
}
finally
{
@@ -746,25 +747,11 @@
//Check if there are any xacml policy files
VirtualFile vf = unit.getMetaDataFile("jboss-xacml-policy.xml");
if(vf != null)
- config.setXacmlPolicyURL(vf.toURL());
+ config.setXacmlPolicyURL(vf.toURL());
deployment.setServer(super.getServer());
deployment.init(config);
- /*
- // new JavaEE5 stuff
- WebMetaData metadata = (WebMetaData)di.metaData;
- TomcatInjectionContainer ic = new TomcatInjectionContainer(di);
- URL warURL = di.localUrl != null ? di.localUrl : di.url;
- ClassLoader parent = di.ucl;
- if (di.parent != null) parent = di.parent.ucl;
- ClassLoader tmpLoader = getTmpLoader(warURL, parent, java2ClassLoadingCompliance);
- ic.setClassLoader(tmpLoader);
-
- ic.processMetadata();
- JmxDependencyPolicy dependencyPolicy = (JmxDependencyPolicy)ic.getDependencyPolicy();
- metadata.setDepends(dependencyPolicy.getDependencies(metadata.getDepends()));
- */
return deployment;
}
@@ -781,4 +768,4 @@
if (server != null)
server.unregisterMBean(OBJECT_NAME);
}
-}
+}
\ No newline at end of file
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployment.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployment.java 2006-11-16 03:54:33 UTC (rev 58432)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/TomcatDeployment.java 2006-11-16 04:14:57 UTC (rev 58433)
@@ -1,611 +1,601 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.web.tomcat.tc6.deployers;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.CodeSource;
-import java.security.cert.Certificate;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
-import javax.management.Attribute;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import org.apache.catalina.Loader;
-import org.apache.tomcat.util.modeler.Registry;
-import org.jboss.deployers.spi.deployer.DeploymentUnit;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.WebMetaData;
-import org.jboss.mx.util.MBeanServerLocator;
-import org.jboss.security.AuthorizationManager;
-import org.jboss.security.authorization.PolicyRegistration;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.web.WebApplication;
-import org.jboss.web.deployers.AbstractWarDeployment;
-import org.jboss.web.tomcat.security.JaccContextValve;
-import org.jboss.web.tomcat.security.RunAsListener;
-import org.jboss.web.tomcat.security.SecurityAssociationValve;
-import org.jboss.web.tomcat.tc6.WebAppLoader;
-import org.jboss.web.tomcat.tc6.WebCtxLoader;
-import org.jboss.web.tomcat.tc6.session.AbstractJBossManager;
-import org.jboss.web.tomcat.tc6.session.ClusteringNotSupportedException;
-import org.jboss.web.tomcat.tc6.session.JBossCacheManager;
-import org.omg.CORBA.ORB;
-
-/**
- * A tomcat web application deployment.
- *
- * @author Scott.Stark at jboss.org
- * @author Costin Manolache
- * @version $Revision: 56605 $
- */
-public class TomcatDeployment extends AbstractWarDeployment
-{
- private static final Logger log = Logger.getLogger(TomcatDeployment.class);
-
- /**
- * The name of the war level context configuration descriptor
- */
- private static final String CONTEXT_CONFIG_FILE = "WEB-INF/context.xml";
-
- private DeployerConfig config;
- private String[] javaVMs = { " jboss.management.local:J2EEServer=Local,j2eeType=JVM,name=localhost" };
- private String serverName = "jboss";
- private HashMap vhostToHostNames = new HashMap();
- private ORB orb = null;
- // private TomcatInjectionContainer injectionContainer;
-
- public ORB getORB()
- {
- return orb;
- }
- public void setORB(ORB orb)
- {
- this.orb = orb;
- }
-
- @Override
- public void init(Object containerConfig) throws Exception
- {
- this.config = (DeployerConfig)containerConfig;
- super.setJava2ClassLoadingCompliance(config.isJava2ClassLoadingCompliance());
- super.setUnpackWars(config.isUnpackWars());
- super.setLenientEjbLink(config.isLenientEjbLink());
- super.setDefaultSecurityDomain(config.getDefaultSecurityDomain());
- }
-
- @Override
- protected void performDeploy(WebApplication webApp, String warUrl)
- throws Exception
- {
- webApp.setDomain(config.getCatalinaDomain());
- WebMetaData metaData = webApp.getMetaData();
- String hostName = null;
- // Get any jboss-web/virtual-hosts
- Iterator vhostNames = metaData.getVirtualHosts();
- // Map the virtual hosts onto the configured hosts
- Iterator hostNames = mapVirtualHosts(vhostNames);
- if (hostNames.hasNext())
- {
- hostName = hostNames.next().toString();
- }
- performDeployInternal(hostName, webApp, warUrl);
- while (hostNames.hasNext())
- {
- String additionalHostName = hostNames.next().toString();
- performDeployInternal(additionalHostName, webApp, warUrl);
- }
- }
-
- protected void performDeployInternal(String hostName,
- WebApplication webApp, String warUrl) throws Exception
- {
-
- WebMetaData metaData = webApp.getMetaData();
- String ctxPath = metaData.getContextRoot();
- if (ctxPath.equals("/") || ctxPath.equals("/ROOT") || ctxPath.equals(""))
- {
- log.debug("deploy root context=" + ctxPath);
- ctxPath = "/";
- metaData.setContextRoot(ctxPath);
- }
-
- log.info("deploy, ctxPath=" + ctxPath + ", warUrl="
- + shortWarUrlFromServerHome(warUrl));
-
- URL url = new URL(warUrl);
-
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- metaData.setContextLoader(loader);
-
- // injectionContainer = new TomcatInjectionContainer(webAppParser, appInfo);
- Loader webLoader = webApp.getDeploymentUnit().getAttachment(Loader.class);
- if( webLoader == null )
- webLoader = getWebLoader(webApp.getDeploymentUnit(), loader, url);
-
- webApp.setName(url.getPath());
- webApp.setClassLoader(loader);
- webApp.setURL(url);
-
- String objectNameS = config.getCatalinaDomain() + ":j2eeType=WebModule,name=//"
- + ((hostName == null) ? "localhost" : hostName) + ctxPath
- + ",J2EEApplication=none,J2EEServer=none";
-
- ObjectName objectName = new ObjectName(objectNameS);
-
- /*
- * server.createMBean("org.apache.tomcat.util.modeler.BaseModelMBean",
- * objectName, new Object[]{warInfo.getContextClassName()}, new
- * String[]{"java.lang.String"});
- */
- String contextClassName = config.getContextClassName();
- Registry.getRegistry().registerComponent(
- Class.forName(contextClassName).newInstance(), objectName,
- contextClassName);
-
- // Find and set warInfo file on the context
- // If WAR is packed, expand warInfo file to temp folder
- String ctxConfig = null;
- try
- {
- // TODO: this should be input metadata
- ctxConfig = findConfig(url);
- } catch (IOException e)
- {
- log.debug("No " + CONTEXT_CONFIG_FILE + " in " + url, e);
- }
-
- /*
- * TODO:
- * if (injectionContainer != null) { server.setAttribute(objectName, new
- * Attribute("annotationProcessor", injectionContainer)); }
- */
-
- server.setAttribute(objectName, new Attribute("docBase", url.getFile()));
-
- server.setAttribute(objectName, new Attribute("configFile", ctxConfig));
-
- server.setAttribute(objectName, new Attribute("defaultContextXml",
- "context.xml"));
- server.setAttribute(objectName, new Attribute("defaultWebXml",
- "conf/web.xml"));
- // If there is an alt-dd set it
- if( metaData.getAltDDPath() != null )
- {
- String altPath = metaData.getAltDDPath();
- log.debug("Setting altDDName to: "+altPath);
- server.setAttribute(objectName, new Attribute("altDDName", altPath));
- }
-
- server.setAttribute(objectName, new Attribute("javaVMs", javaVMs));
-
- server.setAttribute(objectName, new Attribute("server", serverName));
-
- server.setAttribute(objectName,
- new Attribute("saveConfig", Boolean.FALSE));
-
- if (webLoader != null)
- {
- server.setAttribute(objectName, new Attribute("loader", webLoader));
- } else
- {
- server.setAttribute(objectName, new Attribute("parentClassLoader",
- loader));
- }
-
- server.setAttribute(objectName, new Attribute("delegate", new Boolean(
- webApp.getJava2ClassLoadingCompliance())));
-
- String[] jspCP = getCompileClasspath(loader);
- StringBuffer classpath = new StringBuffer();
- for (int u = 0; u < jspCP.length; u++)
- {
- String repository = jspCP[u];
- if (repository == null)
- continue;
- if (repository.startsWith("file://"))
- repository = repository.substring(7);
- else if (repository.startsWith("file:"))
- repository = repository.substring(5);
- else
- continue;
- if (repository == null)
- continue;
- // ok it is a file. Make sure that is is a directory or jar file
- File fp = new File(repository);
- if (!fp.isDirectory())
- {
- // if it is not a directory, try to open it as a zipfile.
- try
- {
- // avoid opening .xml files
- if (fp.getName().toLowerCase().endsWith(".xml"))
- continue;
-
- ZipFile zip = new ZipFile(fp);
- zip.close();
- } catch (IOException e)
- {
- continue;
- }
-
- }
- if (u > 0)
- classpath.append(File.pathSeparator);
- classpath.append(repository);
- }
-
- server.setAttribute(objectName, new Attribute("compilerClasspath",
- classpath.toString()));
-
- // Set the session cookies flag according to metadata
- switch (metaData.getSessionCookies())
- {
- case WebMetaData.SESSION_COOKIES_ENABLED:
- server.setAttribute(objectName, new Attribute("cookies", new Boolean(
- true)));
- log.debug("Enabling session cookies");
- break;
- case WebMetaData.SESSION_COOKIES_DISABLED:
- server.setAttribute(objectName, new Attribute("cookies", new Boolean(
- false)));
- log.debug("Disabling session cookies");
- break;
- default:
- log.debug("Using session cookies default setting");
- }
-
- // Add a valve to estalish the JACC context before authorization valves
- Certificate[] certs = null;
- CodeSource cs = new CodeSource(url, certs);
- JaccContextValve jaccValve = new JaccContextValve(metaData
- .getJaccContextID(), cs);
- server.invoke(objectName, "addValve", new Object[] { jaccValve },
- new String[] { "org.apache.catalina.Valve" });
-
- // Pass the metadata to the RunAsListener via a thread local
- RunAsListener.metaDataLocal.set(metaData);
- try
- {
- // Init the container; this will also start it
- server.invoke(objectName, "init", new Object[] {}, new String[] {});
- }
- finally
- {
- RunAsListener.metaDataLocal.set(null);
- }
-
- // make the context class loader known to the WebMetaData, ws4ee needs it
- // to instanciate service endpoint pojos that live in this webapp
- Loader ctxLoader = (Loader) server.getAttribute(objectName, "loader");
- metaData.setContextLoader(ctxLoader.getClassLoader());
-
- // Build the ENC
- super.processEnc(webLoader.getClassLoader(), webApp);
-
- // Start it
- server.invoke(objectName, "start", new Object[]{},
- new String[]{});
-
- // Clustering
- if (metaData.getDistributable())
- {
- // Try to initate clustering, fallback to standard if no clustering is
- // available
- try
- {
- AbstractJBossManager manager = null;
- String managerClassName = config.getManagerClass();
- Class managerClass = Thread.currentThread().getContextClassLoader()
- .loadClass(managerClassName);
- manager = (AbstractJBossManager) managerClass.newInstance();
- String name = "//" + ((hostName == null) ? "localhost" : hostName)
- + ctxPath;
- manager.init(name, metaData, config.isUseJK(), config
- .isUseLocalCache());
-
- if (manager instanceof JBossCacheManager)
- {
- String snapshotMode = config.getSnapshotMode();
- int snapshotInterval = config.getSnapshotInterval();
- JBossCacheManager jbcm = (JBossCacheManager) manager;
- jbcm.setSnapshotMode(snapshotMode);
- jbcm.setSnapshotInterval(snapshotInterval);
- }
-
- server.setAttribute(objectName, new Attribute("manager", manager));
-
- log.debug("Enabled clustering support for ctxPath=" + ctxPath);
- }
- catch (ClusteringNotSupportedException e)
- {
- // JBAS-3513 Just log a WARN, not an ERROR
- log.warn("Failed to setup clustering, clustering disabled. ClusteringNotSupportedException: "
- + e.getMessage());
- }
- catch (NoClassDefFoundError ncdf)
- {
- // JBAS-3513 Just log a WARN, not an ERROR
- log.debug("Classes needed for clustered webapp unavailable", ncdf);
- log.warn("Failed to setup clustering, clustering disabled. NoClassDefFoundError: "
- + ncdf.getMessage());
- }
- catch (Throwable t)
- {
- // TODO consider letting this through and fail the deployment
- log.error("Failed to setup clustering, clustering disabled. Exception: ", t);
- }
- }
-
- /*
- * Add security association valve after the authorization valves so that
- * the authenticated user may be associated with the request
- * thread/session.
- */
- SecurityAssociationValve valve = new SecurityAssociationValve(metaData,
- config.getSecurityManagerService());
- valve.setSubjectAttributeName(config.getSubjectAttributeName());
- server.invoke(objectName, "addValve", new Object[] { valve },
- new String[] { "org.apache.catalina.Valve" });
-
- /* TODO: Retrieve the state, and throw an exception in case of a failure
- Integer state = (Integer) server.getAttribute(objectName, "state");
- if (state.intValue() != 1)
- {
- throw new DeploymentException("URL " + warUrl + " deployment failed");
- }
- */
-
- webApp.setAppData(objectName);
-
- /*
- * TODO: Create mbeans for the servlets ObjectName servletQuery = new
- * ObjectName (config.getCatalinaDomain() + ":j2eeType=Servlet,WebModule=" +
- * objectName.getKeyProperty("name") + ",*"); Iterator iterator =
- * server.queryMBeans(servletQuery, null).iterator(); while
- * (iterator.hasNext()) {
- * di.mbeans.add(((ObjectInstance)iterator.next()).getObjectName()); }
- */
-
- if (metaData.getSecurityDomain() != null)
- {
- String secDomain = org.jboss.security.Util
- .unprefixSecurityDomain(metaData.getSecurityDomain());
- // Associate the Context Id with the Security Domain
- String contextID = metaData.getJaccContextID();
-
- //Check if an xacml policy file is present
- URL xacmlPolicyFile = this.config.getXacmlPolicyURL();
- if (xacmlPolicyFile != null)
- {
- AuthorizationManager authzmgr = org.jboss.security.Util
- .getAuthorizationManager(secDomain);
- if (authzmgr instanceof PolicyRegistration)
- {
- PolicyRegistration xam = (PolicyRegistration) authzmgr;
- xam.registerPolicy(contextID, xacmlPolicyFile);
- }
- }
- }
-
- log.debug("Initialized: " + webApp + " " + objectName);
- }
-
- public Loader getWebLoader(DeploymentUnit unit, ClassLoader loader, URL url)
- throws MalformedURLException
- {
- Loader webLoader = null;
-
- /*
- * If we are using the jboss class loader we need to augment its path to
- * include the WEB-INF/{lib,classes} dirs or else scoped class loading
- * does not see the war level overrides. The call to setWarURL adds these
- * paths to the deployment UCL.
- */
- ArrayList<URL> classpath = (ArrayList<URL>) unit.getAttachment("org.jboss.web.expandedWarClasspath");
- if (config.isUseJBossWebLoader())
- {
- WebCtxLoader jbossLoader = new WebCtxLoader(loader/*
- * ,
- * injectionContainer
- */);
- if( classpath != null )
- jbossLoader.setClasspath(classpath);
- webLoader = jbossLoader;
- }
- else
- {
- String[] pkgs = config.getFilteredPackages();
- WebAppLoader jbossLoader = new WebAppLoader(loader, pkgs/*
- * ,
- * injectionContainer
- */);
- jbossLoader.setDelegate(getJava2ClassLoadingCompliance());
- if( classpath != null )
- jbossLoader.setClasspath(classpath);
- webLoader = jbossLoader;
- }
- return webLoader;
- }
-
- /*
- * public void setInjectionContainer(TomcatInjectionContainer container) {
- * this.injectionContainer = container; }
- */
-
- /**
- * Called as part of the undeploy() method template to ask the subclass for
- * perform the web container specific undeployment steps.
- */
- protected void performUndeploy(WebApplication warInfo, String warUrl)
- throws Exception
- {
- if (warInfo == null)
- {
- log
- .debug("performUndeploy, no WebApplication found for URL "
- + warUrl);
- return;
- }
-
- log.info("undeploy, ctxPath=" + warInfo.getMetaData().getContextRoot()
- + ", warUrl=" + shortWarUrlFromServerHome(warUrl));
-
- WebMetaData metaData = warInfo.getMetaData();
- String hostName = null;
- Iterator hostNames = metaData.getVirtualHosts();
- if (hostNames.hasNext())
- {
- hostName = hostNames.next().toString();
- }
- performUndeployInternal(hostName, warUrl, warInfo);
- while (hostNames.hasNext())
- {
- String additionalHostName = hostNames.next().toString();
- performUndeployInternal(additionalHostName, warUrl, warInfo);
- }
-
- }
-
- protected void performUndeployInternal(String hostName, String warUrl,
- WebApplication warInfo) throws Exception
- {
-
- WebMetaData metaData = warInfo.getMetaData();
- String ctxPath = metaData.getContextRoot();
-
- // TODO: Need to remove the dependency on MBeanServer
- MBeanServer server = MBeanServerLocator.locateJBoss();
- // If the server is gone, all apps were stopped already
- if (server == null)
- return;
-
- ObjectName objectName = new ObjectName(config.getCatalinaDomain()
- + ":j2eeType=WebModule,name=//"
- + ((hostName == null) ? "localhost" : hostName) + ctxPath
- + ",J2EEApplication=none,J2EEServer=none");
-
- if (server.isRegistered(objectName))
- {
- // Contexts should be stopped by the host already
- server.invoke(objectName, "destroy", new Object[] {}, new String[] {});
- }
-
- }
-
- /**
- * Resolve the input virtual host names to the names of the configured Hosts
- * @param vhostNames Iterator<String> for the jboss-web/virtual-host elements
- * @return Iterator<String> of the unique Host names
- * @throws Exception
- */
- protected synchronized Iterator mapVirtualHosts(Iterator vhostNames)
- throws Exception
- {
- if (vhostToHostNames.size() == 0)
- {
- // Query the configured Host mbeans
- String hostQuery = config.getCatalinaDomain() + ":type=Host,*";
- ObjectName query = new ObjectName(hostQuery);
- Set hosts = server.queryNames(query, null);
- Iterator iter = hosts.iterator();
- while (iter.hasNext())
- {
- ObjectName host = (ObjectName)iter.next();
- String name = host.getKeyProperty("host");
- if (name != null)
- {
- vhostToHostNames.put(name, name);
- String[] aliases = (String[])
- server.invoke(host, "findAliases", null, null);
- int count = aliases != null ? aliases.length : 0;
- for (int n = 0; n < count; n++)
- {
- vhostToHostNames.put(aliases[n], name);
- }
- }
- }
- }
-
- // Map the virtual host names to the hosts
- HashSet hosts = new HashSet();
- while (vhostNames.hasNext())
- {
- String vhost = (String)vhostNames.next();
- String host = (String)vhostToHostNames.get(vhost);
- if (host == null)
- {
- log.warn("Failed to map vhost: " + vhost);
- // This will cause a new host to be created
- host = vhost;
- }
- hosts.add(host);
- }
- return hosts.iterator();
- }
-
- private String findConfig(URL warURL) throws IOException
- {
- String result = null;
- // See if the warUrl is a dir or a file
- File warFile = new File(warURL.getFile());
- if (warURL.getProtocol().equals("file") && warFile.isDirectory() == true)
- {
- File webDD = new File(warFile, CONTEXT_CONFIG_FILE);
- if (webDD.exists() == true)
- result = webDD.getAbsolutePath();
- } else
- {
- ZipFile zipFile = new ZipFile(warFile);
- ZipEntry entry = zipFile.getEntry(CONTEXT_CONFIG_FILE);
- if (entry != null)
- {
- InputStream zipIS = zipFile.getInputStream(entry);
- byte[] buffer = new byte[512];
- int bytes;
- result = warFile.getAbsolutePath() + "-context.xml";
- FileOutputStream fos = new FileOutputStream(result);
- while ((bytes = zipIS.read(buffer)) > 0)
- {
- fos.write(buffer, 0, bytes);
- }
- zipIS.close();
- fos.close();
- }
- zipFile.close();
- }
- return result;
- }
-
-}
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.tc6.deployers;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.CodeSource;
+import java.security.cert.Certificate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import javax.management.Attribute;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.catalina.Loader;
+import org.apache.tomcat.util.modeler.Registry;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.WebMetaData;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.security.AuthorizationManager;
+import org.jboss.security.authorization.PolicyRegistration;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.web.WebApplication;
+import org.jboss.web.deployers.AbstractWarDeployment;
+import org.jboss.web.tomcat.security.JaccContextValve;
+import org.jboss.web.tomcat.security.RunAsListener;
+import org.jboss.web.tomcat.security.SecurityAssociationValve;
+import org.jboss.web.tomcat.tc6.TomcatInjectionContainer;
+import org.jboss.web.tomcat.tc6.WebAppLoader;
+import org.jboss.web.tomcat.tc6.WebCtxLoader;
+import org.jboss.web.tomcat.tc6.session.AbstractJBossManager;
+import org.jboss.web.tomcat.tc6.session.ClusteringNotSupportedException;
+import org.jboss.web.tomcat.tc6.session.JBossCacheManager;
+import org.omg.CORBA.ORB;
+
+/**
+ * A tomcat web application deployment.
+ *
+ * @author Scott.Stark at jboss.org
+ * @author Costin Manolache
+ * @version $Revision: 56605 $
+ */
+public class TomcatDeployment extends AbstractWarDeployment
+{
+ private static final Logger log = Logger.getLogger(TomcatDeployment.class);
+
+ /**
+ * The name of the war level context configuration descriptor
+ */
+ private static final String CONTEXT_CONFIG_FILE = "WEB-INF/context.xml";
+
+ private DeployerConfig config;
+ private String[] javaVMs = { " jboss.management.local:J2EEServer=Local,j2eeType=JVM,name=localhost" };
+ private String serverName = "jboss";
+ private HashMap vhostToHostNames = new HashMap();
+ private ORB orb = null;
+ private TomcatInjectionContainer injectionContainer;
+
+ public ORB getORB()
+ {
+ return orb;
+ }
+ public void setORB(ORB orb)
+ {
+ this.orb = orb;
+ }
+
+ @Override
+ public void init(Object containerConfig) throws Exception
+ {
+ this.config = (DeployerConfig)containerConfig;
+ super.setJava2ClassLoadingCompliance(config.isJava2ClassLoadingCompliance());
+ super.setUnpackWars(config.isUnpackWars());
+ super.setLenientEjbLink(config.isLenientEjbLink());
+ super.setDefaultSecurityDomain(config.getDefaultSecurityDomain());
+ }
+
+ @Override
+ protected void performDeploy(WebApplication webApp, String warUrl)
+ throws Exception
+ {
+ webApp.setDomain(config.getCatalinaDomain());
+ WebMetaData metaData = webApp.getMetaData();
+ String hostName = null;
+ // Get any jboss-web/virtual-hosts
+ Iterator vhostNames = metaData.getVirtualHosts();
+ // Map the virtual hosts onto the configured hosts
+ Iterator hostNames = mapVirtualHosts(vhostNames);
+ if (hostNames.hasNext())
+ {
+ hostName = hostNames.next().toString();
+ }
+ performDeployInternal(hostName, webApp, warUrl);
+ while (hostNames.hasNext())
+ {
+ String additionalHostName = hostNames.next().toString();
+ performDeployInternal(additionalHostName, webApp, warUrl);
+ }
+ }
+
+ protected void performDeployInternal(String hostName,
+ WebApplication webApp, String warUrl) throws Exception
+ {
+
+ WebMetaData metaData = webApp.getMetaData();
+ String ctxPath = metaData.getContextRoot();
+ if (ctxPath.equals("/") || ctxPath.equals("/ROOT") || ctxPath.equals(""))
+ {
+ log.debug("deploy root context=" + ctxPath);
+ ctxPath = "/";
+ metaData.setContextRoot(ctxPath);
+ }
+
+ log.info("deploy, ctxPath=" + ctxPath + ", warUrl="
+ + shortWarUrlFromServerHome(warUrl));
+
+ URL url = new URL(warUrl);
+
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ metaData.setContextLoader(loader);
+
+ injectionContainer = new TomcatInjectionContainer(webApp, webApp.getDeploymentUnit());
+
+ Loader webLoader = webApp.getDeploymentUnit().getAttachment(Loader.class);
+ if( webLoader == null )
+ webLoader = getWebLoader(webApp.getDeploymentUnit(), loader, url);
+
+ webApp.setName(url.getPath());
+ webApp.setClassLoader(loader);
+ webApp.setURL(url);
+
+ String objectNameS = config.getCatalinaDomain() + ":j2eeType=WebModule,name=//"
+ + ((hostName == null) ? "localhost" : hostName) + ctxPath
+ + ",J2EEApplication=none,J2EEServer=none";
+
+ ObjectName objectName = new ObjectName(objectNameS);
+
+ String contextClassName = config.getContextClassName();
+ Registry.getRegistry().registerComponent(
+ Class.forName(contextClassName).newInstance(), objectName,
+ contextClassName);
+
+ // Find and set warInfo file on the context
+ // If WAR is packed, expand warInfo file to temp folder
+ String ctxConfig = null;
+ try
+ {
+ // TODO: this should be input metadata
+ ctxConfig = findConfig(url);
+ } catch (IOException e)
+ {
+ log.debug("No " + CONTEXT_CONFIG_FILE + " in " + url, e);
+ }
+
+ if (injectionContainer != null)
+ {
+ server.setAttribute(objectName, new Attribute("annotationProcessor", injectionContainer));
+ }
+
+ server.setAttribute(objectName, new Attribute("docBase", url.getFile()));
+
+ server.setAttribute(objectName, new Attribute("configFile", ctxConfig));
+
+ server.setAttribute(objectName, new Attribute("defaultContextXml",
+ "context.xml"));
+ server.setAttribute(objectName, new Attribute("defaultWebXml",
+ "conf/web.xml"));
+ // If there is an alt-dd set it
+ if( metaData.getAltDDPath() != null )
+ {
+ String altPath = metaData.getAltDDPath();
+ log.debug("Setting altDDName to: "+altPath);
+ server.setAttribute(objectName, new Attribute("altDDName", altPath));
+ }
+
+ server.setAttribute(objectName, new Attribute("javaVMs", javaVMs));
+
+ server.setAttribute(objectName, new Attribute("server", serverName));
+
+ server.setAttribute(objectName,
+ new Attribute("saveConfig", Boolean.FALSE));
+
+ if (webLoader != null)
+ {
+ server.setAttribute(objectName, new Attribute("loader", webLoader));
+ } else
+ {
+ server.setAttribute(objectName, new Attribute("parentClassLoader",
+ loader));
+ }
+
+ server.setAttribute(objectName, new Attribute("delegate", new Boolean(
+ webApp.getJava2ClassLoadingCompliance())));
+
+ String[] jspCP = getCompileClasspath(loader);
+ StringBuffer classpath = new StringBuffer();
+ for (int u = 0; u < jspCP.length; u++)
+ {
+ String repository = jspCP[u];
+ if (repository == null)
+ continue;
+ if (repository.startsWith("file://"))
+ repository = repository.substring(7);
+ else if (repository.startsWith("file:"))
+ repository = repository.substring(5);
+ else
+ continue;
+ if (repository == null)
+ continue;
+ // ok it is a file. Make sure that is is a directory or jar file
+ File fp = new File(repository);
+ if (!fp.isDirectory())
+ {
+ // if it is not a directory, try to open it as a zipfile.
+ try
+ {
+ // avoid opening .xml files
+ if (fp.getName().toLowerCase().endsWith(".xml"))
+ continue;
+
+ ZipFile zip = new ZipFile(fp);
+ zip.close();
+ } catch (IOException e)
+ {
+ continue;
+ }
+
+ }
+ if (u > 0)
+ classpath.append(File.pathSeparator);
+ classpath.append(repository);
+ }
+
+ server.setAttribute(objectName, new Attribute("compilerClasspath",
+ classpath.toString()));
+
+ // Set the session cookies flag according to metadata
+ switch (metaData.getSessionCookies())
+ {
+ case WebMetaData.SESSION_COOKIES_ENABLED:
+ server.setAttribute(objectName, new Attribute("cookies", new Boolean(
+ true)));
+ log.debug("Enabling session cookies");
+ break;
+ case WebMetaData.SESSION_COOKIES_DISABLED:
+ server.setAttribute(objectName, new Attribute("cookies", new Boolean(
+ false)));
+ log.debug("Disabling session cookies");
+ break;
+ default:
+ log.debug("Using session cookies default setting");
+ }
+
+ // Add a valve to estalish the JACC context before authorization valves
+ Certificate[] certs = null;
+ CodeSource cs = new CodeSource(url, certs);
+ JaccContextValve jaccValve = new JaccContextValve(metaData
+ .getJaccContextID(), cs);
+ server.invoke(objectName, "addValve", new Object[] { jaccValve },
+ new String[] { "org.apache.catalina.Valve" });
+
+ // Pass the metadata to the RunAsListener via a thread local
+ RunAsListener.metaDataLocal.set(metaData);
+ try
+ {
+ // Init the container; this will also start it
+ server.invoke(objectName, "init", new Object[] {}, new String[] {});
+ }
+ finally
+ {
+ RunAsListener.metaDataLocal.set(null);
+ }
+
+ // make the context class loader known to the WebMetaData, ws4ee needs it
+ // to instanciate service endpoint pojos that live in this webapp
+ Loader ctxLoader = (Loader) server.getAttribute(objectName, "loader");
+ metaData.setContextLoader(ctxLoader.getClassLoader());
+
+ // Start it
+ server.invoke(objectName, "start", new Object[]{},
+ new String[]{});
+ // Build the ENC
+ if (injectionContainer == null)
+ super.processEnc(webLoader.getClassLoader(), webApp);
+ else
+ injectionContainer.populateEnc(webLoader.getClassLoader());
+
+ // Clustering
+ if (metaData.getDistributable())
+ {
+ // Try to initate clustering, fallback to standard if no clustering is
+ // available
+ try
+ {
+ AbstractJBossManager manager = null;
+ String managerClassName = config.getManagerClass();
+ Class managerClass = Thread.currentThread().getContextClassLoader()
+ .loadClass(managerClassName);
+ manager = (AbstractJBossManager) managerClass.newInstance();
+ String name = "//" + ((hostName == null) ? "localhost" : hostName)
+ + ctxPath;
+ manager.init(name, metaData, config.isUseJK(), config
+ .isUseLocalCache());
+
+ if (manager instanceof JBossCacheManager)
+ {
+ String snapshotMode = config.getSnapshotMode();
+ int snapshotInterval = config.getSnapshotInterval();
+ JBossCacheManager jbcm = (JBossCacheManager) manager;
+ jbcm.setSnapshotMode(snapshotMode);
+ jbcm.setSnapshotInterval(snapshotInterval);
+ }
+
+ server.setAttribute(objectName, new Attribute("manager", manager));
+
+ log.debug("Enabled clustering support for ctxPath=" + ctxPath);
+ }
+ catch (ClusteringNotSupportedException e)
+ {
+ // JBAS-3513 Just log a WARN, not an ERROR
+ log.warn("Failed to setup clustering, clustering disabled. ClusteringNotSupportedException: "
+ + e.getMessage());
+ }
+ catch (NoClassDefFoundError ncdf)
+ {
+ // JBAS-3513 Just log a WARN, not an ERROR
+ log.debug("Classes needed for clustered webapp unavailable", ncdf);
+ log.warn("Failed to setup clustering, clustering disabled. NoClassDefFoundError: "
+ + ncdf.getMessage());
+ }
+ catch (Throwable t)
+ {
+ // TODO consider letting this through and fail the deployment
+ log.error("Failed to setup clustering, clustering disabled. Exception: ", t);
+ }
+ }
+
+ /*
+ * Add security association valve after the authorization valves so that
+ * the authenticated user may be associated with the request
+ * thread/session.
+ */
+ SecurityAssociationValve valve = new SecurityAssociationValve(metaData,
+ config.getSecurityManagerService());
+ valve.setSubjectAttributeName(config.getSubjectAttributeName());
+ server.invoke(objectName, "addValve", new Object[] { valve },
+ new String[] { "org.apache.catalina.Valve" });
+
+ /* TODO: Retrieve the state, and throw an exception in case of a failure
+ Integer state = (Integer) server.getAttribute(objectName, "state");
+ if (state.intValue() != 1)
+ {
+ throw new DeploymentException("URL " + warUrl + " deployment failed");
+ }
+ */
+
+ webApp.setAppData(objectName);
+
+ /*
+ * TODO: Create mbeans for the servlets ObjectName servletQuery = new
+ * ObjectName (config.getCatalinaDomain() + ":j2eeType=Servlet,WebModule=" +
+ * objectName.getKeyProperty("name") + ",*"); Iterator iterator =
+ * server.queryMBeans(servletQuery, null).iterator(); while
+ * (iterator.hasNext()) {
+ * di.mbeans.add(((ObjectInstance)iterator.next()).getObjectName()); }
+ */
+
+ if (metaData.getSecurityDomain() != null)
+ {
+ String secDomain = org.jboss.security.Util
+ .unprefixSecurityDomain(metaData.getSecurityDomain());
+ // Associate the Context Id with the Security Domain
+ String contextID = metaData.getJaccContextID();
+
+ //Check if an xacml policy file is present
+ URL xacmlPolicyFile = this.config.getXacmlPolicyURL();
+ if (xacmlPolicyFile != null)
+ {
+ AuthorizationManager authzmgr = org.jboss.security.Util
+ .getAuthorizationManager(secDomain);
+ if (authzmgr instanceof PolicyRegistration)
+ {
+ PolicyRegistration xam = (PolicyRegistration) authzmgr;
+ xam.registerPolicy(contextID, xacmlPolicyFile);
+ }
+ }
+ }
+
+ log.debug("Initialized: " + webApp + " " + objectName);
+ }
+
+ public Loader getWebLoader(DeploymentUnit unit, ClassLoader loader, URL url)
+ throws MalformedURLException
+ {
+ Loader webLoader = null;
+
+ /*
+ * If we are using the jboss class loader we need to augment its path to
+ * include the WEB-INF/{lib,classes} dirs or else scoped class loading
+ * does not see the war level overrides. The call to setWarURL adds these
+ * paths to the deployment UCL.
+ */
+ ArrayList<URL> classpath = (ArrayList<URL>) unit.getAttachment("org.jboss.web.expandedWarClasspath");
+ if (config.isUseJBossWebLoader())
+ {
+ WebCtxLoader jbossLoader = new WebCtxLoader(loader, injectionContainer);
+ if( classpath != null )
+ jbossLoader.setClasspath(classpath);
+ webLoader = jbossLoader;
+ }
+ else
+ {
+ String[] pkgs = config.getFilteredPackages();
+ WebAppLoader jbossLoader = new WebAppLoader(loader, pkgs, injectionContainer);
+ jbossLoader.setDelegate(getJava2ClassLoadingCompliance());
+ if( classpath != null )
+ jbossLoader.setClasspath(classpath);
+ webLoader = jbossLoader;
+ }
+ return webLoader;
+ }
+
+ public void setInjectionContainer(TomcatInjectionContainer container)
+ {
+ this.injectionContainer = container;
+ }
+
+ /**
+ * Called as part of the undeploy() method template to ask the subclass for
+ * perform the web container specific undeployment steps.
+ */
+ protected void performUndeploy(WebApplication warInfo, String warUrl)
+ throws Exception
+ {
+ if (warInfo == null)
+ {
+ log.debug("performUndeploy, no WebApplication found for URL "+ warUrl);
+ return;
+ }
+
+ log.info("undeploy, ctxPath=" + warInfo.getMetaData().getContextRoot()
+ + ", warUrl=" + shortWarUrlFromServerHome(warUrl));
+
+ WebMetaData metaData = warInfo.getMetaData();
+ String hostName = null;
+ Iterator hostNames = metaData.getVirtualHosts();
+ if (hostNames.hasNext())
+ {
+ hostName = hostNames.next().toString();
+ }
+ performUndeployInternal(hostName, warUrl, warInfo);
+ while (hostNames.hasNext())
+ {
+ String additionalHostName = hostNames.next().toString();
+ performUndeployInternal(additionalHostName, warUrl, warInfo);
+ }
+
+ }
+
+ protected void performUndeployInternal(String hostName, String warUrl,
+ WebApplication warInfo) throws Exception
+ {
+
+ WebMetaData metaData = warInfo.getMetaData();
+ String ctxPath = metaData.getContextRoot();
+
+ // TODO: Need to remove the dependency on MBeanServer
+ MBeanServer server = MBeanServerLocator.locateJBoss();
+ // If the server is gone, all apps were stopped already
+ if (server == null)
+ return;
+
+ ObjectName objectName = new ObjectName(config.getCatalinaDomain()
+ + ":j2eeType=WebModule,name=//"
+ + ((hostName == null) ? "localhost" : hostName) + ctxPath
+ + ",J2EEApplication=none,J2EEServer=none");
+
+ if (server.isRegistered(objectName))
+ {
+ // Contexts should be stopped by the host already
+ server.invoke(objectName, "destroy", new Object[] {}, new String[] {});
+ }
+
+ }
+
+ /**
+ * Resolve the input virtual host names to the names of the configured Hosts
+ * @param vhostNames Iterator<String> for the jboss-web/virtual-host elements
+ * @return Iterator<String> of the unique Host names
+ * @throws Exception
+ */
+ protected synchronized Iterator mapVirtualHosts(Iterator vhostNames)
+ throws Exception
+ {
+ if (vhostToHostNames.size() == 0)
+ {
+ // Query the configured Host mbeans
+ String hostQuery = config.getCatalinaDomain() + ":type=Host,*";
+ ObjectName query = new ObjectName(hostQuery);
+ Set hosts = server.queryNames(query, null);
+ Iterator iter = hosts.iterator();
+ while (iter.hasNext())
+ {
+ ObjectName host = (ObjectName)iter.next();
+ String name = host.getKeyProperty("host");
+ if (name != null)
+ {
+ vhostToHostNames.put(name, name);
+ String[] aliases = (String[])
+ server.invoke(host, "findAliases", null, null);
+ int count = aliases != null ? aliases.length : 0;
+ for (int n = 0; n < count; n++)
+ {
+ vhostToHostNames.put(aliases[n], name);
+ }
+ }
+ }
+ }
+
+ // Map the virtual host names to the hosts
+ HashSet hosts = new HashSet();
+ while (vhostNames.hasNext())
+ {
+ String vhost = (String)vhostNames.next();
+ String host = (String)vhostToHostNames.get(vhost);
+ if (host == null)
+ {
+ log.warn("Failed to map vhost: " + vhost);
+ // This will cause a new host to be created
+ host = vhost;
+ }
+ hosts.add(host);
+ }
+ return hosts.iterator();
+ }
+
+ private String findConfig(URL warURL) throws IOException
+ {
+ String result = null;
+ // See if the warUrl is a dir or a file
+ File warFile = new File(warURL.getFile());
+ if (warURL.getProtocol().equals("file") && warFile.isDirectory() == true)
+ {
+ File webDD = new File(warFile, CONTEXT_CONFIG_FILE);
+ if (webDD.exists() == true)
+ result = webDD.getAbsolutePath();
+ } else
+ {
+ ZipFile zipFile = new ZipFile(warFile);
+ ZipEntry entry = zipFile.getEntry(CONTEXT_CONFIG_FILE);
+ if (entry != null)
+ {
+ InputStream zipIS = zipFile.getInputStream(entry);
+ byte[] buffer = new byte[512];
+ int bytes;
+ result = warFile.getAbsolutePath() + "-context.xml";
+ FileOutputStream fos = new FileOutputStream(result);
+ while ((bytes = zipIS.read(buffer)) > 0)
+ {
+ fos.write(buffer, 0, bytes);
+ }
+ zipIS.close();
+ fos.close();
+ }
+ zipFile.close();
+ }
+ return result;
+ }
+
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list