Provide default Tomcat SSL support
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 30 May 2013 16:24:24 +0000 (16:24 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 30 May 2013 16:24:24 +0000 (16:24 +0000)
https://www.argeo.org/bugzilla/show_bug.cgi?id=160

git-svn-id: https://svn.argeo.org/commons/branches/1.x@6313 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

server/runtime/org.argeo.server.catalina.start/src/main/java/org/argeo/catalina/start/CatalinaActivator.java
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-ssl.xml [new file with mode: 0644]

index 2656490fd0ddef489bb0b6e91c10ede84e282828..b990c9906c645d0346b74eb82648b5391a8aa986 100644 (file)
@@ -6,11 +6,15 @@ import java.net.URL;
 import java.util.Properties;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 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 Log log = LogFactory.getLog(CatalinaActivator.class);
+
        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";
@@ -72,6 +76,14 @@ public class CatalinaActivator extends Activator {
                        System.setProperty("catalina.base",
                                        System.getProperty(ARGEO_OSGI_DATA_DIR) + "/tomcat");
 
+               // Make sure directories are created
+               File catalinaDir = new File(System.getProperty("catalina.home"));
+               if (!catalinaDir.exists()) {
+                       catalinaDir.mkdirs();
+                       if (log.isDebugEnabled())
+                               log.debug("Created Tomcat directory " + catalinaDir);
+               }
+
                // Call Spring starter
                super.start(context);
        }
index 9481f3158282293b52325071f5b96813aaa06aaf..17ed5e996e1bafe308c3548f8f5ecaed8ec6711d 100644 (file)
@@ -20,6 +20,7 @@ import java.io.File;
 import java.io.FileOutputStream;\r
 import java.io.IOException;\r
 import java.io.InputStream;\r
+import java.net.MalformedURLException;\r
 import java.net.URL;\r
 import java.net.URLConnection;\r
 import java.net.URLStreamHandler;\r
@@ -155,12 +156,20 @@ public class Activator implements BundleActivator {
                        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
+               if (System.getProperty(CatalinaActivator.ARGEO_SERVER_TOMCAT_CONFIG) != null) {\r
+                       String customConfig = System\r
+                                       .getProperty(CatalinaActivator.ARGEO_SERVER_TOMCAT_CONFIG);\r
+                       try {\r
+                               xmlConfiguration = new URL(customConfig);\r
+                       } catch (MalformedURLException e) {\r
+                               // within this bundle\r
+                               // typically 'default-server-ssl.xml'\r
+                               xmlConfiguration = bundle.getResource(customConfig);\r
+                       }\r
+               } else {\r
                        // fragment\r
                        xmlConfiguration = bundle.getResource(XML_CONF_LOCATION);\r
+               }\r
 \r
                if (xmlConfiguration != null) {\r
                        log.info("Using custom XML configuration " + xmlConfiguration);\r
diff --git a/server/runtime/org.argeo.server.catalina.start/src/main/resources/conf/default-server-ssl.xml b/server/runtime/org.argeo.server.catalina.start/src/main/resources/conf/default-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