[jboss-cvs] JBossAS SVN: r107892 - trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 30 13:57:51 EDT 2010
Author: remy.maucherat at jboss.com
Date: 2010-08-30 13:57:50 -0400 (Mon, 30 Aug 2010)
New Revision: 107892
Modified:
trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatService.java
Log:
- Focus on adding aliases to an existing vhost if needed.
- Deployment will fail if a webapp is associated with more than one vhost.
- Multiple services are no longer allowed.
Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java 2010-08-30 16:24:51 UTC (rev 107891)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java 2010-08-30 17:57:50 UTC (rev 107892)
@@ -119,29 +119,23 @@
warUrl = URLDecoder.decode(warUrl, "UTF-8");
webApp.setDomain(config.getCatalinaDomain());
JBossWebMetaData metaData = webApp.getMetaData();
- String hostName = null;
// Get any jboss-web/virtual-hosts
List<String> vhostNames = metaData.getVirtualHosts();
// Map the virtual hosts onto the configured hosts
- Iterator hostNames = mapVirtualHosts(vhostNames);
- if (hostNames.hasNext())
+ String hostName = mapVirtualHosts(vhostNames);
+ if (hostName == null)
{
- hostName = hostNames.next().toString();
- }
- else
- {
- hostNames = getDefaultHosts();
+ Iterator hostNames = getDefaultHosts();
if (hostNames.hasNext())
{
hostName = hostNames.next().toString();
}
}
- performDeployInternal(webApp, hostName, warUrl);
- while (hostNames.hasNext())
+ if (hostName == null)
{
- String additionalHostName = hostNames.next().toString();
- performDeployInternal(webApp, additionalHostName, warUrl);
+ throw new IllegalStateException("No default host defined");
}
+ performDeployInternal(webApp, hostName, warUrl);
}
protected void performDeployInternal(WebApplication webApp, String hostName, String warUrlStr) throws Exception
@@ -513,29 +507,19 @@
log.info("undeploy, ctxPath=" + warInfo.getMetaData().getContextRoot());
JBossWebMetaData metaData = warInfo.getMetaData();
- String hostName = null;
// Get any jboss-web/virtual-hosts
List<String> vhostNames = metaData.getVirtualHosts();
// Map the virtual hosts onto the configured hosts
- Iterator hostNames = mapVirtualHosts(vhostNames);
- if (hostNames.hasNext())
+ String hostName = mapVirtualHosts(vhostNames);
+ if (hostName == null)
{
- hostName = hostNames.next().toString();
- }
- else
- {
- hostNames = getDefaultHosts();
+ Iterator hostNames = getDefaultHosts();
if (hostNames.hasNext())
{
hostName = hostNames.next().toString();
}
}
performUndeployInternal(warInfo, hostName, warUrl);
- while (hostNames.hasNext())
- {
- String additionalHostName = hostNames.next().toString();
- performUndeployInternal(warInfo, additionalHostName, warUrl);
- }
}
@@ -567,7 +551,7 @@
* @return Iterator<String> of the unique Host names
* @throws Exception
*/
- protected synchronized Iterator mapVirtualHosts(List<String> vhostNames) throws Exception
+ protected synchronized String mapVirtualHosts(List<String> vhostNames) throws Exception
{
if (vhostToHostNames.size() == 0)
{
@@ -594,7 +578,8 @@
}
// Map the virtual host names to the hosts
- HashSet hosts = new HashSet();
+ HashSet<String> hosts = new HashSet<String>();
+ String webappHost = null;
if (vhostNames != null)
{
for (String vhost : vhostNames)
@@ -603,13 +588,53 @@
if (host == null)
{
log.warn("Failed to map vhost: " + vhost);
- // This will cause a new host to be created
- host = vhost;
+ // This will cause a new alias to be added
+ hosts.add(vhost);
}
- hosts.add(host);
+ else
+ {
+ if (webappHost == null)
+ {
+ webappHost = host;
+ }
+ else
+ {
+ throw new IllegalStateException("Cannot add webapp to two different hosts: "
+ + webappHost + " and " + host);
+ }
+ }
}
+ // Add to default host if none exists
+ if (webappHost == null)
+ {
+ Iterator defaultHosts = getDefaultHosts();
+ if (defaultHosts.hasNext())
+ {
+ webappHost = defaultHosts.next().toString();
+ }
+ }
+ // Add missing aliases to matching host
+ if (webappHost != null)
+ {
+ String hostQuery = config.getCatalinaDomain() + ":type=Host,host=" + webappHost + ",*";
+ ObjectName query = new ObjectName(hostQuery);
+ Set hostONs = server.queryNames(query, null);
+ Iterator iter = hostONs.iterator();
+ if (iter.hasNext())
+ {
+ ObjectName host = (ObjectName)iter.next();
+ Object[] name = new Object[1];
+ String[] args = { "java.lang.String" };
+ for (String vhost : hosts)
+ {
+ log.warn("Adding alias to vhost: " + vhost);
+ name[0] = vhost;
+ server.invoke(host, "addAlias", name, args);
+ }
+ }
+ }
}
- return hosts.iterator();
+ return webappHost;
}
/**
Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatService.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatService.java 2010-08-30 16:24:51 UTC (rev 107891)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatService.java 2010-08-30 17:57:50 UTC (rev 107892)
@@ -243,7 +243,7 @@
throw new IllegalArgumentException("No services");
}
Iterator<ServiceMetaData> serviceMetaDatas = serverMetaData.getServices().iterator();
- while (serviceMetaDatas.hasNext())
+ if (serviceMetaDatas.hasNext())
{
ServiceMetaData serviceMetaData = serviceMetaDatas.next();
org.apache.catalina.Service service =
@@ -344,6 +344,12 @@
}
}
+
+ // Forbid more than one service
+ if (serviceMetaDatas.hasNext())
+ {
+ throw new IllegalArgumentException("Only one service declaration is allowed in server.xml");
+ }
// Set the resulting Server to the Catalina instance
catalina.setServer(catalinaServer);
More information about the jboss-cvs-commits
mailing list