You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by fl...@apache.org on 2010/11/24 15:27:58 UTC

svn commit: r1038622 - in /lenya/trunk/org.apache.lenya.core.proxy: ./ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/lenya/ src/main/java/org/apache/lenya/cms/ src/main/java/org/apache/lenya/cms/linking/ src/main/java/org/apache...

Author: florent
Date: Wed Nov 24 14:27:58 2010
New Revision: 1038622

URL: http://svn.apache.org/viewvc?rev=1038622&view=rev
Log:
populate proxy

Added:
    lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/
    lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/
    lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/
    lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/
    lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/
    lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/GlobalProxies.java
    lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/impl/
    lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/impl/GlobalProxiesImpl.java
    lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/publication/
    lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/publication/Proxy.java
      - copied, changed from r1034526, lenya/trunk/org.apache.lenya.core.publication.impl/src/main/java/org/apache/lenya/cms/publication/Proxy.java
    lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/publication/ProxyImpl.java
      - copied, changed from r1034526, lenya/trunk/org.apache.lenya.core.publication.impl/src/main/java/org/apache/lenya/cms/publication/Proxy.java
Modified:
    lenya/trunk/org.apache.lenya.core.proxy/pom.xml

Modified: lenya/trunk/org.apache.lenya.core.proxy/pom.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.proxy/pom.xml?rev=1038622&r1=1038621&r2=1038622&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.proxy/pom.xml (original)
+++ lenya/trunk/org.apache.lenya.core.proxy/pom.xml Wed Nov 24 14:27:58 2010
@@ -16,7 +16,10 @@
   <description>Implements proxy capabilities in Lenya</description>
   
   <dependencies>
-  
+  <dependency>
+      <groupId>org.apache.lenya</groupId>
+      <artifactId>lenya-core-document-api</artifactId>
+    </dependency>
   <!-- TODO : see if all theses dependencies are required -->
     <dependency>
       <groupId>org.apache.cocoon</groupId>

Added: lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/GlobalProxies.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/GlobalProxies.java?rev=1038622&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/GlobalProxies.java (added)
+++ lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/GlobalProxies.java Wed Nov 24 14:27:58 2010
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.
+ *
+ */
+package org.apache.lenya.cms.linking;
+
+import org.apache.lenya.cms.publication.Proxy;
+
+/**
+ * Service to manage the web-application-wide proxy settings.
+ */
+public interface GlobalProxies {
+    
+    /**
+     * The service role.
+     */
+    String ROLE = GlobalProxies.class.getName();
+    
+    /**
+     * @param ssl If SSL is used.
+     * @return A proxy.
+     */
+    Proxy getProxy(boolean ssl);
+
+}

Added: lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/impl/GlobalProxiesImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/impl/GlobalProxiesImpl.java?rev=1038622&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/impl/GlobalProxiesImpl.java (added)
+++ lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/linking/impl/GlobalProxiesImpl.java Wed Nov 24 14:27:58 2010
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.
+ *
+ */
+package org.apache.lenya.cms.linking.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cocoon.processing.ProcessInfoProvider;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
+import org.apache.cocoon.util.AbstractLogEnabled;
+import org.apache.lenya.cms.linking.GlobalProxies;
+import org.apache.lenya.cms.publication.Proxy;
+import org.apache.lenya.cms.publication.ProxyImpl;
+
+/**
+ * GlobalProxy service implementation.
+ * The class is implemented as a singleton.
+ */
+public class GlobalProxiesImpl extends AbstractLogEnabled implements GlobalProxies {
+    
+    private Map ssl2proxy = new HashMap();
+
+    public Proxy getProxy(boolean ssl) {
+        Object key = Boolean.valueOf(ssl);
+        Proxy proxy = (Proxy) this.ssl2proxy.get(key);
+        if (proxy == null) {
+            proxy = initializeProxy(key);
+        }
+        return proxy;
+    }
+
+    protected synchronized Proxy initializeProxy(Object key) {
+        ProcessInfoProvider process = (ProcessInfoProvider) WebAppContextUtils
+                .getCurrentWebApplicationContext().getBean(ProcessInfoProvider.ROLE);
+        Proxy proxy = new ProxyImpl();
+        proxy.setUrl(process.getRequest().getContextPath());
+        this.ssl2proxy.put(key, proxy);
+        return proxy;
+    }
+    
+    public void setNonSslProxyUrl(String url) {
+        Proxy proxy = new ProxyImpl();
+        proxy.setUrl(url);
+        setProxy(false, proxy);
+    }
+
+    public void setSslProxyUrl(String url) {
+        Proxy proxy = new ProxyImpl();
+        proxy.setUrl(url);
+        setProxy(true, proxy);
+    }
+
+    /**
+     * @param ssl If the proxy is responsible for SSL requests.
+     * @param proxy A proxy.
+     */
+    public void setProxy(boolean ssl, Proxy proxy) {
+        this.ssl2proxy.put(Boolean.valueOf(ssl), proxy);
+    }
+
+}

