From e683e1408e610457f280e8c7efa301ecd104bbee Mon Sep 17 00:00:00 2001 From: antelder Date: Sun, 6 Dec 2009 10:33:23 +0000 Subject: 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 --- .../java/org/apache/tuscany/sca/war/Installer.java | 59 +++++++++++++++++++--- 1 file changed, 53 insertions(+), 6 deletions(-) (limited to 'sca-java-2.x/trunk/distribution/tomcat/tomcat-servlet') 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" + " \r\n" + + " \r\n" + + " org.apache.tuscany.sca.host.webapp.TuscanyContextListener\r\n" + + " \r\n" + + "\r\n" + + " \r\n" + + " tuscany\r\n" + + " org.apache.tuscany.sca.host.webapp.TuscanyServletFilter\r\n" + + " \r\n" + + "\r\n" + + " \r\n" + + " tuscany\r\n" + + " /*\r\n" + + " "; + + 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, "", ">" + 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" + " \r\n" + " "; @@ -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, "" + 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, "", tuscanyHostConfig); + backup(serverXmlFile); + writeAll(serverXmlFile, newServerXml); + } + private void removeHostConfigXml(File serverXmlFile) { + String serverXML = readAll(serverXmlFile); + if (serverXML.contains(tuscanyHostConfig)) { + String newServerXml = replace(serverXML, ""); + writeAll(serverXmlFile, newServerXml); + } } private String replace(String inputText, String begin, String newBegin, String end, String newEnd) { -- cgit v1.2.3