You are viewing a plain text version of this content. The canonical link for it is here.
Posted to portalapps-dev@portals.apache.org by wo...@apache.org on 2014/07/22 04:22:12 UTC

svn commit: r1612445 - in /portals/applications/webcontent/trunk: ./ portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/ reverse-proxy/ reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/ reverse...

Author: woonsan
Date: Tue Jul 22 02:22:11 2014
New Revision: 1612445

URL: http://svn.apache.org/r1612445
Log:
APA-64: adding mapping and other configuration handling (in YAML)

Added:
    portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultReverseProxyPortlet.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java
    portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/
    portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/
    portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/web.xml
      - copied, changed from r1612176, portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/web.xml
    portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/index.jsp
    portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/portals-includes.jsp
      - copied, changed from r1612176, portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/portal-includes.jsp
Removed:
    portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/portal-includes.jsp
    portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/web.xml
Modified:
    portals/applications/webcontent/trunk/pom.xml
    portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java
    portals/applications/webcontent/trunk/reverse-proxy/pom.xml
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/ProxyMappingRegistry.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/DefaultProxyMappingRegistry.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/SimpleProxyMapping.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/DefaultReverseProxyServlet.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java

Modified: portals/applications/webcontent/trunk/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/pom.xml?rev=1612445&r1=1612444&r2=1612445&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/pom.xml (original)
+++ portals/applications/webcontent/trunk/pom.xml Tue Jul 22 02:22:11 2014
@@ -50,6 +50,7 @@
     <commons-chain.version>1.2</commons-chain.version>
     <velocity.version>1.6.3</velocity.version>
     <velocity-tools.version>1.3</velocity-tools.version>
+    <snakeyaml.version>1.13</snakeyaml.version>
 
     <maven-jetty-plugin.version>6.1.10</maven-jetty-plugin.version>
 
@@ -104,6 +105,12 @@
       </dependency>
 
       <dependency>
+        <groupId>org.yaml</groupId>
+        <artifactId>snakeyaml</artifactId>
+        <version>${snakeyaml.version}</version>
+      </dependency>
+
+      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-api</artifactId>
         <version>${slf4j.version}</version>

