Make Tomcat much easier to configure.
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 11 Dec 2012 10:56:21 +0000 (10:56 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 11 Dec 2012 10:56:21 +0000 (10:56 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@5951 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

16 files changed:
demo/argeo_node_rcp.properties
demo/argeo_node_web.properties
demo/tomcat-server-ssl.xml [new file with mode: 0644]
pom.xml
security/dep/org.argeo.security.dep.node/pom.xml
server/dep/org.argeo.server.dep.tomcat/pom.xml
server/modules/org.argeo.server.tomcat/pom.xml
server/modules/pom.xml
server/runtime/org.argeo.server.catalina.start/META-INF/MANIFEST.MF
server/runtime/org.argeo.server.catalina.start/pom.xml
server/runtime/org.argeo.server.catalina.start/src/main/java/org/argeo/catalina/start/CatalinaActivator.java [new file with mode: 0644]
server/runtime/org.argeo.server.catalina.start/src/main/java/org/argeo/dep/osgi/catalina/start/CatalinaActivator.java [deleted file]
server/runtime/org.argeo.server.catalina.start/src/main/java/org/springframework/osgi/web/tomcat/internal/Activator.java
server/runtime/org.argeo.server.catalina.start/src/main/resources/conf/default-server.xml
server/runtime/org.argeo.server.catalina.start/tomcat.properties [new file with mode: 0644]
server/runtime/pom.xml

index df2da86e6c0f71765a0920d750cbc4a2e32612e5..a2e7105a2fdbc207a47fc97cd796f611cdfbc8f3 100644 (file)
@@ -3,7 +3,7 @@ org.springframework.osgi.extender,\
 org.argeo.node.repo.jackrabbit,\
 org.argeo.security.dao.os,\
 
-#org.argeo.dep.osgi.catalina.start,\
+#org.argeo.server.catalina.start,\
 #org.springframework.osgi.web.extender,\
 #org.argeo.jackrabbit.webapp,\
 
index 02bb7756499fe4132fadabe13cf65e52f13f9f48..1d8ad752f4533e90fc333c5da0b254f21815d0fd 100644 (file)
@@ -9,7 +9,7 @@ org.argeo.security.dao.ldap,\
 argeo.osgi.start.4.node=\
 org.argeo.jackrabbit.webapp,\
 org.argeo.server.rap.webapp,\
-org.argeo.dep.osgi.catalina.start,\
+org.argeo.server.catalina.start,\
 org.eclipse.equinox.http.registry,\
 org.springframework.osgi.web.extender,\
 
@@ -18,6 +18,7 @@ org.springframework.osgi.web.extender,\
 #org.argeo.security.ui.initialPerspective=org.argeo.jcr.ui.explorer.perspective
 
 log4j.configuration=file:../../log4j.properties
+argeo.server.tomcat.config=file:../../tomcat-server-ssl.xml
 
 argeo.i18n.availableLocales=en,fr,de,ru,ar
 eclipse.registry.MultiLanguage=true
diff --git a/demo/tomcat-server-ssl.xml b/demo/tomcat-server-ssl.xml
new file mode 100644 (file)
index 0000000..0417b7c
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version='1.0' encoding='utf-8'?>
+<Server port="-1" shutdown="SHUTDOWN">
+       <!--APR library loader. Documentation at /docs/apr.html -->
+       <!-- <Listener className="org.apache.catalina.core.AprLifecycleListener" 
+               SSLEngine="on" /> -->
+       <!-- Initialize Jasper prior to webapps are loaded. -->
+       <Listener className="org.apache.catalina.core.JasperListener" />
+       <!-- JMX -->
+       <!-- <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" 
+               /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" 
+               /> -->
+
+       <Service name="Catalina">
+               <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
+                       maxThreads="150" minSpareThreads="4" />
+
+               <!-- HTTP -->
+               <Connector executor="tomcatThreadPool" port="${argeo.server.port.http}"
+                       protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="${argeo.server.port.https}"
+                       secure="${argeo.server.http.secure}" proxyName="${argeo.server.http.proxyName}"
+                       proxyPort="${argeo.server.http.proxyPort}" />
+               <!-- HTTPS -->
+               <Connector port="${argeo.server.port.https}" protocol="HTTP/1.1"
+                       SSLEnabled="true" scheme="https" secure="true" sslProtocol="TLS"
+                       keystoreFile="${argeo.server.keystoreFile}" keystoreType="JKS"
+                       keystorePass="${argeo.server.keystorePass}" truststoreFile="${argeo.server.truststoreFile}"
+                       truststoreType="JKS" truststorePass="${argeo.server.truststorePass}"
+                       clientAuth="${argeo.server.https.clientAuth}" />
+                        
+               <!-- AJP (for proxying with httpd) -->
+               <Connector port="${argeo.server.port.ajp}" protocol="AJP/1.3"
+                       redirectPort="${argeo.server.port.https}" />
+
+               <Engine name="Catalina" defaultHost="localhost">
+                       <Host name="localhost" appBase="webapps" unpackWARs="true"
+                               autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"
+                               workDir="work">
+                       </Host>
+               </Engine>
+       </Service>
+</Server>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index b0a237e6a75e075297ff8266373b2ab063adb8b1..3b54e609104084f3b0a9ccd42ddeb1a3861dd0a0 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -95,6 +95,27 @@ limitations under the License.
                                <version>2.2</version>
                        </extension>
                </extensions>
+               <resources>
+                       <resource>
+                               <directory>src/main/resources</directory>
+                       </resource>
+                       <resource>
+                               <directory>.</directory>
+                               <includes>
+                                       <include>plugin.xml</include>
+                                       <include>META-INF/**</include>
+                                       <include>WEB-INF/**</include>
+                                       <include>icons/**</include>
+                                       <include>branding/**</include>
+                                       <include>*.properties</include>
+                                       <include>properties/*.properties</include>
+                                       <include>p2.inf</include>
+                               </includes>
+                               <excludes>
+                                       <exclude>build.properties</exclude>
+                               </excludes>
+                       </resource>
+               </resources>
                <pluginManagement>
                        <plugins>
                                <!-- Maven -->
@@ -341,27 +362,6 @@ limitations under the License.
                                </plugin>
                        </plugins>
                </pluginManagement>
-               <resources>
-                       <resource>
-                               <directory>src/main/resources</directory>
-                       </resource>
-                       <resource>
-                               <directory>.</directory>
-                               <includes>
-                                       <include>plugin.xml</include>
-                                       <include>META-INF/**</include>
-                                       <include>WEB-INF/**</include>
-                                       <include>icons/**</include>
-                                       <include>branding/**</include>
-                                       <include>*.properties</include>
-                                       <include>properties/*.properties</include>
-                                       <include>p2.inf</include>
-                               </includes>
-                               <excludes>
-                                       <exclude>build.properties</exclude>
-                               </excludes>
-                       </resource>
-               </resources>
                <plugins>
                        <plugin>
                                <groupId>org.codehaus.mojo</groupId>
index f0d26e55018e8693e879aeb5b8bce8b66bdcc410..88950f74f9919966d382e8a887abd403d59e07f8 100644 (file)
                        <version>1.1.9-SNAPSHOT</version>
                </dependency>
 
-               <!-- Default Tomcat conf -->
-               <dependency>
-                       <groupId>org.argeo.commons.server</groupId>
-                       <artifactId>org.argeo.server.tomcat</artifactId>
-                       <version>1.1.9-SNAPSHOT</version>
-               </dependency>
-
                <!-- DB drivers -->
                <dependency>
                        <groupId>org.argeo.tp</groupId>
index 5d5b393f7525134444d81329281b13155fafbe6c..54dd542df5630458ad8547b9fc781f5127bc9075 100644 (file)
@@ -1,4 +1,6 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.commons.server</groupId>
                        <artifactId>org.argeo.server.catalina</artifactId>
                        <version>1.1.9-SNAPSHOT</version>
                </dependency>
-<!--           <dependency> -->
-<!--                   <groupId>org.argeo.commons.server</groupId> -->
-<!--                   <artifactId>org.argeo.server.tomcat</artifactId> -->
-<!--                   <version>0.3.1-SNAPSHOT</version> -->
-<!--           </dependency> -->
+               <dependency>
+                       <groupId>org.argeo.commons.server</groupId>
+                       <artifactId>org.argeo.server.catalina.start</artifactId>
+                       <version>1.1.9-SNAPSHOT</version>
+               </dependency>
 
                <!-- JEE -->
                <dependency>
                </dependency>
 
                <!-- Tomcat -->
-               <dependency>
-                       <groupId>org.argeo.tp</groupId>
-                       <artifactId>org.argeo.dep.osgi.catalina.start</artifactId>
-               </dependency>
                <dependency>
                        <groupId>org.argeo.tp</groupId>
                        <artifactId>org.apache.coyote</artifactId>
                        <artifactId>org.apache.xmlcommons</artifactId>
                        <scope>test</scope>
                </dependency>
-               
-                                               <!-- OSGi test -->
-                               <dependency>
-                                       <groupId>org.argeo.commons.base</groupId>
-                                       <artifactId>org.argeo.osgi.boot</artifactId>
-                                       <version>1.1.9-SNAPSHOT</version>
-                                       <scope>test</scope>
-                               </dependency>
-               
+
+               <!-- OSGi test -->
+               <dependency>
+                       <groupId>org.argeo.commons.base</groupId>
+                       <artifactId>org.argeo.osgi.boot</artifactId>
+                       <version>1.1.9-SNAPSHOT</version>
+                       <scope>test</scope>
+               </dependency>
+
        </dependencies>
 </project>
\ No newline at end of file
index c8b285e043a03a7848d1276e024208991749bf2b..7b458b3f0a78aa20f5f82ef149b71d762d5a5793 100644 (file)
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.commons.server</groupId>
@@ -16,7 +17,7 @@
                                <artifactId>maven-bundle-plugin</artifactId>
                                <configuration>
                                        <instructions>
-                                               <Fragment-Host>org.argeo.dep.osgi.catalina.start</Fragment-Host>
+                                               <Fragment-Host>org.argeo.catalina.start</Fragment-Host>
                                        </instructions>
                                </configuration>
                        </plugin>
index 27fd306a699832fe952ea634ac57ed62a49300c2..c6a4c1fb0f43875e81067992a922880c2fcade1e 100644 (file)
@@ -21,7 +21,7 @@
                <module>org.argeo.server.catalina</module>
                <module>org.argeo.server.jdbc</module>
                <module>org.argeo.server.rap.webapp</module>
-               <module>org.argeo.server.tomcat</module>
+<!--           <module>org.argeo.server.tomcat</module> -->
        </modules>
        <build>
                <resources>
index 2b322c77015f6ca9eea83dfedf6361cba58ebc15..bea8a29cb079de6cb53e30055c6d13457c4de266 100644 (file)
@@ -1,18 +1,26 @@
-Bundle-Activator: org.argeo.dep.osgi.catalina.start.CatalinaActivator\r
-Created-By: Argeo\r
-Import-Package: javax.management;resolution:=optional,\r
- org.apache.catalina,\r
- org.apache.catalina.connector,\r
- org.apache.catalina.core,\r
- org.apache.catalina.startup,\r
- org.apache.catalina.util,\r
- org.apache.commons.io,\r
- org.apache.commons.logging;resolution:=optional,\r
- org.apache.naming.resources,\r
- org.osgi.framework;version="1.3",\r
- org.osgi.service.url;version="1.0"\r
-Bundle-Version: 1.0.0.0009\r
-Bundle-Name: Tomcat Catalina OSGi Activator (Argeo)\r
-Bundle-Description: Tomcat Catalina OSGi Activator with Argeo addons\r
-Bundle-SymbolicName: org.argeo.dep.osgi.catalina.start\r
-Bundle-RequiredExecutionEnvironment: J2SE-1.5\r
+Manifest-Version: 1.0\r
+Bnd-LastModified: 1355222632573\r
+Build-Jdk: 1.6.0_24\r
+Built-By: mbaudier\r
+Bundle-Activator: org.argeo.catalina.start.CatalinaActivator\r
+Bundle-Description: Catalina starter hacked from Spring DM sandbox\r
+Bundle-DocURL: http://www.argeo.org\r
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+Bundle-ManifestVersion: 2\r
+Bundle-Name: Commons Catalina starter\r
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6\r
+Bundle-SymbolicName: org.argeo.server.catalina.start\r
+Bundle-Vendor: Argeo\r
+Bundle-Version: 1.1.9.SNAPSHOT-r121211_1143\r
+Created-By: Apache Maven Bundle Plugin\r
+Export-Package: org.argeo.catalina.start;uses:="org.osgi.framework,org.a\r
+ pache.commons.io";version="1.1.9.SNAPSHOT-r121211_1143"\r
+Import-Package: javax.management;version="0.0.0",org.apache.catalina;ver\r
+ sion="[6.0,7)",org.apache.catalina.connector;version="[6.0,7)",org.apac\r
+ he.catalina.core;version="[6.0,7)",org.apache.catalina.startup;version=\r
+ "[6.0,7)",org.apache.catalina.util;version="[6.0,7)",org.apache.commons\r
+ .io;version="[1.4,2)",org.apache.commons.logging;version="[1.1,2)",org.\r
+ apache.naming.resources;version="[6.0,7)",org.osgi.framework;version="[\r
+ 1.5,2)",org.osgi.service.url;version="[1.0,2)"\r
+SLC-GroupId: org.argeo.commons.server\r
+Tool: Bnd-1.50.0\r
index 7a405ebba23cd40be66e95db3a76586f3ac7721f..9e6cf2ad1488e5ddca2c82b6a433bfbdfafcf569 100644 (file)
@@ -4,7 +4,7 @@
        <parent>
                <groupId>org.argeo.commons.server</groupId>
                <version>1.1.9-SNAPSHOT</version>
-               <artifactId>modules</artifactId>
+               <artifactId>runtime</artifactId>
                <relativePath>..</relativePath>
        </parent>
        <artifactId>org.argeo.server.catalina.start</artifactId>
                                <artifactId>maven-bundle-plugin</artifactId>
                                <configuration>
                                        <instructions>
-                                               <Bundle-Activator>org.argeo.dep.osgi.catalina.start.CatalinaActivator</Bundle-Activator>
+                                               <Bundle-Activator>org.argeo.catalina.start.CatalinaActivator</Bundle-Activator>
+                                               <Import-Package>
+                                                       javax.management;version="0.0.0",
+                                                       *
+                                               </Import-Package>
                                        </instructions>
                                </configuration>
                        </plugin>
@@ -25,7 +29,7 @@
        </build>
        <dependencies>
                <dependency>
-                       <groupId>org.eclipse.osgi</groupId>
+                       <groupId>org.argeo.tp</groupId>
                        <artifactId>org.eclipse.osgi</artifactId>
                </dependency>
                <dependency>
diff --git a/server/runtime/org.argeo.server.catalina.start/src/main/java/org/argeo/catalina/start/CatalinaActivator.java b/server/runtime/org.argeo.server.catalina.start/src/main/java/org/argeo/catalina/start/CatalinaActivator.java
new file mode 100644 (file)
index 0000000..2656490
--- /dev/null
@@ -0,0 +1,93 @@
+package org.argeo.catalina.start;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Properties;
+
+import org.apache.commons.io.IOUtils;
+import org.osgi.framework.BundleContext;
+import org.springframework.osgi.web.tomcat.internal.Activator;
+
+/** Starts Catalina (hacked from Spring OSGi 1.0) */
+public class CatalinaActivator extends Activator {
+       private final static String ARGEO_OSGI_DATA_DIR = "argeo.osgi.data.dir";
+       /** System properties used to override Tomcat XML config URL */
+       public final static String ARGEO_SERVER_TOMCAT_CONFIG = "argeo.server.tomcat.config";
+
+       public void start(BundleContext context) throws Exception {
+               if (!System.getProperties().containsKey(ARGEO_OSGI_DATA_DIR)) {
+                       String osgiInstanceArea = System.getProperty("osgi.instance.area");
+                       String osgiInstanceAreaDefault = System
+                                       .getProperty("osgi.instance.area.default");
+                       String tempDir = System.getProperty("java.io.tmpdir");
+
+                       File dataDir = null;
+                       if (osgiInstanceArea != null) {
+                               // within OSGi with -data specified
+                               osgiInstanceArea = removeFilePrefix(osgiInstanceArea);
+                               dataDir = new File(osgiInstanceArea);
+                       } else if (osgiInstanceAreaDefault != null) {
+                               // within OSGi without -data specified
+                               osgiInstanceAreaDefault = removeFilePrefix(osgiInstanceAreaDefault);
+                               dataDir = new File(osgiInstanceAreaDefault);
+                       } else {// outside OSGi
+                               dataDir = new File(tempDir + File.separator + "osgiData");
+                       }
+
+                       System.setProperty(ARGEO_OSGI_DATA_DIR, dataDir.getAbsolutePath());
+               }
+
+               // Load config properties and put them in system properties so that they
+               // can be used in tomcat conf
+               Properties confProps = new Properties();
+               URL propsUrl = context.getBundle().getResource("tomcat.properties");
+               if (propsUrl != null) {
+                       InputStream in = null;
+                       try {
+                               in = propsUrl.openStream();
+                               confProps.load(in);
+                       } catch (Exception e) {
+                               throw new RuntimeException("Cannot read catalina properties.",
+                                               e);
+                       } finally {
+                               IOUtils.closeQuietly(in);
+                       }
+
+                       for (Object key : confProps.keySet()) {
+                               // System properties have priority
+                               if (!System.getProperties().containsKey(key)) {
+                                       System.setProperty(key.toString(),
+                                                       confProps.getProperty(key.toString()));
+                               }
+                       }
+               }
+
+               // calling Catalina.setCatalinaHome(String) or
+               // Catalina.setCatalinaBase(String) does the same
+               if (System.getProperty("catalina.home") == null)
+                       System.setProperty("catalina.home",
+                                       System.getProperty(ARGEO_OSGI_DATA_DIR) + "/tomcat");
+               if (System.getProperty("catalina.base") == null)
+                       System.setProperty("catalina.base",
+                                       System.getProperty(ARGEO_OSGI_DATA_DIR) + "/tomcat");
+
+               // Call Spring starter
+               super.start(context);
+       }
+
+       @Override
+       public void stop(BundleContext context) throws Exception {
+               super.stop(context);
+       }
+
+       protected String removeFilePrefix(String url) {
+               if (url.startsWith("file:"))
+                       return url.substring("file:".length());
+               else if (url.startsWith("reference:file:"))
+                       return url.substring("reference:file:".length());
+               else
+                       return url;
+       }
+
+}
diff --git a/server/runtime/org.argeo.server.catalina.start/src/main/java/org/argeo/dep/osgi/catalina/start/CatalinaActivator.java b/server/runtime/org.argeo.server.catalina.start/src/main/java/org/argeo/dep/osgi/catalina/start/CatalinaActivator.java
deleted file mode 100644 (file)
index 5c1df1a..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-package org.argeo.dep.osgi.catalina.start;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Properties;
-
-import org.apache.commons.io.IOUtils;
-import org.osgi.framework.BundleContext;
-import org.springframework.osgi.web.tomcat.internal.Activator;
-
-/** Starts Catalina (hacked from Spring OSGi 1.0) */
-public class CatalinaActivator extends Activator {
-       private final static String ARGEO_OSGI_DATA_DIR = "argeo.osgi.data.dir";
-
-       public void start(BundleContext context) throws Exception {
-               if (!System.getProperties().containsKey(ARGEO_OSGI_DATA_DIR)) {
-                       String osgiInstanceArea = System.getProperty("osgi.instance.area");
-                       String osgiInstanceAreaDefault = System
-                                       .getProperty("osgi.instance.area.default");
-                       String tempDir = System.getProperty("java.io.tmpdir");
-
-                       File dataDir = null;
-                       if (osgiInstanceArea != null) {
-                               // within OSGi with -data specified
-                               osgiInstanceArea = removeFilePrefix(osgiInstanceArea);
-                               dataDir = new File(osgiInstanceArea);
-                       } else if (osgiInstanceAreaDefault != null) {
-                               // within OSGi without -data specified
-                               osgiInstanceAreaDefault = removeFilePrefix(osgiInstanceAreaDefault);
-                               dataDir = new File(osgiInstanceAreaDefault);
-                       } else {// outside OSGi
-                               dataDir = new File(tempDir + File.separator + "osgiData");
-                       }
-
-                       System.setProperty(ARGEO_OSGI_DATA_DIR, dataDir.getAbsolutePath());
-               }
-
-               // Load config properties and put them in system properties so that they
-               // can be used in tomcat conf
-               Properties confProps = new Properties();
-               URL propsUrl = context.getBundle().getResource("tomcat.properties");
-               if (propsUrl != null) {
-                       InputStream in = null;
-                       try {
-                               in = propsUrl.openStream();
-                               confProps.load(in);
-                       } catch (Exception e) {
-                               throw new RuntimeException("Cannot read catalina properties.",
-                                               e);
-                       } finally {
-                               IOUtils.closeQuietly(in);
-                       }
-
-                       for (Object key : confProps.keySet()) {
-                               // System properties have priority
-                               if (!System.getProperties().containsKey(key)) {
-                                       System.setProperty(key.toString(),
-                                                       confProps.getProperty(key.toString()));
-                               }
-                       }
-               }
-
-               // calling Catalina.setCatalinaHome(String) or
-               // Catalina.setCatalinaBase(String) does the same
-               if (System.getProperty("catalina.home") == null)
-                       System.setProperty("catalina.home",
-                                       System.getProperty(ARGEO_OSGI_DATA_DIR) + "/tomcat");
-               if (System.getProperty("catalina.base") == null)
-                       System.setProperty("catalina.base",
-                                       System.getProperty(ARGEO_OSGI_DATA_DIR) + "/tomcat");
-
-               // Call Spring starter
-               super.start(context);
-       }
-
-       @Override
-       public void stop(BundleContext context) throws Exception {
-               super.stop(context);
-       }
-
-       protected String removeFilePrefix(String url) {
-               if (url.startsWith("file:"))
-                       return url.substring("file:".length());
-               else if (url.startsWith("reference:file:"))
-                       return url.substring("reference:file:".length());
-               else
-                       return url;
-       }
-
-}
index 70284fe18fde732ea9ad8b3681901ee729509269..9481f3158282293b52325071f5b96813aaa06aaf 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.catalina.util.ServerInfo;
 import org.apache.commons.logging.Log;\r
 import org.apache.commons.logging.LogFactory;\r
 import org.apache.naming.resources.DirContextURLStreamHandler;\r
+import org.argeo.catalina.start.CatalinaActivator;\r
 import org.osgi.framework.Bundle;\r
 import org.osgi.framework.BundleActivator;\r
 import org.osgi.framework.BundleContext;\r
@@ -49,9 +50,10 @@ import org.osgi.service.url.URLStreamHandlerService;
  * Simple activator for starting Apache Tomcat Catalina container inside OSGi\r
  * using Tomcat's XML configuration files.\r
  * \r
- * <p/> This activator looks initially for a <code>conf/server.xml</code> file\r
- * falling back to <code>conf/default-server.xml</code>. This allows the\r
- * default configuration to be tweaked through fragments for example.\r
+ * <p/>\r
+ * This activator looks initially for a <code>conf/server.xml</code> file\r
+ * falling back to <code>conf/default-server.xml</code>. This allows the default\r
+ * configuration to be tweaked through fragments for example.\r
  * \r
  * @author Costin Leau\r
  */\r
@@ -74,7 +76,6 @@ public class Activator implements BundleActivator {
 \r
        private Thread startupThread;\r
 \r
-\r
        public void start(BundleContext context) throws Exception {\r
                this.bundleContext = context;\r
                // do the initialization on a different thread\r
@@ -99,22 +100,22 @@ public class Activator implements BundleActivator {
                                        Connector[] connectors = server.findConnectors();\r
                                        for (int i = 0; i < connectors.length; i++) {\r
                                                Connector conn = connectors[i];\r
-                                               log.info("Succesfully started " + ServerInfo.getServerInfo() + " @ " + conn.getDomain() + ":"\r
-                                                               + conn.getPort());\r
+                                               log.info("Succesfully started "\r
+                                                               + ServerInfo.getServerInfo() + " @ "\r
+                                                               + conn.getDomain() + ":" + conn.getPort());\r
                                        }\r
 \r
                                        // register URL service\r
                                        urlRegistration = registerTomcatJNDIUrlService();\r
                                        // publish server as an OSGi service\r
                                        registration = publishServerAsAService(server);\r
-                                       log.info("Published " + ServerInfo.getServerInfo() + " as an OSGi service");\r
-                               }\r
-                               catch (Exception ex) {\r
+                                       log.info("Published " + ServerInfo.getServerInfo()\r
+                                                       + " as an OSGi service");\r
+                               catch (Exception ex) {\r
                                        String msg = "Cannot start " + ServerInfo.getServerInfo();\r
                                        log.error(msg, ex);\r
                                        throw new RuntimeException(msg, ex);\r
-                               }\r
-                               finally {\r
+                               } finally {\r
                                        current.setContextClassLoader(old);\r
                                }\r
                        }\r
@@ -137,29 +138,33 @@ public class Activator implements BundleActivator {
 \r
                try {\r
                        current.setContextClassLoader(cl);\r
-                       //reset CCL \r
+                       // reset CCL\r
                        // current.setContextClassLoader(null);\r
                        log.info("Stopping " + ServerInfo.getServerInfo() + " ...");\r
                        server.stop();\r
                        log.info("Succesfully stopped " + ServerInfo.getServerInfo());\r
-               }\r
-               catch (Exception ex) {\r
+               } catch (Exception ex) {\r
                        log.error("Cannot stop " + ServerInfo.getServerInfo(), ex);\r
                        throw ex;\r
-               }\r
-               finally {\r
+               } finally {\r
                        current.setContextClassLoader(old);\r
                }\r
        }\r
 \r
-       private StandardService createCatalinaServer(Bundle bundle) throws Exception {\r
-               // first try to use the XML file\r
-               URL xmlConfiguration = bundle.getResource(XML_CONF_LOCATION);\r
+       private StandardService createCatalinaServer(Bundle bundle)\r
+                       throws Exception {\r
+               URL xmlConfiguration = null;\r
+\r
+               if (System.getProperty(CatalinaActivator.ARGEO_SERVER_TOMCAT_CONFIG) != null)\r
+                       xmlConfiguration = new URL(\r
+                                       System.getProperty(CatalinaActivator.ARGEO_SERVER_TOMCAT_CONFIG));\r
+               else\r
+                       // fragment\r
+                       xmlConfiguration = bundle.getResource(XML_CONF_LOCATION);\r
 \r
                if (xmlConfiguration != null) {\r
                        log.info("Using custom XML configuration " + xmlConfiguration);\r
-               }\r
-               else {\r
+               } else {\r
                        xmlConfiguration = bundle.getResource(DEFAULT_XML_CONF_LOCATION);\r
                        if (xmlConfiguration == null)\r
                                log.error("No XML configuration found; bailing out...");\r
@@ -170,20 +175,25 @@ public class Activator implements BundleActivator {
                return createServerFromXML(xmlConfiguration);\r
        }\r
 \r
-       private StandardService createServerFromXML(URL xmlConfiguration) throws IOException {\r
+       private StandardService createServerFromXML(URL xmlConfiguration)\r
+                       throws IOException {\r
                OsgiCatalina catalina = new OsgiCatalina();\r
                catalina.setAwait(false);\r
                catalina.setUseShutdownHook(false);\r
                catalina.setName("Catalina");\r
-               catalina.setParentClassLoader(Thread.currentThread().getContextClassLoader());\r
+               catalina.setParentClassLoader(Thread.currentThread()\r
+                               .getContextClassLoader());\r
 \r
-               // copy the URL file to a local temporary file (since Catalina doesn't use URL unfortunately)\r
+               // copy the URL file to a local temporary file (since Catalina doesn't\r
+               // use URL unfortunately)\r
                File configTempFile = File.createTempFile("dm.catalina", ".cfg.xml");\r
                configTempFile.deleteOnExit();\r
 \r
                // copy URL to temporary file\r
-               copyURLToFile(xmlConfiguration.openStream(), new FileOutputStream(configTempFile));\r
-               log.debug("Copied configuration " + xmlConfiguration + " to temporary file " + configTempFile);\r
+               copyURLToFile(xmlConfiguration.openStream(), new FileOutputStream(\r
+                               configTempFile));\r
+               log.debug("Copied configuration " + xmlConfiguration\r
+                               + " to temporary file " + configTempFile);\r
 \r
                catalina.setConfigFile(configTempFile.getAbsolutePath());\r
 \r
@@ -202,20 +212,17 @@ public class Activator implements BundleActivator {
                        while ((bytesRead = inStream.read(buf)) >= 0) {\r
                                outStream.write(buf, 0, bytesRead);\r
                        }\r
-               }\r
-               catch (IOException ex) {\r
-                       throw (RuntimeException) new IllegalStateException("Cannot copy URL to file").initCause(ex);\r
-               }\r
-               finally {\r
+               } catch (IOException ex) {\r
+                       throw (RuntimeException) new IllegalStateException(\r
+                                       "Cannot copy URL to file").initCause(ex);\r
+               } finally {\r
                        try {\r
                                inStream.close();\r
-                       }\r
-                       catch (IOException ignore) {\r
+                       } catch (IOException ignore) {\r
                        }\r
                        try {\r
                                outStream.close();\r
-                       }\r
-                       catch (IOException ignore) {\r
+                       } catch (IOException ignore) {\r
                        }\r
                }\r
        }\r
@@ -226,14 +233,17 @@ public class Activator implements BundleActivator {
                props.put(Constants.SERVICE_VENDOR, "Spring Dynamic Modules");\r
                props.put(Constants.SERVICE_DESCRIPTION, ServerInfo.getServerInfo());\r
                props.put(Constants.BUNDLE_VERSION, ServerInfo.getServerNumber());\r
-               props.put(Constants.BUNDLE_NAME, bundleContext.getBundle().getSymbolicName());\r
+               props.put(Constants.BUNDLE_NAME, bundleContext.getBundle()\r
+                               .getSymbolicName());\r
 \r
                // spring-dm specific property\r
                props.put("org.springframework.osgi.bean.name", "tomcat-server");\r
 \r
-               // publish just the interfaces and the major classes (server/handlerWrapper)\r
-               String[] classes = new String[] { StandardService.class.getName(), Service.class.getName(),\r
-                       MBeanRegistration.class.getName(), Lifecycle.class.getName() };\r
+               // publish just the interfaces and the major classes\r
+               // (server/handlerWrapper)\r
+               String[] classes = new String[] { StandardService.class.getName(),\r
+                               Service.class.getName(), MBeanRegistration.class.getName(),\r
+                               Lifecycle.class.getName() };\r
 \r
                return bundleContext.registerService(classes, server, props);\r
        }\r
@@ -243,15 +253,17 @@ public class Activator implements BundleActivator {
                properties.put(URLConstants.URL_HANDLER_PROTOCOL, "jndi");\r
                final URLStreamHandler handler = new DirContextURLStreamHandler();\r
 \r
-               return bundleContext.registerService(URLStreamHandlerService.class.getName(),\r
-                       new AbstractURLStreamHandlerService() {\r
+               return bundleContext.registerService(\r
+                               URLStreamHandlerService.class.getName(),\r
+                               new AbstractURLStreamHandlerService() {\r
 \r
-                               private final static String EMPTY_STRING = "";\r
+                                       private final static String EMPTY_STRING = "";\r
 \r
-\r
-                               public URLConnection openConnection(URL u) throws IOException {\r
-                                       return new URL(u, EMPTY_STRING, handler).openConnection();\r
-                               }\r
-                       }, properties);\r
+                                       public URLConnection openConnection(URL u)\r
+                                                       throws IOException {\r
+                                               return new URL(u, EMPTY_STRING, handler)\r
+                                                               .openConnection();\r
+                                       }\r
+                               }, properties);\r
        }\r
 }
\ No newline at end of file
index c8cd5bb7b7278828f673feb271922e0407548440..a558e134e6b3e54be5d9e7bdd7bce8e3585b4504 100644 (file)
@@ -1,16 +1,41 @@
-<Server port="8005" shutdown="SHUTDOWN">\r
-\r
-\r
-       <Service name="Catalina">\r
-               <Connector port="8080" />\r
-\r
-               <Engine name="Catalina" defaultHost="localhost">\r
-                       <Host name="localhost" unpackWARs="false" autoDeploy="false"\r
-                               liveDeploy="false" deployOnStartup="false" xmlValidation="false"\r
-                               xmlNamespaceAware="false">\r
-                       </Host>\r
-               </Engine>\r
-\r
-\r
-       </Service>\r
-</Server>\r
+<?xml version='1.0' encoding='utf-8'?>
+<Server port="-1" shutdown="SHUTDOWN">
+       <!--APR library loader. Documentation at /docs/apr.html -->
+       <!-- <Listener className="org.apache.catalina.core.AprLifecycleListener" 
+               SSLEngine="on" /> -->
+       <!-- Initialize Jasper prior to webapps are loaded. -->
+       <Listener className="org.apache.catalina.core.JasperListener" />
+       <!-- JMX -->
+       <!-- <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" 
+               /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" 
+               /> -->
+
+       <Service name="Catalina">
+               <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
+                       maxThreads="150" minSpareThreads="4" />
+
+               <!-- HTTP -->
+               <Connector executor="tomcatThreadPool" port="${argeo.server.port.http}"
+                       protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="${argeo.server.port.https}"
+                       secure="${argeo.server.http.secure}" proxyName="${argeo.server.http.proxyName}"
+                       proxyPort="${argeo.server.http.proxyPort}" />
+               <!-- HTTPS
+               <Connector port="${argeo.server.port.https}" protocol="HTTP/1.1"
+                       SSLEnabled="true" scheme="https" secure="true" sslProtocol="TLS"
+                       keystoreFile="${argeo.server.keystoreFile}" keystoreType="JKS"
+                       keystorePass="${argeo.server.keystorePass}" truststoreFile="${argeo.server.truststoreFile}"
+                       truststoreType="JKS" truststorePass="${argeo.server.truststorePass}"
+                       clientAuth="${argeo.server.https.clientAuth}" />
+                        -->
+               <!-- AJP (for proxying with httpd) -->
+               <Connector port="${argeo.server.port.ajp}" protocol="AJP/1.3"
+                       redirectPort="${argeo.server.port.https}" />
+
+               <Engine name="Catalina" defaultHost="localhost">
+                       <Host name="localhost" appBase="webapps" unpackWARs="true"
+                               autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"
+                               workDir="work">
+                       </Host>
+               </Engine>
+       </Service>
+</Server>
\ No newline at end of file
diff --git a/server/runtime/org.argeo.server.catalina.start/tomcat.properties b/server/runtime/org.argeo.server.catalina.start/tomcat.properties
new file mode 100644 (file)
index 0000000..5e6a5f1
--- /dev/null
@@ -0,0 +1,14 @@
+argeo.server.port.http=7070
+argeo.server.port.https=7073
+argeo.server.port.ajp=7079
+
+# Used only when SSL is activated (uncommented in server.xml)
+argeo.server.keystoreFile=../../../../ssl/server.ks
+argeo.server.keystorePass=changeit
+argeo.server.truststoreFile=../../../../ssl/server.ts
+argeo.server.truststorePass=changeit
+argeo.server.https.clientAuth=want
+
+argeo.server.http.proxyName=
+argeo.server.http.proxyPort=
+argeo.server.http.secure=false
\ No newline at end of file
index ac2525529b34ca8dcada635557172041b8be1352..82be322f978381dce6f5acc1ec6ca58fb56e56f2 100644 (file)
@@ -14,6 +14,7 @@
        <modules>
                <module>org.argeo.server.core</module>
                <module>org.argeo.server.json</module>
+               <module>org.argeo.server.catalina.start</module>
                <module>org.argeo.server.webextender</module>
                <module>org.argeo.server.jxl</module>
                <module>org.argeo.server.hibernate</module>