summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/distribution/tomcat/tomcat-servlet
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-12-06 10:33:23 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-12-06 10:33:23 +0000
commite683e1408e610457f280e8c7efa301ecd104bbee (patch)
treec05c5e83364a5a842832e365d562b72a11cc1794 /sca-java-2.x/trunk/distribution/tomcat/tomcat-servlet
parent6c140c8eac266f62ee90487b7a92a05178b9a449 (diff)
Update the installer to explicitly add the TuscanyHostConfig to Host definitions in conf/server.xml as there doesn't seem to be any way to do that programatically
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@887658 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/distribution/tomcat/tomcat-servlet')
-rw-r--r--sca-java-2.x/trunk/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/war/Installer.java59
1 files changed, 53 insertions, 6 deletions
diff --git a/sca-java-2.x/trunk/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/war/Installer.java b/sca-java-2.x/trunk/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/war/Installer.java
index 40651050fa..e469ed235a 100644
--- a/sca-java-2.x/trunk/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/war/Installer.java
+++ b/sca-java-2.x/trunk/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/war/Installer.java
@@ -114,11 +114,7 @@ public class Installer {
throw new IllegalStateException("conf/server.xml not found: " + serverXml.getAbsolutePath());
}
removeServerXml(serverXml);
- File propFile = new File(tuscanyWAR, "tuscany.properties");
- if (propFile.isFile()) {
- propFile.delete();
- }
-
+ removeHostConfigXml(serverXml);
}
private boolean doInstall() {
@@ -155,9 +151,44 @@ public class Installer {
// Add Tuscany LifecycleListener to Tomcat server.xml
updateServerXml(serverXml);
+ // Add Tuscany HostConfig to Hosts definitions in server.xml
+ updateHostConfigXml(serverXml);
+
+ // Add Tuscany specific default web.xml
+ addTuscanyWebXml();
+
return true;
}
+ private static final String tuscanyWebXML =
+ "\r\n\r\n" + " <!-- Tuscany Listener and Filter definitions -->\r\n" +
+ " <listener>\r\n" +
+ " <listener-class>org.apache.tuscany.sca.host.webapp.TuscanyContextListener</listener-class>\r\n" +
+ " </listener>\r\n" +
+ "\r\n" +
+ " <filter>\r\n" +
+ " <filter-name>tuscany</filter-name>\r\n" +
+ " <filter-class>org.apache.tuscany.sca.host.webapp.TuscanyServletFilter</filter-class>\r\n" +
+ " </filter>\r\n" +
+ "\r\n" +
+ " <filter-mapping>\r\n" +
+ " <filter-name>tuscany</filter-name>\r\n" +
+ " <url-pattern>/*</url-pattern>\r\n" +
+ " </filter-mapping>";
+
+ private void addTuscanyWebXml() {
+ File tuscanyWebXmlFile = new File(catalinaBase, "/conf/tuscany-web.xml");
+ if (!(tuscanyWebXmlFile.exists())) {
+ File webXmlFile = new File(catalinaBase, "/conf/web.xml");
+ if (!(webXmlFile.exists())) {
+ throw new IllegalStateException("conf/web.xml not found: " + webXmlFile.getAbsolutePath());
+ }
+ String webXML = readAll(webXmlFile);
+ String newWebXml = replace(webXML, "<web-app", "<web-app", ">", ">" + tuscanyWebXML);
+ writeAll(tuscanyWebXmlFile, newWebXml);
+ }
+ }
+
private File findTuscanyTomcatJar(File tuscanyWAR) {
File lib = new File(tuscanyWAR, "/tomcat-lib");
for (File f : lib.listFiles()) {
@@ -168,6 +199,7 @@ public class Installer {
return null;
}
+
static final String tuscanyListener =
"\r\n" + " <!-- Tuscany plugin for Tomcat -->\r\n"
+ " <Listener className=\"org.apache.tuscany.sca.tomcat.TuscanyLifecycleListener\" />";
@@ -179,7 +211,6 @@ public class Installer {
backup(serverXmlFile);
writeAll(serverXmlFile, newServerXml);
}
-
}
private void removeServerXml(File serverXmlFile) {
@@ -188,7 +219,23 @@ public class Installer {
String newServerXml = replace(serverXML, "<Server", "<Server", ">" + tuscanyListener, ">");
writeAll(serverXmlFile, newServerXml);
}
+ }
+
+ static final String tuscanyHostConfig = " hostConfigClass=\"org.apache.tuscany.sca.tomcat.TuscanyHostConfig\" >";
+
+ private void updateHostConfigXml(File serverXmlFile) {
+ String serverXML = readAll(serverXmlFile);
+ String newServerXml = replace(serverXML, "<Host", "<Host", ">", tuscanyHostConfig);
+ backup(serverXmlFile);
+ writeAll(serverXmlFile, newServerXml);
+ }
+ private void removeHostConfigXml(File serverXmlFile) {
+ String serverXML = readAll(serverXmlFile);
+ if (serverXML.contains(tuscanyHostConfig)) {
+ String newServerXml = replace(serverXML, "<Host", "<Host", tuscanyHostConfig, ">");
+ writeAll(serverXmlFile, newServerXml);
+ }
}
private String replace(String inputText, String begin, String newBegin, String end, String newEnd) {