You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by mi...@apache.org on 2005/11/12 22:06:42 UTC

svn commit: r332837 - in /lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation: Configuration.java ProxyGenerator.java conf.properties

Author: michi
Date: Sat Nov 12 13:06:37 2005
New Revision: 332837

URL: http://svn.apache.org/viewcvs?rev=332837&view=rev
Log:
ProxyGenerator with https resp. getScheme enhanced

Added:
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/Configuration.java
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/conf.properties
Modified:
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/ProxyGenerator.java

Added: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/Configuration.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/Configuration.java?rev=332837&view=auto
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/Configuration.java (added)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/Configuration.java Sat Nov 12 13:06:37 2005
@@ -0,0 +1,101 @@
+package org.apache.lenya.cms.cocoon.generation;
+
+
+import java.net.URL;
+import java.util.Properties;
+
+import org.apache.log4j.Category;
+
+
+/**
+ * Read configuration
+ */
+public class Configuration {
+    static Category log = Category.getInstance(Configuration.class);
+    public static final String DEFAULT_CONFIGURATION_FILE = "org/apache/lenya/cms/cocoon/generation/conf.properties";
+    public static final String DEFAULT_CONFIGURATION_KEY = "lenya.configuration";
+    public static final String OVERRIDE_DEFAULT_CONFIGURATION_KEY = "override.lenya.configuration";
+    public String trustStore = null;
+    public String trustStorePassword = null;
+
+    /**
+     * Creates a new Configuration object.
+     */
+    public Configuration() {
+        getProperties(load());
+    }
+
+    /**
+     * DOCUMENT ME!
+     *
+     * @return DOCUMENT ME!
+     */
+    public static Properties load() {
+        String resourcePathRelativeToClasspath = System.getProperty(OVERRIDE_DEFAULT_CONFIGURATION_KEY);
+
+        if (resourcePathRelativeToClasspath == null) {
+            resourcePathRelativeToClasspath = System.getProperty(DEFAULT_CONFIGURATION_KEY, DEFAULT_CONFIGURATION_FILE);
+            log.debug(DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath);
+        } else {
+            log.debug(OVERRIDE_DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath);
+        }
+
+        URL url = Configuration.class.getClassLoader().getResource(resourcePathRelativeToClasspath);
+
+        if (url == null) {
+            log.error(".load(): Could not find resource on classpath: " + resourcePathRelativeToClasspath);
+        }
+
+        log.debug(url);
+
+        Properties properties = new Properties();
+
+        try {
+            properties.load(Configuration.class.getResourceAsStream("conf.properties"));
+        } catch (Exception e) {
+            log.error(e);
+        }
+
+        return properties;
+    }
+
+    /**
+     * DOCUMENT ME!
+     *
+     * @param properties DOCUMENT ME!
+     */
+    public void getProperties(Properties properties) {
+        if (properties != null) {
+            trustStore = getProperty(properties, "org.apache.lenya.cms.cocoon.generation.ProxyGenerator.trustStore");
+            trustStorePassword = getProperty(properties, "org.apache.lenya.cms.cocoon.generation.ProxyGenerator.trustStorePassword");
+        }
+    }
+
+    /**
+     * DOCUMENT ME!
+     *
+     * @param properties DOCUMENT ME!
+     * @param key DOCUMENT ME!
+     *
+     * @return DOCUMENT ME!
+     */
+    public String getProperty(Properties properties, String key) {
+        String value = properties.getProperty(key);
+
+        if (value != null) {
+            log.debug(key + "=" + value);
+
+            return value;
+        } else {
+            log.error("No such property: " + key);
+        }
+
+        return null;
+    }
+
+    /**
+     * DOCUMENT ME!
+     */
+    public static void register() {
+    }
+}
\ No newline at end of file

Modified: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/ProxyGenerator.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/ProxyGenerator.java?rev=332837&r1=332836&r2=332837&view=diff
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/ProxyGenerator.java (original)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/ProxyGenerator.java Sat Nov 12 13:06:37 2005
@@ -39,6 +39,7 @@
 import org.apache.commons.httpclient.HttpState;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.excalibur.xml.sax.SAXParser;
+import org.apache.lenya.cms.cocoon.generation.Configuration;
 import org.apache.log4j.Category;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -47,7 +48,17 @@
 public class ProxyGenerator extends org.apache.cocoon.generation.ServletGenerator implements
         Parameterizable {
     private static Category log = Category.getInstance(ProxyGenerator.class);
-
+    
+    private static String trustStore = null;
+    private static String trustStorePassword = null;    
+    
+    public ProxyGenerator() {
+        Configuration conf = new Configuration();
+        trustStore = conf.trustStore;
+        trustStorePassword = conf.trustStorePassword;
+        log.debug("loaded ProxyGenerator Config: " + "trustStore="+trustStore + " trustStorePassword=" + trustStorePassword);
+    }
+    
     // The URI of the namespace of this generator
     private String URI = "http://apache.org/cocoon/lenya/proxygenerator/1.0";
 
@@ -63,7 +74,7 @@
      */
     public void generate() throws SAXException {
         Request request = (Request) objectModel.get(ObjectModelHelper.REQUEST_OBJECT);
-
+        
         log.debug("\n----------------------------------------------------------------"
                 + "\n- Request: (" + request.getClass().getName() + ") at port "
                 + request.getServerPort()
@@ -140,14 +151,22 @@
                 String name = (String) e.nextElement();
                 httpMethod.addRequestHeader(name, request.getHeader(name));
             }
+                        
             HostConfiguration hostConfiguration = new HostConfiguration();
-            hostConfiguration.setHost(url.getHost(), url.getPort());
+            hostConfiguration.setHost(url.getHost(), url.getPort(), url.getProtocol());
 
             log.debug("\n----------------------------------------------------------------"
                     + "\n- Starting session at URI: " + url + "\n- Host:                    "
                     + url.getHost() + "\n- Port:                    " + url.getPort()
                     + "\n----------------------------------------------------------------");
-
+            
+            if (trustStore != null) {
+            	System.setProperty("javax.net.ssl.trustStore", trustStore);
+            }            
+            if (trustStorePassword != null) {
+            	System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);     
+            }
+            
             int result = httpClient.executeMethod(hostConfiguration, httpMethod);
 
             log.debug("\n----------------------------------------------------------------"
@@ -200,7 +219,7 @@
             url = new URL(this.source);
             log.debug(".createURL(): " + url);
         } catch (MalformedURLException e) {
-            url = new URL("http://" + request.getServerName() + ":" + request.getServerPort() + this.source);
+            url = new URL(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + this.source);
             log.debug(".createURL(): Add localhost and port: " + url);
         }
 

Added: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/conf.properties
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/conf.properties?rev=332837&view=auto
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/conf.properties (added)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/cocoon/generation/conf.properties Sat Nov 12 13:06:37 2005
@@ -0,0 +1,17 @@
+# Copyright 1999-2004 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+org.apache.lenya.cms.cocoon.generation.ProxyGenerator.trustStore=/home/lenya/.keystore
+org.apache.lenya.cms.cocoon.generation.ProxyGenerator.trustStorePassword=changeit
+



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org