You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2007/07/03 14:51:54 UTC
svn commit: r552818 - in /lenya/trunk/src:
impl/java/org/apache/lenya/cms/publication/
modules-core/linking/config/cocoon-xconf/
modules-core/linking/java/src/org/apache/lenya/cms/linking/
modules-core/linking/java/src/org/apache/lenya/cms/linking/impl...
Author: andreas
Date: Tue Jul 3 05:51:52 2007
New Revision: 552818
URL: http://svn.apache.org/viewvc?view=rev&rev=552818
Log:
Replaced per-publication <proxies root=/> configuration with GlobalProxies service. See http://www.nabble.com/-1.4---Proposal--Global-proxy-configuration-tf3999411.html.
Added:
lenya/trunk/src/modules-core/linking/config/cocoon-xconf/globalproxies.xconf
lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/GlobalProxies.java
lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/impl/
lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/impl/GlobalProxiesImpl.java
Modified:
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationImpl.java
lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/OutgoingLinkRewriter.java
lenya/trunk/src/pubs/default/config/publication.xml
Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java?view=diff&rev=552818&r1=552817&r2=552818
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java Tue Jul 3 05:51:52 2007
@@ -81,8 +81,6 @@
private static final String ELEMENT_BREADCRUMB_PREFIX = "breadcrumb-prefix";
private static final String ELEMENT_CONTENT_DIR = "content-dir";
private static final String ATTRIBUTE_SRC = "src";
- private static final String ELEMENT_PROXIES = "proxies";
- protected static final String ATTRIBUTE_ROOT = "root";
private static final String ELEMENT_PROXY = "proxy";
private static final String ATTRIBUTE_AREA = "area";
private static final String ATTRIBUTE_URL = "url";
@@ -181,35 +179,21 @@
this.siteManagerName = siteManagerConfiguration.getAttribute(ATTRIBUTE_NAME);
}
- Configuration proxyConfig = config.getChild(ELEMENT_PROXIES);
- if (proxyConfig != null) {
- // root/global proxy
- String urlRoot = proxyConfig.getAttribute(ATTRIBUTE_ROOT, null);
- String sslRoot = proxyConfig.getAttribute(ATTRIBUTE_SSL, null);
- if (urlRoot != null & sslRoot != null) {
- Proxy rootProxy = new Proxy();
- rootProxy.setUrl(urlRoot);
- Object rootKey = getProxyKey(ATTRIBUTE_ROOT, Boolean.valueOf(sslRoot)
- .booleanValue());
- this.areaSsl2proxy.put(rootKey, rootProxy);
- }
- // Area proxies
- Configuration[] proxyConfigs = proxyConfig.getChildren(ELEMENT_PROXY);
- for (int i = 0; i < proxyConfigs.length; i++) {
- String url = proxyConfigs[i].getAttribute(ATTRIBUTE_URL);
- String ssl = proxyConfigs[i].getAttribute(ATTRIBUTE_SSL);
- String area = proxyConfigs[i].getAttribute(ATTRIBUTE_AREA);
-
- Proxy proxy = new Proxy();
- proxy.setUrl(url);
-
- Object key = getProxyKey(area, Boolean.valueOf(ssl).booleanValue());
- this.areaSsl2proxy.put(key, proxy);
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(
- "Adding proxy: [" + proxy + "] for area=[" + area + "] SSL=[" + ssl
- + "]");
- }
+ Configuration[] proxyConfigs = config.getChildren(ELEMENT_PROXY);
+ for (int i = 0; i < proxyConfigs.length; i++) {
+ String url = proxyConfigs[i].getAttribute(ATTRIBUTE_URL);
+ String ssl = proxyConfigs[i].getAttribute(ATTRIBUTE_SSL);
+ String area = proxyConfigs[i].getAttribute(ATTRIBUTE_AREA);
+
+ Proxy proxy = new Proxy();
+ proxy.setUrl(url);
+
+ Object key = getProxyKey(area, Boolean.valueOf(ssl).booleanValue());
+ this.areaSsl2proxy.put(key, proxy);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(
+ "Adding proxy: [" + proxy + "] for area=[" + area + "] SSL=[" + ssl
+ + "]");
}
}
@@ -223,7 +207,7 @@
// with all kinds of NPEs that keep cropping up...
if (templateConfig == null) {
this.templates = new String[0]; // ugh. empty array to keep the
- // legacy code from breaking.
+ // legacy code from breaking.
} else {
this.templates = new String[1];
this.templates[0] = templateConfig.getAttribute(ATTRIBUTE_ID);
@@ -440,7 +424,7 @@
Proxy proxy = (Proxy) this.areaSsl2proxy.get(key);
return proxy;
}
-
+
/**
* @param area The area.
* @param isSslProtected If the proxy is for SSL-protected URLs.
Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationImpl.java?view=diff&rev=552818&r1=552817&r2=552818
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationImpl.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/PublicationImpl.java Tue Jul 3 05:51:52 2007
@@ -147,12 +147,7 @@
* @return The proxy URL if no proxy is declared in {@link PublicationConfiguration#CONFIGURATION_FILE}.
*/
protected String getDefaultProxyUrl(String area) {
- if (area.equals(PublicationConfiguration.ATTRIBUTE_ROOT)) {
- return getContextPath();
- }
- else {
- return getContextPath() + "/" + getId() + "/" + area;
- }
+ return getContextPath() + "/" + getId() + "/" + area;
}
private List allResourceTypes;
Added: lenya/trunk/src/modules-core/linking/config/cocoon-xconf/globalproxies.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/config/cocoon-xconf/globalproxies.xconf?view=auto&rev=552818
==============================================================================
--- lenya/trunk/src/modules-core/linking/config/cocoon-xconf/globalproxies.xconf (added)
+++ lenya/trunk/src/modules-core/linking/config/cocoon-xconf/globalproxies.xconf Tue Jul 3 05:51:52 2007
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+
+<!-- $Id:$ -->
+
+<xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.cms.linking.GlobalProxies']">
+
+ <component logger="lenya.proxy"
+ role="org.apache.lenya.cms.linking.GlobalProxies"
+ class="org.apache.lenya.cms.linking.impl.GlobalProxiesImpl"/>
+
+</xconf>
Added: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/GlobalProxies.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/GlobalProxies.java?view=auto&rev=552818
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/GlobalProxies.java (added)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/GlobalProxies.java Tue Jul 3 05:51:52 2007
@@ -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);
+
+}
Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/OutgoingLinkRewriter.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/OutgoingLinkRewriter.java?view=diff&rev=552818&r1=552817&r2=552818
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/OutgoingLinkRewriter.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/OutgoingLinkRewriter.java Tue Jul 3 05:51:52 2007
@@ -21,6 +21,7 @@
import java.util.Arrays;
import java.util.List;
+import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.lenya.ac.AccessController;
@@ -39,8 +40,8 @@
/**
* <p>
* Converts web application links to links which will be sent to the browser by
- * using the publication's proxy settings. If the current request is SSL-encrypted,
- * all link URLs will use the SSL proxy.
+ * using the publication's proxy settings. If the current request is
+ * SSL-encrypted, all link URLs will use the SSL proxy.
* </p>
* <p>
* Objects of this class are not thread-safe.
@@ -48,14 +49,12 @@
*/
public class OutgoingLinkRewriter extends ServletLinkRewriter {
- private static final String ATTRIBUTE_ROOT = "root";
-
private boolean relativeUrls;
private PolicyManager policyManager;
private AccreditableManager accreditableManager;
private DocumentFactory factory;
- private Publication publication;
private boolean ssl;
+ private GlobalProxies globalProxies;
/**
* @param manager The service manager to use.
@@ -77,11 +76,6 @@
try {
this.factory = DocumentUtil.createDocumentFactory(this.manager, session);
- URLInformation info = new URLInformation(requestUrl);
- String pubId = info.getPublicationId();
- if (pubId != null && isPublication(pubId)) {
- this.publication = this.factory.getPublication(pubId);
- }
serviceSelector = (ServiceSelector) this.manager.lookup(AccessControllerResolver.ROLE
+ "Selector");
@@ -102,7 +96,17 @@
this.manager.release(serviceSelector);
}
}
+ }
+ protected GlobalProxies getGlobalProxies() {
+ if (this.globalProxies == null) {
+ try {
+ this.globalProxies = (GlobalProxies) this.manager.lookup(GlobalProxies.ROLE);
+ } catch (ServiceException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return this.globalProxies;
}
public boolean matches(String url) {
@@ -131,15 +135,10 @@
rewrittenUrl = rewriteLink(url, pub, useSsl);
}
- // link doesn't point to publication -> use own publication if
- // exists
- else if (this.publication != null) {
- rewrittenUrl = rewriteLink(url, this.publication, useSsl);
- }
-
- // link doesn't point to publication, no own publication
+ // link doesn't point to publication
else {
- rewrittenUrl = getContextPath() + url;
+ Proxy proxy = getGlobalProxies().getProxy(ssl);
+ rewrittenUrl = proxy.getUrl() + url;
}
}
} catch (Exception e) {
@@ -169,7 +168,7 @@
// invalid area
else {
- Proxy proxy = pub.getProxy(ATTRIBUTE_ROOT, ssl);
+ Proxy proxy = getGlobalProxies().getProxy(ssl);
rewrittenUrl = proxy.getUrl() + linkUrl;
}
return rewrittenUrl;
Added: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/impl/GlobalProxiesImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/impl/GlobalProxiesImpl.java?view=auto&rev=552818
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/impl/GlobalProxiesImpl.java (added)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/impl/GlobalProxiesImpl.java Tue Jul 3 05:51:52 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.lenya.cms.cocoon.components.context.ContextUtility;
+import org.apache.lenya.cms.linking.GlobalProxies;
+import org.apache.lenya.cms.publication.Proxy;
+
+/**
+ * GlobalProxy service implementation.
+ * The class is implemented as a singleton.
+ */
+public class GlobalProxiesImpl extends AbstractLogEnabled implements GlobalProxies, Serviceable,
+ ThreadSafe, Configurable {
+
+ private Map ssl2proxy = new HashMap();
+ private ServiceManager manager;
+
+ 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) {
+ Proxy proxy;
+ proxy = new Proxy();
+ ContextUtility context = null;
+ try {
+ context = (ContextUtility) manager.lookup(ContextUtility.ROLE);
+ proxy.setUrl(context.getRequest().getContextPath());
+ } catch (ServiceException e) {
+ throw new RuntimeException(e);
+ }
+ finally {
+ if (context != null) {
+ this.manager.release(context);
+ }
+ }
+ this.ssl2proxy.put(key, proxy);
+ return proxy;
+ }
+
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+
+ public void configure(Configuration config) throws ConfigurationException {
+ Configuration[] proxyConfigs = config.getChildren("proxy");
+ for (int p = 0; p < proxyConfigs.length; p++) {
+ boolean ssl = proxyConfigs[p].getAttributeAsBoolean("ssl");
+ String url = proxyConfigs[p].getAttribute("url");
+ Proxy proxy = new Proxy();
+ proxy.setUrl(url);
+ this.ssl2proxy.put(Boolean.valueOf(ssl), proxy);
+ }
+ }
+
+}
Modified: lenya/trunk/src/pubs/default/config/publication.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/config/publication.xml?view=diff&rev=552818&r1=552817&r2=552818
==============================================================================
--- lenya/trunk/src/pubs/default/config/publication.xml (original)
+++ lenya/trunk/src/pubs/default/config/publication.xml Tue Jul 3 05:51:52 2007
@@ -100,13 +100,16 @@
-->
<!-- Lenya can rewrite the links to cater to special proxy setups.
- For information about these settings, read http://lenya.apache.org/1_2_x/components/deployment/proxying.html
- (yes, this needs some updating... sorry.)--><!--
- <proxies ssl="false" root="http://www.host.com/non-ssl/">
- <proxy area="live" ssl="true" url="https://www.host.com/ssl/default"/>
- <proxy area="live" ssl="false" url="http://www.host.com/default"/>
- <proxy area="authoring" ssl="true" url="https://www.host.com/lenya/default/authoring"/>
- <proxy area="authoring" ssl="false" url="http://www.host.com/lenya/default/authoring"/>
- </proxies>
+ Make sure to update the GlobalProxies configuration in cocoon.xconf as well.
+ For information about these settings, read
+ http://lenya.zones.apache.org/docu/docs/1_4/tutorials/proxy.html
+ FIXME: Update to lenya.apache.org page as soon as the website is updated
+ -->
+ <!--
+ <proxy area="live" ssl="true" url="https://www.host.com/ssl/default"/>
+ <proxy area="live" ssl="false" url="http://www.host.com/default"/>
+ <proxy area="authoring" ssl="true" url="https://cms.host.com/default"/>
+ <proxy area="authoring" ssl="false" url="http://cms.host.com/default"/>
-->
+
</publication>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org