Copied: lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/publication/Proxy.java (from r1034526, lenya/trunk/org.apache.lenya.core.publication.impl/src/main/java/org/apache/lenya/cms/publication/Proxy.java)
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/publication/Proxy.java?p2=lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/publication/Proxy.java&p1=lenya/trunk/org.apache.lenya.core.publication.impl/src/main/java/org/apache/lenya/cms/publication/Proxy.java&r1=1034526&r2=1038622&rev=1038622&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.publication.impl/src/main/java/org/apache/lenya/cms/publication/Proxy.java (original)
+++ lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/publication/Proxy.java Wed Nov 24 14:27:58 2010
@@ -1,107 +1,35 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You 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.
- *
- */
 package org.apache.lenya.cms.publication;
 
-import org.apache.commons.lang.Validate;
+public interface Proxy {
+
+	/**
+	 * @param area The area.
+	 * @return The proxy URL if no proxy is declared in {@link PublicationConfiguration#CONFIGURATION_FILE}.
+	 */
+	public String getDefaultUrl();
+
+	/**
+	 * Returns the absolute URL of a particular document.
+	 * @param document The document.
+	 * @return A string.
+	 */
+	public String getURL(Document document);
+
+	/**
+	 * Returns the proxy URL.
+	 * @return A string.
+	 */
+	public String getUrl();
+
+	/**
+	 * Sets the proxy URL.
+	 * @param _url The url to set.
+	 */
+	public void setUrl(String _url);
+
+	/**
+	 * @see java.lang.Object#toString()
+	 */
+	public String toString();
 
-/**
- * <p>
- * An object of this class represents a proxy configuration.
- * </p>
- * <p>
- * Configuration example (<code>$PUB_HOME/config/publication.xml</code>):
- * </p>
- * <pre>
- * &lt;proxies&gt;
- *   &lt;proxy area="live" ssl="true" url="https://www.host.com/ssl/default"/&gt;
- *   &lt;proxy area="live" ssl="false" url="http://www.host.com/default"/&gt;
- *   &lt;proxy area="authoring" ssl="true" url="https://www.host.com/lenya/default/authoring"/&gt;
- *   &lt;proxy area="authoring" ssl="false" url="http://www.host.com/lenya/default/authoring"/&gt;
- * &lt;proxies;&gt;
- * </pre>
- * 
- * @version $Id$
- */
-public class Proxy {
-    
-    private String defaultUrl;
-    private String url;
-
-    /**
-     * @param defaultUrl The default proxy URL.
-     */
-    public Proxy(String defaultUrl) {
-        Validate.notNull(defaultUrl);
-        this.defaultUrl = defaultUrl;
-    }
-
-    /**
-     */
-    public Proxy() {
-    }
-
-    /**
-     * @param area The area.
-     * @return The proxy URL if no proxy is declared in {@link PublicationConfiguration#CONFIGURATION_FILE}.
-     */
-    public String getDefaultUrl() {
-        return this.defaultUrl;
-    }
-
-    /**
-     * Returns the absolute URL of a particular document.
-     * @param document The document.
-     * @return A string.
-     */
-    public String getURL(Document document) {
-        return getUrl() + document.getCanonicalDocumentURL();
-    }
-
-    /**
-     * Returns the proxy URL.
-     * @return A string.
-     */
-    public String getUrl() {
-        if (this.url != null) {
-            return this.url;
-        }
-        else if (this.defaultUrl != null) {
-            return this.defaultUrl;
-        }
-        else {
-            throw new IllegalStateException("This proxy has no URL.");
-        }
-    }
-
-    /**
-     * Sets the proxy URL.
-     * @param _url The url to set.
-     */
-    public void setUrl(String _url) {
-        Validate.notNull(_url);
-        this.url = _url;
-    }
-
-    /**
-     * @see java.lang.Object#toString()
-     */
-    public String toString() {
-        return "Proxy URL=[" + getUrl() + "]";
-    }
-    
 }
\ No newline at end of file

Copied: lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/publication/ProxyImpl.java (from r1034526, lenya/trunk/org.apache.lenya.core.publication.impl/src/main/java/org/apache/lenya/cms/publication/Proxy.java)
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/publication/ProxyImpl.java?p2=lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/publication/ProxyImpl.java&p1=lenya/trunk/org.apache.lenya.core.publication.impl/src/main/java/org/apache/lenya/cms/publication/Proxy.java&r1=1034526&r2=1038622&rev=1038622&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.publication.impl/src/main/java/org/apache/lenya/cms/publication/Proxy.java (original)
+++ lenya/trunk/org.apache.lenya.core.proxy/src/main/java/org/apache/lenya/cms/publication/ProxyImpl.java Wed Nov 24 14:27:58 2010
@@ -35,9 +35,8 @@ import org.apache.commons.lang.Validate;
  * &lt;proxies;&gt;
  * </pre>
  * 
- * @version $Id$
  */
-public class Proxy {
+public class ProxyImpl implements Proxy {
     
     private String defaultUrl;
     private String url;
@@ -45,14 +44,14 @@ public class Proxy {
     /**
      * @param defaultUrl The default proxy URL.
      */
-    public Proxy(String defaultUrl) {
+    public ProxyImpl(String defaultUrl) {
         Validate.notNull(defaultUrl);
         this.defaultUrl = defaultUrl;
     }
 
     /**
      */
-    public Proxy() {
+    public ProxyImpl() {
     }
 
     /**



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