Added: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultReverseProxyPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultReverseProxyPortlet.java?rev=1612445&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultReverseProxyPortlet.java (added)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultReverseProxyPortlet.java Tue Jul 22 02:22:11 2014
@@ -0,0 +1,42 @@
+/* 
+ * 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.portals.applications.webcontent2.portlet.proxy;
+
+import org.apache.portals.applications.webcontent2.proxy.ReverseProxyService;
+import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+
+public class DefaultReverseProxyPortlet extends GenericVelocityPortlet
+{
+
+    private ReverseProxyService proxyService;
+
+    public DefaultReverseProxyPortlet()
+    {
+    }
+
+    public ReverseProxyService getProxyService()
+    {
+        return proxyService;
+    }
+
+    public void setProxyService(ReverseProxyService proxyService)
+    {
+        this.proxyService = proxyService;
+    }
+
+
+}

Modified: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java?rev=1612445&r1=1612444&r2=1612445&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java (original)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java Tue Jul 22 02:22:11 2014
@@ -21,6 +21,7 @@ import java.util.List;
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletException;
 
+import org.apache.commons.lang.math.NumberUtils;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.params.ConnManagerParamBean;
 import org.apache.http.conn.scheme.PlainSocketFactory;
@@ -31,7 +32,6 @@ import org.apache.http.impl.conn.tsccm.T
 import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.HttpParams;
 import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
-import org.apache.portals.applications.webcontent2.proxy.ReverseProxyService;
 import org.apache.portals.applications.webcontent2.proxy.command.AddCookiesToResponseCommand;
 import org.apache.portals.applications.webcontent2.proxy.command.AddHeaderToHttpRequestCommand;
 import org.apache.portals.applications.webcontent2.proxy.command.AddHeadersToResponseCommand;
@@ -52,40 +52,41 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.impl.DefaultReverseProxyService;
 import org.apache.portals.applications.webcontent2.proxy.impl.DefaultURICleaner;
 import org.apache.portals.applications.webcontent2.proxy.impl.ProxyProcessingChain;
-import org.apache.portals.applications.webcontent2.proxy.impl.SimpleProxyMapping;
-import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+import org.apache.portals.applications.webcontent2.proxy.util.YamlConfigUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class SimpleReverseProxyPortlet extends GenericVelocityPortlet
+public class SimpleReverseProxyPortlet extends DefaultReverseProxyPortlet
 {
 
     private static Logger log = LoggerFactory.getLogger(SimpleReverseProxyPortlet.class);
 
-    private ReverseProxyService proxyService;
+    public static final String MAPPINGS_PARAM_NAME = "mappings";
 
-    private ProxyProcessingChain proxyServiceCommand;
+    public static final String HTTP_MAX_TOTAL_CONNECTIONS_PARAM_NAME = "http.max.total.connections";
 
-    public SimpleReverseProxyPortlet()
-    {
-    }
+    public static final String HTTP_TIMEOUT_PARAM_NAME = "http.timeout";
 
-    public ReverseProxyService getProxyService()
-    {
-        return proxyService;
-    }
+    private int httpMaxTotalConnections = 400;
+
+    private long httpTimeout = 10000L;
 
-    public void setProxyService(ReverseProxyService proxyService)
+    private ProxyProcessingChain proxyServiceCommand;
+
+    public SimpleReverseProxyPortlet()
     {
-        this.proxyService = proxyService;
+        super();
     }
 
-
     @Override
     public void init(PortletConfig portletConfig) throws PortletException
     {
         super.init(portletConfig);
 
+        httpMaxTotalConnections = NumberUtils.toInt(portletConfig.getInitParameter(HTTP_MAX_TOTAL_CONNECTIONS_PARAM_NAME), httpMaxTotalConnections);
+
+        httpTimeout = NumberUtils.toLong(portletConfig.getInitParameter(HTTP_TIMEOUT_PARAM_NAME), httpTimeout);
+
         proxyServiceCommand = createProxyServiceCommand(portletConfig);
 
         List<AbstractProxyCommand> allProxyCommands = proxyServiceCommand.getAllProxyCommands();
@@ -99,25 +100,6 @@ public class SimpleReverseProxyPortlet e
         setProxyService(proxyService);
     }
 
-    @Override
-    public void destroy() {
-        List<AbstractProxyCommand> allProxyCommands = proxyServiceCommand.getAllProxyCommands();
-
-        for (AbstractProxyCommand proxyCommand : allProxyCommands)
-        {
-            try
-            {
-                proxyCommand.destroy();
-            }
-            catch (Exception e)
-            {
-                log.error("Failed to destroy proxy command, " + proxyCommand, e);
-            }
-        }
-
-        super.destroy();
-    }
-
     protected ProxyProcessingChain createProxyServiceCommand(final PortletConfig portletConfig)
     {
         ProxyProcessingChain preprocessingChain = new ProxyProcessingChain();
@@ -130,10 +112,7 @@ public class SimpleReverseProxyPortlet e
 
         ResolveLocalPathCommand resolveLocalPathCommand = new ResolveLocalPathCommand();
 
-        // TODO: read config
-        ProxyMappingRegistry proxyMappingRegistry = new DefaultProxyMappingRegistry();
-        proxyMappingRegistry.addProxyMapping(new SimpleProxyMapping("/", "http://portals.apache.org/", null));
-        ResolveProxyMappingCommand resolveProxyMappingCommand = new ResolveProxyMappingCommand(proxyMappingRegistry);
+        ResolveProxyMappingCommand resolveProxyMappingCommand = new ResolveProxyMappingCommand(createProxyMappingRegistry());
 
         ResolveRemoteURICommand resolveRemoteURICommand = new ResolveRemoteURICommand();
         resolveRemoteURICommand.setUriCleaner(new DefaultURICleaner());
@@ -145,8 +124,8 @@ public class SimpleReverseProxyPortlet e
         schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
         HttpParams connManagerParams = new BasicHttpParams();
         ConnManagerParamBean connManagerParamBean = new ConnManagerParamBean(connManagerParams);
-        connManagerParamBean.setMaxTotalConnections(400);
-        connManagerParamBean.setTimeout(10000L);
+        connManagerParamBean.setMaxTotalConnections(httpMaxTotalConnections);
+        connManagerParamBean.setTimeout(httpTimeout);
         ClientConnectionManager clientConnectionManager = new ThreadSafeClientConnManager(connManagerParams, schemeRegistry);
         initHttpClientCommand.setClientConnectionManager(clientConnectionManager);
         initHttpClientCommand.setHttpClientParams(new BasicHttpParams());
@@ -189,4 +168,31 @@ public class SimpleReverseProxyPortlet e
         return proxyServiceChain;
     }
 
+    protected ProxyMappingRegistry createProxyMappingRegistry()
+    {
+        ProxyMappingRegistry proxyMappingRegistry = new DefaultProxyMappingRegistry();
+        final String param = getPortletConfig().getInitParameter(MAPPINGS_PARAM_NAME);
+        proxyMappingRegistry.addAllProxyMappings(YamlConfigUtils.loadProxyMappings(param, getPortletContext()));
+        return proxyMappingRegistry;
+    }
+
+    @Override
+    public void destroy() {
+        List<AbstractProxyCommand> allProxyCommands = proxyServiceCommand.getAllProxyCommands();
+
+        for (AbstractProxyCommand proxyCommand : allProxyCommands)
+        {
+            try
+            {
+                proxyCommand.destroy();
+            }
+            catch (Exception e)
+            {
+                log.error("Failed to destroy proxy command, " + proxyCommand, e);
+            }
+        }
+
+        super.destroy();
+    }
+
 }

Modified: portals/applications/webcontent/trunk/reverse-proxy/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/pom.xml?rev=1612445&r1=1612444&r2=1612445&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/pom.xml (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/pom.xml Tue Jul 22 02:22:11 2014
@@ -80,6 +80,11 @@
     </dependency>
 
     <dependency>
+      <groupId>org.yaml</groupId>
+      <artifactId>snakeyaml</artifactId>
+    </dependency>
+
+    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
       <scope>test</scope>
@@ -102,7 +107,7 @@
   <profiles>
 
     <!--
-      You can run `mvn -Prun clean veryfy' for easier testing at http://localhost:8080/rproxy.
+      You can run `mvn -Prun clean veryfy' for easier testing at http://localhost:8080/rproxy/.
       Also, you can run the following for remote debugging:
 
       $ export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
@@ -154,8 +159,7 @@
             </executions>
             <configuration>
               <contextPath>/rproxy</contextPath>
-              <webAppSourceDirectory>${basedir}/src/test/resources</webAppSourceDirectory>
-              <webXml>${basedir}/target/test-classes/web.xml</webXml>
+              <webAppSourceDirectory>${basedir}/src/test/webapp</webAppSourceDirectory>
               <classesDirectory>${basedir}/target/classes, ${basedir}/target/test-classes</classesDirectory>
               <systemProperties>
                 <systemProperty>

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/ProxyMappingRegistry.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/ProxyMappingRegistry.java?rev=1612445&r1=1612444&r2=1612445&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/ProxyMappingRegistry.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/ProxyMappingRegistry.java Tue Jul 22 02:22:11 2014
@@ -25,6 +25,8 @@ public interface ProxyMappingRegistry
 
     public boolean addProxyMapping(ProxyMapping proxyMapping);
 
+    public boolean addAllProxyMappings(Collection<ProxyMapping> proxyMappings);
+
     public boolean removeProxyMapping(ProxyMapping proxyMapping);
 
     public Collection<ProxyMapping> getProxyMappings();

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/DefaultProxyMappingRegistry.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/DefaultProxyMappingRegistry.java?rev=1612445&r1=1612444&r2=1612445&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/DefaultProxyMappingRegistry.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/DefaultProxyMappingRegistry.java Tue Jul 22 02:22:11 2014
@@ -36,6 +36,16 @@ public class DefaultProxyMappingRegistry
         return proxyMappings.add(proxyMapping);
     }
 
+    public boolean addAllProxyMappings(Collection<ProxyMapping> proxyMappingsCollection)
+    {
+        if (proxyMappingsCollection != null)
+        {
+            return this.proxyMappings.addAll(proxyMappingsCollection);
+        }
+
+        return false;
+    }
+
     public boolean removeProxyMapping(ProxyMapping proxyMapping)
     {
         return proxyMappings.remove(proxyMapping);
@@ -53,13 +63,9 @@ public class DefaultProxyMappingRegistry
             return null;
         }
 
-        String localBasePath = null;
-
         for (ProxyMapping proxyMapping : proxyMappings)
         {
-            localBasePath = proxyMapping.getLocalBasePath();
-
-            if (localBasePath != null && localPath.startsWith(localBasePath))
+            if (proxyMapping.matchesLocal(localPath))
             {
                 return proxyMapping;
             }
@@ -75,13 +81,9 @@ public class DefaultProxyMappingRegistry
             return null;
         }
 
-        String remoteBaseURI = null;
-
         for (ProxyMapping proxyMapping : proxyMappings)
         {
-            remoteBaseURI = proxyMapping.getRemoteBaseURI();
-
-            if (remoteBaseURI != null && remoteURI.startsWith(remoteBaseURI))
+            if (proxyMapping.matchesRemote(remoteURI))
             {
                 return proxyMapping;
             }

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/SimpleProxyMapping.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/SimpleProxyMapping.java?rev=1612445&r1=1612444&r2=1612445&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/SimpleProxyMapping.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/SimpleProxyMapping.java Tue Jul 22 02:22:11 2014
@@ -22,15 +22,12 @@ import org.apache.portals.applications.w
 public class SimpleProxyMapping extends AbstractProxyMapping
 {
 
-    private final String localBasePath;
-    private final String remoteBaseURI;
-    private final ContentRewriter contentRewriter;
+    private String localBasePath;
+    private String remoteBaseURI;
+    private ContentRewriter contentRewriter;
 
-    public SimpleProxyMapping(final String localBasePath, final String remoteBaseURI, final ContentRewriter contentRewriter)
+    public SimpleProxyMapping()
     {
-        this.localBasePath = localBasePath;
-        this.remoteBaseURI = remoteBaseURI;
-        this.contentRewriter = contentRewriter;
     }
 
     public String getLocalBasePath()
@@ -38,11 +35,31 @@ public class SimpleProxyMapping extends 
         return localBasePath;
     }
 
+    public void setLocalBasePath(String localBasePath)
+    {
+        this.localBasePath = localBasePath;
+    }
+
     public String getRemoteBaseURI()
     {
         return remoteBaseURI;
     }
 
+    public void setRemoteBaseURI(String remoteBaseURI)
+    {
+        this.remoteBaseURI = remoteBaseURI;
+    }
+
+    public ContentRewriter getContentRewriter()
+    {
+        return contentRewriter;
+    }
+
+    public void setContentRewriter(ContentRewriter contentRewriter)
+    {
+        this.contentRewriter = contentRewriter;
+    }
+
     public boolean matchesLocal(String localPath)
     {
         return StringUtils.startsWith(localPath, localBasePath);
@@ -73,8 +90,4 @@ public class SimpleProxyMapping extends 
         return null;
     }
 
-    public ContentRewriter getContentRewriter()
-    {
-        return contentRewriter;
-    }
 }

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/DefaultReverseProxyServlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/DefaultReverseProxyServlet.java?rev=1612445&r1=1612444&r2=1612445&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/DefaultReverseProxyServlet.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/DefaultReverseProxyServlet.java Tue Jul 22 02:22:11 2014
@@ -61,6 +61,10 @@ public class DefaultReverseProxyServlet 
 
     private ReverseProxyService proxyService;
 
+    public DefaultReverseProxyServlet()
+    {
+    }
+
     public ReverseProxyService getProxyService()
     {
         return proxyService;

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java?rev=1612445&r1=1612444&r2=1612445&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java Tue Jul 22 02:22:11 2014
@@ -21,6 +21,7 @@ import java.util.List;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 
+import org.apache.commons.lang.math.NumberUtils;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.params.ConnManagerParamBean;
 import org.apache.http.conn.scheme.PlainSocketFactory;
@@ -51,7 +52,7 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.impl.DefaultReverseProxyService;
 import org.apache.portals.applications.webcontent2.proxy.impl.DefaultURICleaner;
 import org.apache.portals.applications.webcontent2.proxy.impl.ProxyProcessingChain;
-import org.apache.portals.applications.webcontent2.proxy.impl.SimpleProxyMapping;
+import org.apache.portals.applications.webcontent2.proxy.util.YamlConfigUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -65,13 +66,32 @@ public class SimpleReverseProxyServlet e
 
     private static Logger log = LoggerFactory.getLogger(SimpleReverseProxyServlet.class);
 
+    public static final String MAPPINGS_PARAM_NAME = "mappings";
+
+    public static final String HTTP_MAX_TOTAL_CONNECTIONS_PARAM_NAME = "http.max.total.connections";
+
+    public static final String HTTP_TIMEOUT_PARAM_NAME = "http.timeout";
+
+    private int httpMaxTotalConnections = 400;
+
+    private long httpTimeout = 10000L;
+
     private ProxyProcessingChain proxyServiceCommand;
 
+    public SimpleReverseProxyServlet()
+    {
+        super();
+    }
+
     @Override
     public void init(ServletConfig servletConfig) throws ServletException
     {
         super.init(servletConfig);
 
+        httpMaxTotalConnections = NumberUtils.toInt(servletConfig.getInitParameter(HTTP_MAX_TOTAL_CONNECTIONS_PARAM_NAME), httpMaxTotalConnections);
+
+        httpTimeout = NumberUtils.toLong(servletConfig.getInitParameter(HTTP_TIMEOUT_PARAM_NAME), httpTimeout);
+
         proxyServiceCommand = createProxyServiceCommand(servletConfig);
 
         List<AbstractProxyCommand> allProxyCommands = proxyServiceCommand.getAllProxyCommands();
@@ -97,10 +117,7 @@ public class SimpleReverseProxyServlet e
 
         ResolveLocalPathCommand resolveLocalPathCommand = new ResolveLocalPathCommand();
 
-        // TODO: read config
-        ProxyMappingRegistry proxyMappingRegistry = new DefaultProxyMappingRegistry();
-        proxyMappingRegistry.addProxyMapping(new SimpleProxyMapping("/", "http://portals.apache.org/", null));
-        ResolveProxyMappingCommand resolveProxyMappingCommand = new ResolveProxyMappingCommand(proxyMappingRegistry);
+        ResolveProxyMappingCommand resolveProxyMappingCommand = new ResolveProxyMappingCommand(createProxyMappingRegistry());
 
         ResolveRemoteURICommand resolveRemoteURICommand = new ResolveRemoteURICommand();
         resolveRemoteURICommand.setUriCleaner(new DefaultURICleaner());
@@ -112,8 +129,8 @@ public class SimpleReverseProxyServlet e
         schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
         HttpParams connManagerParams = new BasicHttpParams();
         ConnManagerParamBean connManagerParamBean = new ConnManagerParamBean(connManagerParams);
-        connManagerParamBean.setMaxTotalConnections(400);
-        connManagerParamBean.setTimeout(10000L);
+        connManagerParamBean.setMaxTotalConnections(httpMaxTotalConnections);
+        connManagerParamBean.setTimeout(httpTimeout);
         ClientConnectionManager clientConnectionManager = new ThreadSafeClientConnManager(connManagerParams, schemeRegistry);
         initHttpClientCommand.setClientConnectionManager(clientConnectionManager);
         initHttpClientCommand.setHttpClientParams(new BasicHttpParams());
@@ -156,6 +173,14 @@ public class SimpleReverseProxyServlet e
         return proxyServiceChain;
     }
 
+    protected ProxyMappingRegistry createProxyMappingRegistry()
+    {
+        ProxyMappingRegistry proxyMappingRegistry = new DefaultProxyMappingRegistry();
+        final String param = getServletConfig().getInitParameter(MAPPINGS_PARAM_NAME);
+        proxyMappingRegistry.addAllProxyMappings(YamlConfigUtils.loadProxyMappings(param, getServletContext()));
+        return proxyMappingRegistry;
+    }
+
     @Override
     public void destroy()
     {

Added: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java?rev=1612445&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java (added)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java Tue Jul 22 02:22:11 2014
@@ -0,0 +1,129 @@
+/*
+ * 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.portals.applications.webcontent2.proxy.util;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.beanutils.MethodUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.text.StrSubstitutor;
+import org.apache.portals.applications.webcontent2.proxy.ProxyMapping;
+import org.apache.portals.applications.webcontent2.proxy.impl.SimpleProxyMapping;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.TypeDescription;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.BaseConstructor;
+import org.yaml.snakeyaml.constructor.Constructor;
+
+public class YamlConfigUtils
+{
+
+    private static Logger log = LoggerFactory.getLogger(YamlConfigUtils.class);
+
+    public static Iterable<Object> loadYaml(BaseConstructor constructor, String yamlConfig, Object servletContextOrPortletContext)
+    {
+        Iterable<Object> allObjects = null;
+
+        String mappingYaml = null;
+        InputStream input = null;
+        BufferedInputStream bis = null;
+
+        final String mappings = StrSubstitutor.replaceSystemProperties(StringUtils.trim(yamlConfig));
+
+        if (StringUtils.isNotEmpty(mappings))
+        {
+            try
+            {
+                if (StringUtils.startsWith(mappings, "file:"))
+                {
+                    input = new FileInputStream(new File(URI.create(mappings)));
+                }
+                else if (StringUtils.startsWith(mappings, "classpath:"))
+                {
+                    input = Thread.currentThread().getContextClassLoader().getResourceAsStream(mappings.substring(10));
+                }
+                else if (StringUtils.startsWith(mappings, "/"))
+                {
+                    input = (InputStream) MethodUtils.invokeMethod(servletContextOrPortletContext, "getResourceAsStream", mappings);
+                }
+                else
+                {
+                    mappingYaml = mappings;
+                }
+
+                Yaml yaml = new Yaml(constructor);
+
+                if (mappingYaml != null)
+                {
+                    allObjects = yaml.loadAll(mappingYaml);
+                }
+                else if (input != null)
+                {
+                    bis = new BufferedInputStream(input);
+                    allObjects = yaml.loadAll(bis);
+                }
+            }
+            catch (Exception e)
+            {
+                log.error("Failed to load yaml configuration at '{}'. {}", yamlConfig, e);
+            }
+            finally
+            {
+                IOUtils.closeQuietly(bis);
+                IOUtils.closeQuietly(input);
+            }
+        }
+
+        return allObjects;
+    }
+
+    public static List<ProxyMapping> loadProxyMappings(String yamlConfig, Object servletContextOrPortletContext)
+    {
+        List<ProxyMapping> proxyMappings = new ArrayList<ProxyMapping>();
+
+        Constructor constructor = new Constructor();
+        constructor.addTypeDescription(new TypeDescription(SimpleProxyMapping.class, "!mapping"));
+
+        Iterable<Object> allObjects = loadYaml(constructor, yamlConfig, servletContextOrPortletContext);
+
+        for (Object mapping : allObjects)
+        {
+            if (mapping instanceof ProxyMapping)
+            {
+                proxyMappings.add((ProxyMapping) mapping);
+            }
+            else
+            {
+                log.error("Invalid mapping type: {} - {}" + mapping.getClass(), mapping);
+            }
+        }
+
+        return proxyMappings;
+    }
+
+    private YamlConfigUtils()
+    {
+    }
+}

Copied: portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/web.xml (from r1612176, portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/web.xml)
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/web.xml?p2=portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/web.xml&p1=portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/web.xml&r1=1612176&r2=1612445&rev=1612445&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/web.xml (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/web.xml Tue Jul 22 02:22:11 2014
@@ -25,13 +25,25 @@
   <servlet>
     <servlet-name>ReverseProxyServlet</servlet-name>
     <servlet-class>org.apache.portals.applications.webcontent2.proxy.servlet.SimpleReverseProxyServlet</servlet-class>
+    <init-param>
+      <param-name>mappings</param-name>
+      <param-value>
+--- !mapping
+localBasePath: /applications/
+remoteBaseURI: http://portals.apache.org/applications/
+
+--- !mapping
+localBasePath: /bridges/
+remoteBaseURI: http://portals.apache.org/bridges/
+      </param-value>
+    </init-param>
     <load-on-startup>0</load-on-startup>
   </servlet>
   
   <!-- Map /* path to the Reverse Proxy Servlet -->
   <servlet-mapping>
     <servlet-name>ReverseProxyServlet</servlet-name>
-    <url-pattern>/portal/*</url-pattern>
+    <url-pattern>/portals/*</url-pattern>
   </servlet-mapping>
   
 </web-app>

Added: portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/index.jsp
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/index.jsp?rev=1612445&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/index.jsp (added)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/index.jsp Tue Jul 22 02:22:11 2014
@@ -0,0 +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.
+--%>
+<%@ page language="java"%>
+<html>
+<head>
+<title>Apache Portals Application Web Content 2</title>
+</head>
+<body>
+
+<h1>Apache Portals Application Web Content 2</h1>
+
+<hr/>
+
+<ul>
+  <li><a href="portals/applications/" target="_blank">Apache Portals Applications (reverse proxied)</a></li>
+  <li><a href="portals/bridges/" target="_blank">Apache Portals Bridges (reverse proxied)</a></li>
+  <li><a href="portals-includes.jsp" target="_blank">JSP Include for Apache Portals Applications (reverse proxied)</a></li>
+</ul>
+
+</body>
+</html>

Copied: portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/portals-includes.jsp (from r1612176, portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/portal-includes.jsp)
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/portals-includes.jsp?p2=portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/portals-includes.jsp&p1=portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/portal-includes.jsp&r1=1612176&r2=1612445&rev=1612445&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/portal-includes.jsp (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/portals-includes.jsp Tue Jul 22 02:22:11 2014
@@ -14,23 +14,18 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY 
 See the License for the specific language governing permissions and
 limitations under the License.
 --%>
-
 <%@ page language="java"%>
-<%@ page import="javax.servlet.http.HttpServletRequest" %>
-<%@ page import="org.apache.commons.codec.binary.Base64" %>
-<%@ page import="org.apache.commons.lang.StringUtils" %>
-
 <html>
 <head>
-<title>Apache Software License</title>
+<title>Apache Portals Applications</title>
 </head>
 <body>
 
-<h1>Apache Software License</h1>
+<h1>Apache Portals Applications</h1>
 
 <hr/>
 
-<jsp:include page="/portal/license.html" />
+<jsp:include page="/portals/applications/" />
 
 </body>
 </html>