portals-portalapps-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r1647444 [1/2] - in /portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy: builder/ command/ filter/ rewriter/ servlet/ util/
Date Mon, 22 Dec 2014 23:23:16 GMT
Author: woonsan
Date: Mon Dec 22 23:23:15 2014
New Revision: 1647444

URL: http://svn.apache.org/r1647444
Log:
APA-67: javadocs in reverse-proxy packages

Added:
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/AbstractProxyProcessingChainBuilder.java
Modified:
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultProxyProcessingChainBuilder.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/ProxyProcessingChainBuilder.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/ProxyServices.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeaderToHttpRequestCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeadersToResponseCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/CleanupCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ExecuteHttpClientCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleNotModifiedCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleRedirectionCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpClientCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpRequestCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitializationCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveContentRewriterCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveLocalPathCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveProxyMappingCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveRemoteURICommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/SerializeHttpEntityContentCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/GenericReverseProxyFilter.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/SimpleReverseProxyFilter.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/GenericReverseProxyServlet.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/CharArraySegment.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/ProxyCommandUtils.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/RequestUtils.java
    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/builder/AbstractProxyProcessingChainBuilder.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/AbstractProxyProcessingChainBuilder.java?rev=1647444&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/AbstractProxyProcessingChainBuilder.java (added)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/AbstractProxyProcessingChainBuilder.java Mon Dec 22 23:23:15 2014
@@ -0,0 +1,133 @@
+/*
+ * 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.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.chain.Chain;
+import org.apache.commons.chain.Command;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
+import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
+import org.apache.portals.applications.webcontent2.proxy.impl.ProxyProcessingChain;
+
+/**
+ * Abstract {@link ProxyProcessingChain} builder class providing basic functionality
+ * to add or remove internal {@link Command}s.
+ * <p>
+ * An inherited implementation can simply implement {@link #initializeCommands(ProxyMappingRegistry, HttpClientBuilder, HttpClientContextBuilder)}
+ * in order to add or remove {@link Command}s before {@link #build(ProxyMappingRegistry, HttpClientBuilder, HttpClientContextBuilder)} gets called.
+ * </p>
+ */
+public abstract class AbstractProxyProcessingChainBuilder implements ProxyProcessingChainBuilder
+{
+
+    /**
+     * The root reverse proxy processing {@link Chain}.
+     */
+    private ProxyProcessingChain chain;
+
+    /**
+     * The internal reverse proxy processing {@link Command}s.
+     */
+    private List<Command> commands;
+
+    /**
+     * Zero-argument default constructor.
+     */
+    public AbstractProxyProcessingChainBuilder()
+    {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ProxyProcessingChain build(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder,
+                                      HttpClientContextBuilder httpClientContextBuilder)
+    {
+        if (chain == null)
+        {
+            chain = new ProxyProcessingChain();
+        }
+
+        initializeCommands(proxyMappingRegistry, httpClientBuilder, httpClientContextBuilder);
+
+        if (commands != null)
+        {
+            for (Command command : commands)
+            {
+                chain.addCommand(command);
+            }
+        }
+
+        return chain;
+    }
+
+    /**
+     * Adds the given <code>command</code> to the internal {@link Command} list
+     * which will be added to the root {@link Chain} on {@link #build(ProxyMappingRegistry, HttpClientBuilder, HttpClientContextBuilder)} call.
+     * @param command
+     */
+    public void addCommand(Command command)
+    {
+        if (commands == null)
+        {
+            commands = new ArrayList<Command>();
+        }
+
+        commands.add(command);
+    }
+
+    /**
+     * Removes the given <code>command</code> instance from the internal {@link Command} list.
+     * @param command
+     */
+    public void removeCommand(Command command)
+    {
+        if (commands != null)
+        {
+            commands.remove(command);
+        }
+    }
+
+    /**
+     * Removes all the commands from the internal {@link Command} list.
+     */
+    public void removeAllCommands()
+    {
+        if (commands != null)
+        {
+            commands.clear();
+        }
+    }
+
+    /**
+     * Initializes all the internal commands to be used by the root {@link Chain} on
+     * {@link #build(ProxyMappingRegistry, HttpClientBuilder, HttpClientContextBuilder)} call.
+     * <p>
+     * An implementation may invoke {@link #addCommand(Command)}, {@link #removeCommand(Command)}
+     * and {@link #removeAllCommands()} during the initialization.
+     * </p>
+     * 
+     * @param proxyMappingRegistry
+     * @param httpClientBuilder
+     * @param httpClientContextBuilder
+     */
+    protected abstract void initializeCommands(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder,
+                                               HttpClientContextBuilder httpClientContextBuilder);
+}

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultProxyProcessingChainBuilder.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultProxyProcessingChainBuilder.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultProxyProcessingChainBuilder.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultProxyProcessingChainBuilder.java Mon Dec 22 23:23:15 2014
@@ -16,6 +16,8 @@
  */
 package org.apache.portals.applications.webcontent2.proxy.builder;
 
+import org.apache.commons.chain.Chain;
+import org.apache.commons.chain.Command;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
 import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
@@ -37,25 +39,53 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.impl.DefaultURICleaner;
 import org.apache.portals.applications.webcontent2.proxy.impl.ProxyProcessingChain;
 
-public class DefaultProxyProcessingChainBuilder extends ProxyProcessingChainBuilder
+/**
+ * Default {@link ProxyProcessingChainBuilder} implementation.
+ */
+public class DefaultProxyProcessingChainBuilder extends AbstractProxyProcessingChainBuilder
 {
 
+    /**
+     * Zero-argument default constructor.
+     */
     public DefaultProxyProcessingChainBuilder()
     {
         super();
     }
 
-    public ProxyProcessingChain build(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder, HttpClientContextBuilder httpClientContextBuilder)
+    /**
+     * {@inheritDoc}
+     * <p>
+     * The implementation adds three {@link Chain} commands for each reverse proxy processing phase.
+     * That is, <em>pre-processing phase</em>, <em>processing phase</em> and <em>post-processing phase</em>.
+     * </p>
+     * <p>
+     * In <em>pre-processing phase</em>, all the initialization related {@link Command}s are added.
+     * In <em>processing phase</em>, core reverse proxy processing {@link Command}s are added.
+     * In <em>post-processing phase</em>, all the resource cleanup related {@link Command}s are added.
+     * </p>
+     * <p>
+     * The {@link Chain} for <em>pre-processing phase</em> is created by {@link #createDefaultPreprocessingCommand(ProxyMappingRegistry, HttpClientBuilder, HttpClientContextBuilder)}.
+     * The {@link Chain} for <em>processing phase</em> is created by {@link #createDefaultProcessingCommand(ProxyMappingRegistry, HttpClientBuilder, HttpClientContextBuilder)}.
+     * Finally the {@link Chain} for <em>post-processing phase</em> is created by {@link #createDefaultPostprocessingCommand(ProxyMappingRegistry, HttpClientBuilder, HttpClientContextBuilder)}.
+     * </p>
+     */
+    @Override
+    protected void initializeCommands(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder,
+                                                HttpClientContextBuilder httpClientContextBuilder)
     {
-        removeAllCommands();
-
         addCommand(createDefaultPreprocessingCommand(proxyMappingRegistry, httpClientBuilder, httpClientContextBuilder));
         addCommand(createDefaultProcessingCommand(proxyMappingRegistry, httpClientBuilder, httpClientContextBuilder));
         addCommand(createDefaultPostprocessingCommand(proxyMappingRegistry, httpClientBuilder, httpClientContextBuilder));
-
-        return super.build(proxyMappingRegistry, httpClientBuilder, httpClientContextBuilder);
     }
 
+    /**
+     * Creates a {@link ProxyProcessingChain} which contains all the {@link Command}s in the pre-processing phase.
+     * @param proxyMappingRegistry
+     * @param httpClientBuilder
+     * @param httpClientContextBuilder
+     * @return
+     */
     protected ProxyProcessingChain createDefaultPreprocessingCommand(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder, HttpClientContextBuilder httpClientContextBuilder)
     {
         ProxyProcessingChain preprocessingChain = new ProxyProcessingChain();
@@ -64,6 +94,13 @@ public class DefaultProxyProcessingChain
         return preprocessingChain;
     }
 
+    /**
+     * Creates a {@link ProxyProcessingChain} which contains all the {@link Command}s in the core processing phase.
+     * @param proxyMappingRegistry
+     * @param httpClientBuilder
+     * @param httpClientContextBuilder
+     * @return
+     */
     protected ProxyProcessingChain createDefaultProcessingCommand(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder, HttpClientContextBuilder httpClientContextBuilder)
     {
         ProxyProcessingChain processingChain = new ProxyProcessingChain();
@@ -108,6 +145,13 @@ public class DefaultProxyProcessingChain
         return processingChain;
     }
 
+    /**
+     * Creates a {@link ProxyProcessingChain} which contains all the {@link Command}s in the post-processing phase.
+     * @param proxyMappingRegistry
+     * @param httpClientBuilder
+     * @param httpClientContextBuilder
+     * @return
+     */
     protected ProxyProcessingChain createDefaultPostprocessingCommand(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder, HttpClientContextBuilder httpClientContextBuilder)
     {
         ProxyProcessingChain postprocessingChain = new ProxyProcessingChain();

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/ProxyProcessingChainBuilder.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/ProxyProcessingChainBuilder.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/ProxyProcessingChainBuilder.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/ProxyProcessingChainBuilder.java Mon Dec 22 23:23:15 2014
@@ -16,66 +16,26 @@
  */
 package org.apache.portals.applications.webcontent2.proxy.builder;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.chain.Command;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
 import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
 import org.apache.portals.applications.webcontent2.proxy.impl.ProxyProcessingChain;
 
-public class ProxyProcessingChainBuilder
+/**
+ * Interface responsible for building {@link ProxyProcessingChain} instances.
+ */
+public interface ProxyProcessingChainBuilder
 {
 
-    private ProxyProcessingChain chain;
-    private List<Command> commands;
-
-    public ProxyProcessingChainBuilder()
-    {
-    }
-
-    public ProxyProcessingChain build(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder, HttpClientContextBuilder httpClientContextBuilder)
-    {
-        if (chain == null)
-        {
-            chain = new ProxyProcessingChain();
-        }
-
-        if (commands != null)
-        {
-            for (Command command : commands)
-            {
-                chain.addCommand(command);
-            }
-        }
-
-        return chain;
-    }
-
-    public void addCommand(Command command)
-    {
-        if (commands == null)
-        {
-            commands = new ArrayList<Command>();
-        }
-
-        commands.add(command);
-    }
-
-    public void removeCommand(Command command)
-    {
-        if (commands != null)
-        {
-            commands.remove(command);
-        }
-    }
+    /**
+     * Builds a {@link ProxyProcessingChain} instance with given <code>proxyMappingRegistry</code>, <code>httpClientBuilder</code> and
+     * <code>httpClientContextBuilder</code>.
+     * 
+     * @param proxyMappingRegistry
+     * @param httpClientBuilder
+     * @param httpClientContextBuilder
+     * @return
+     */
+    public ProxyProcessingChain build(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder, HttpClientContextBuilder httpClientContextBuilder);
 
-    public void removeAllCommands()
-    {
-        if (commands != null)
-        {
-            commands.clear();
-        }
-    }
 }

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/ProxyServices.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/ProxyServices.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/ProxyServices.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/ProxyServices.java Mon Dec 22 23:23:15 2014
@@ -17,6 +17,10 @@
 package org.apache.portals.applications.webcontent2.proxy.builder;
 
 
+
+/**
+ * Factory methods for {@link ProxyProcessingChainBuilder} instances.
+ */
 public class ProxyServices
 {
 
@@ -24,6 +28,11 @@ public class ProxyServices
     {
     }
 
+    /**
+     * Creates {@link ProxyProcessingChainBuilder} instance with default
+     * configuration.
+     * @return
+     */
     public static ProxyProcessingChainBuilder createDefault()
     {
         return new DefaultProxyProcessingChainBuilder();

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommand.java Mon Dec 22 23:23:15 2014
@@ -23,6 +23,8 @@ import java.util.List;
 
 import javax.servlet.http.Cookie;
 
+import org.apache.commons.chain.Command;
+import org.apache.http.HttpResponse;
 import org.apache.http.client.CookieStore;
 import org.apache.http.client.utils.URIUtils;
 import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
@@ -30,9 +32,24 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
 
 
+/**
+ * {@link Command} responsible for copying all the original HTTP response cookies
+ * from the remote content to the internally created {@link HttpResponse} instance.
+ * <p>
+ * For example, if it is serving <code>/webcontent2/rproxy/portals/</code>
+ * (where <code>/webcontent2/rproxy</code> is the concatenation of the servlet context path and the servlet path)
+ * for <code>http://portals.apache.org/</code>
+ * and the remote content sets a cookie with cookie path, <code>/</code>, then this method should translate the cookie path (<code>/</code>)
+ * to <code>/webcontent2/rproxy/portals/</code> in order not to pollute the cookie paths in the single reverse proxy
+ * web application serving multiple remote target web sites.
+ * </p>
+ */
 public class AddCookiesToResponseCommand extends AbstractProxyCommand
 {
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {
@@ -78,6 +95,20 @@ public class AddCookiesToResponseCommand
         return false;
     }
 
+    /**
+     * Returns the translated cookie path in the reverse proxy side for the original response cookie.
+     * <p>
+     * For example, if it is serving <code>/webcontent2/rproxy/portals/</code>
+     * (where <code>/webcontent2/rproxy</code> is the concatenation of the servlet context path and the servlet path)
+     * for <code>http://portals.apache.org/</code>
+     * and the remote content sets a cookie with cookie path, <code>/</code>, then this method should translate the cookie path (<code>/</code>)
+     * to <code>/webcontent2/rproxy/portals/</code> in order not to pollute the cookie paths in the single reverse proxy
+     * web application serving multiple remote target web sites.
+     * </p>
+     * @param context
+     * @param responseCookie
+     * @return
+     */
     protected String getReverseCookiePath(final ProxyContext context, final org.apache.http.cookie.Cookie responseCookie) 
     {
         String cookiePath = responseCookie.getPath();

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeaderToHttpRequestCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeaderToHttpRequestCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeaderToHttpRequestCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeaderToHttpRequestCommand.java Mon Dec 22 23:23:15 2014
@@ -19,6 +19,7 @@ package org.apache.portals.applications.
 import java.io.IOException;
 import java.util.Enumeration;
 
+import org.apache.commons.chain.Command;
 import org.apache.commons.lang.StringUtils;
 import org.apache.http.client.methods.HttpRequestBase;
 import org.apache.http.protocol.HTTP;
@@ -27,9 +28,23 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
 
 
+/**
+ * {@link Command} responsible for copying all the original HTTP request headers
+ * to the internally created {@link HttpRequestBase} instance.
+ * <p>
+ * The following HTTP headers are excluded during the copy:
+ * <ul>
+ * <li><code>Content-Length</code></li>
+ * <li><code>Host</code></li>
+ * </ul>
+ * </p>
+ */
 public class AddHeaderToHttpRequestCommand extends AbstractProxyCommand
 {
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeadersToResponseCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeadersToResponseCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeadersToResponseCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeadersToResponseCommand.java Mon Dec 22 23:23:15 2014
@@ -18,8 +18,10 @@ package org.apache.portals.applications.
 
 import java.io.IOException;
 
+import javax.servlet.ServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.chain.Command;
 import org.apache.commons.lang.StringUtils;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
@@ -30,12 +32,40 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
 import org.apache.portals.applications.webcontent2.proxy.util.RequestUtils;
 
-
+/**
+ * {@link Command} responsible for copying all the original HTTP response headers
+ * except of HTTP Cookie related headers
+ * from the remote content to the internally created {@link HttpResponse} instance.
+ * <p>
+ * <em>Note:</em> All the HTTP Cookie related headers are cared by {@link AddCookiesToResponseCommand}.
+ * </p>
+ * <p>
+ * Also, the following HTTP headers are excluded during the copy:
+ * <ul>
+ * <li><code>Content-Length</code></li>
+ * <li><code>Content-Encoding</code></li>
+ * </ul>
+ * </p>
+ * <p>
+ * Meanwhile, the following HTTP header(s) are rewritten:
+ * <ul>
+ * <li><code>Host</code></li>
+ * </ul>
+ * </p>
+ */
 public class AddHeadersToResponseCommand extends AbstractProxyCommand
 {
 
+    /**
+     * Custom specific "Host" HTTP header value.
+     * If this is null, then it is resolved at runtime
+     * by using {@link ServletRequest#getServerName()} and {@link ServletRequest#getServerPort()}.
+     */
     private String hostHeaderValue;
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {
@@ -81,7 +111,7 @@ public class AddHeadersToResponseCommand
 
                 if (StringUtils.equalsIgnoreCase(headerName, HTTP.TARGET_HOST))
                 {
-                    String host = hostHeaderValue;
+                    String host = getHostHeaderValue();
 
                     if (host == null)
                     {
@@ -107,11 +137,23 @@ public class AddHeadersToResponseCommand
         return false;
     }
 
+    /**
+     * Returns the custom specific "Host" HTTP header value.
+     * If this returns null, then it is resolved at runtime
+     * by using {@link ServletRequest#getServerName()} and {@link ServletRequest#getServerPort()}.
+     * @return
+     */
     public String getHostHeaderValue()
     {
         return hostHeaderValue;
     }
 
+    /**
+     * Sets the custom specific "Host" HTTP header value.
+     * If this is set to a non-null value, then it doesn't try to resolve the "Host" HTTP header value
+     * at runtime, but just returns the custom specific header value instead.
+     * @param hostHeaderValue
+     */
     public void setHostHeaderValue(String hostHeaderValue)
     {
         this.hostHeaderValue = hostHeaderValue;

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/CleanupCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/CleanupCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/CleanupCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/CleanupCommand.java Mon Dec 22 23:23:15 2014
@@ -18,6 +18,7 @@ package org.apache.portals.applications.
 
 import java.io.IOException;
 
+import org.apache.commons.chain.Command;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
@@ -31,12 +32,19 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
-
+/**
+ * {@link Command} responsible for cleaning up all the resources
+ * (such as <code>HttpRequestBase</code>, <code>HttpResponse</code>, <code>HttpEntity</code> and <code>HttpClient</code>)
+ * used during reverse proxy processing in the previous steps.
+ */
 public class CleanupCommand extends AbstractProxyCommand
 {
 
     private static Logger log = LoggerFactory.getLogger(CleanupCommand.class);
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ExecuteHttpClientCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ExecuteHttpClientCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ExecuteHttpClientCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ExecuteHttpClientCommand.java Mon Dec 22 23:23:15 2014
@@ -18,20 +18,38 @@ package org.apache.portals.applications.
 
 import java.io.IOException;
 
+import org.apache.commons.chain.Command;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.protocol.HttpContext;
 import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
 import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
 import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
 
 
+/**
+ * {@link Command} responsible for executing the internal {@link HttpClient}
+ * with the {@link HttpRequestBase} instance.
+ * <p>
+ * If {@link #getHttpClientContextBuilder()} returns a non-null instance, then
+ * this command executes the internal {@link HttpClient}
+ * with the {@link HttpRequestBase} instance and a {@link HttpContext} built by
+ * {@link #getHttpClientContextBuilder()}.
+ * </p>
+ */
 public class ExecuteHttpClientCommand extends AbstractProxyCommand
 {
 
+    /**
+     * Internal {@link HttpClientContextBuilder}.
+     */
     private HttpClientContextBuilder httpClientContextBuilder;
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {
@@ -54,11 +72,19 @@ public class ExecuteHttpClientCommand ex
         return false;
     }
 
+    /**
+     * Returns the internal {@link HttpClientContextBuilder}.
+     * @return
+     */
     public HttpClientContextBuilder getHttpClientContextBuilder()
     {
         return httpClientContextBuilder;
     }
 
+    /**
+     * Sets the internal {@link HttpClientContextBuilder}.
+     * @param httpClientContextBuilder
+     */
     public void setHttpClientContextBuilder(HttpClientContextBuilder httpClientContextBuilder)
     {
         this.httpClientContextBuilder = httpClientContextBuilder;

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleNotModifiedCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleNotModifiedCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleNotModifiedCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleNotModifiedCommand.java Mon Dec 22 23:23:15 2014
@@ -20,6 +20,7 @@ import java.io.IOException;
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.chain.Command;
 import org.apache.http.HttpResponse;
 import org.apache.http.protocol.HTTP;
 import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
@@ -27,9 +28,15 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
 
 
+/**
+ * {@link Command} responsible for handling HTTP 304 error response from the remote target content.
+ */
 public class HandleNotModifiedCommand extends AbstractProxyCommand
 {
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleRedirectionCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleRedirectionCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleRedirectionCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleRedirectionCommand.java Mon Dec 22 23:23:15 2014
@@ -21,6 +21,7 @@ import java.net.URI;
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.chain.Command;
 import org.apache.http.Header;
 import org.apache.http.HttpResponse;
 import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
@@ -31,11 +32,26 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
+/**
+ * {@link Command} responsible for handling HTTP Redirection response from the remote target content.
+ * <p>
+ * This tries to translate the <code>Location</code> HTTP response header value to a local path info
+ * by using the currently resolved {@link ProxyMapping} first.
+ * </p>
+ * <p>
+ * If it cannot resolve the mapped local path info from the currently resolved {@link ProxyMapping},
+ * then it tries to translate the <code>Location</code> HTTP response header value to a local path info
+ * by invoking {@link ProxyMappingRegistry.findProxyMappingByRemoteURI(URI)} afterward.
+ * </p>
+ */
 public class HandleRedirectionCommand extends AbstractProxyCommand
 {
 
     private static Logger log = LoggerFactory.getLogger(HandleRedirectionCommand.class);
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpClientCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpClientCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpClientCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpClientCommand.java Mon Dec 22 23:23:15 2014
@@ -18,6 +18,8 @@ package org.apache.portals.applications.
 
 import java.io.IOException;
 
+import org.apache.commons.chain.Command;
+import org.apache.http.client.HttpClient;
 import org.apache.http.impl.client.BasicCookieStore;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
@@ -26,11 +28,21 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
 
 
+/**
+ * {@link Command} responsible for initializing the {@link HttpClient} instance
+ * which is used to invoke the resolved remote target URI.
+ */
 public class InitHttpClientCommand extends AbstractProxyCommand
 {
 
+    /**
+     * Internal {@link HttpClientBuilder} which is used to build an {@link HttpClient} instance.
+     */
     private HttpClientBuilder httpClientBuilder;
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {
@@ -40,11 +52,19 @@ public class InitHttpClientCommand exten
         return false;
     }
 
+    /**
+     * Returns internal {@link HttpClientBuilder} instance.
+     * @return
+     */
     public HttpClientBuilder getHttpClientBuilder()
     {
         return httpClientBuilder;
     }
 
+    /**
+     * Sets internal {@link HttpClientBuilder} instance.
+     * @param httpClientBuilder
+     */
     public void setHttpClientBuilder(HttpClientBuilder httpClientBuilder)
     {
         this.httpClientBuilder = httpClientBuilder;

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpRequestCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpRequestCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpRequestCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpRequestCommand.java Mon Dec 22 23:23:15 2014
@@ -21,6 +21,7 @@ import java.net.URI;
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.chain.Command;
 import org.apache.commons.lang.math.NumberUtils;
 import org.apache.http.HttpEntity;
 import org.apache.http.client.methods.HttpDelete;
@@ -38,9 +39,17 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
 
 
+/**
+ * {@link Command} responsible for initializing the {@link HttpRequestBase} instance
+ * which is used to invoke the resolved remote target URI,
+ * based on the original request method name and the resolved remote target URI.
+ */
 public class InitHttpRequestCommand extends AbstractProxyCommand
 {
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {
@@ -49,6 +58,14 @@ public class InitHttpRequestCommand exte
         return false;
     }
 
+    /**
+     * Creates an {@link HttpRequestBase} instance
+     * which is used to invoke the resolved remote target URI.
+     * @param context
+     * @return
+     * @throws ReverseProxyException
+     * @throws IOException
+     */
     protected HttpRequestBase createHttpRequest(final ProxyContext context) throws ReverseProxyException, IOException
     {
         HttpRequestBase httpRequest = null;

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitializationCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitializationCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitializationCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitializationCommand.java Mon Dec 22 23:23:15 2014
@@ -18,6 +18,7 @@ package org.apache.portals.applications.
 
 import java.io.IOException;
 
+import org.apache.commons.chain.Command;
 import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
 import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
@@ -25,12 +26,17 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
-
+/**
+ * {@link Command} responsible for initializing anything necessary for reverse proxy request processing.
+ */
 public class InitializationCommand extends AbstractProxyCommand
 {
 
     private static Logger log = LoggerFactory.getLogger(InitializationCommand.class);
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveContentRewriterCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveContentRewriterCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveContentRewriterCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveContentRewriterCommand.java Mon Dec 22 23:23:15 2014
@@ -18,6 +18,7 @@ package org.apache.portals.applications.
 
 import java.io.IOException;
 
+import org.apache.commons.chain.Command;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.entity.ContentType;
@@ -27,9 +28,16 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
 import org.apache.portals.applications.webcontent2.rewriter.ContentRewriter;
 
+/**
+ * {@link Command} responsible for resolving the content rewriter
+ * from the resolved {@link ProxyMaping} and the content type of the remote content.
+ */
 public class ResolveContentRewriterCommand extends AbstractProxyCommand
 {
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveLocalPathCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveLocalPathCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveLocalPathCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveLocalPathCommand.java Mon Dec 22 23:23:15 2014
@@ -18,15 +18,22 @@ package org.apache.portals.applications.
 
 import java.io.IOException;
 
+import org.apache.commons.chain.Command;
 import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
 import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
 
 
 
+/**
+ * {@link Command} responsible for resolving the local request path info.
+ */
 public class ResolveLocalPathCommand extends AbstractProxyCommand
 {
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveProxyMappingCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveProxyMappingCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveProxyMappingCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveProxyMappingCommand.java Mon Dec 22 23:23:15 2014
@@ -20,22 +20,37 @@ import java.io.IOException;
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.chain.Command;
 import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
 import org.apache.portals.applications.webcontent2.proxy.ProxyMapping;
 import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
 import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
 
+/**
+ * {@link Command} responsible for resolving a {@link ProxyMapping} from the local request path info.
+ */
 public class ResolveProxyMappingCommand extends AbstractProxyCommand
 {
 
+    /**
+     * Internal {@link ProxyMappingRegistry} which is used to resolve a local request path info
+     * to a {@link ProxyMapping}.
+     */
     private final ProxyMappingRegistry proxyMappingRegistry;
 
+    /**
+     * Constructs ResolveProxyMappingCommand with the given <code>proxyMappingRegistry</code>.
+     * @param proxyMappingRegistry
+     */
     public ResolveProxyMappingCommand(final ProxyMappingRegistry proxyMappingRegistry)
     {
         this.proxyMappingRegistry = proxyMappingRegistry;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveRemoteURICommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveRemoteURICommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveRemoteURICommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ResolveRemoteURICommand.java Mon Dec 22 23:23:15 2014
@@ -21,7 +21,9 @@ import java.net.URI;
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.chain.Command;
 import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
+import org.apache.portals.applications.webcontent2.proxy.ProxyMapping;
 import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
 import org.apache.portals.applications.webcontent2.proxy.URICleaner;
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
@@ -29,13 +31,24 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
+/**
+ * {@link Command} responsible for resolving the remote target URI
+ * from the local request path info and the resolved {@link ProxyMapping}.
+ */
 public class ResolveRemoteURICommand extends AbstractProxyCommand
 {
 
     private static Logger log = LoggerFactory.getLogger(ResolveRemoteURICommand.class);
 
+    /**
+     * Internal {@link URICleaner} which is used to verify
+     * the resolved remote target URI and clean it up if necessary.
+     */
     private URICleaner uriCleaner;
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {
@@ -78,11 +91,19 @@ public class ResolveRemoteURICommand ext
         return false;
     }
 
+    /**
+     * Returns the internal {@link URICleaner}.
+     * @return
+     */
     public URICleaner getUriCleaner()
     {
         return uriCleaner;
     }
 
+    /**
+     * Sets the internal {@link URICleaner}.
+     * @param uriCleaner
+     */
     public void setUriCleaner(URICleaner uriCleaner)
     {
         this.uriCleaner = uriCleaner;

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/SerializeHttpEntityContentCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/SerializeHttpEntityContentCommand.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/SerializeHttpEntityContentCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/SerializeHttpEntityContentCommand.java Mon Dec 22 23:23:15 2014
@@ -25,6 +25,7 @@ import java.io.Writer;
 import java.nio.charset.Charset;
 import java.util.zip.GZIPInputStream;
 
+import org.apache.commons.chain.Command;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.http.Header;
@@ -45,12 +46,21 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.rewriter.Source;
 import org.apache.portals.applications.webcontent2.rewriter.impl.SimpleContentRewritingContext;
 
-
+/**
+ * {@link Command} responsible for serializing the response body from the remote content
+ * to the response in the reverse proxy side.
+ */
 public class SerializeHttpEntityContentCommand extends AbstractProxyCommand
 {
 
+    /**
+     * Default character encoding to be used when serializing content to response.
+     */
     private String defaultCharacterEncoding = "UTF-8";
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {
@@ -72,16 +82,36 @@ public class SerializeHttpEntityContentC
         return false;
     }
 
+    /**
+     * Returns the default character encoding to be used when serializing content to response.
+     * @return
+     */
     public String getDefaultCharacterEncoding()
     {
         return defaultCharacterEncoding;
     }
 
+    /**
+     * Sets the default character encoding to be used when serializing content to response.
+     * @param defaultCharacterEncoding
+     */
     public void setDefaultCharacterEncoding(String defaultCharacterEncoding)
     {
         this.defaultCharacterEncoding = defaultCharacterEncoding;
     }
 
+    /**
+     * Write the {@link HttpEntity} of {@link HttpResponse} from the remote content
+     * to the non-dispatched response in the reverse proxy side.
+     * <p>
+     * If a {@link ContentRewriter} was resolved in the previous step, then
+     * it used the {@link ContentRewriter} to rewriter the response content.
+     * </p>
+     * @param context
+     * @param httpEntity
+     * @throws ReverseProxyException
+     * @throws IOException
+     */
     protected void writeHttpEntityToResponse(final ProxyContext context, final HttpEntity httpEntity) throws ReverseProxyException, IOException
     {
         Source source = new HttpEntitySource(httpEntity);
@@ -140,6 +170,18 @@ public class SerializeHttpEntityContentC
         }
     }
 
+    /**
+     * Write the {@link HttpEntity} of {@link HttpResponse} from the remote content
+     * to the dispatched response in the reverse proxy side.
+     * <p>
+     * If a {@link ContentRewriter} was resolved in the previous step, then
+     * it used the {@link ContentRewriter} to rewriter the response content.
+     * </p>
+     * @param context
+     * @param httpEntity
+     * @throws ReverseProxyException
+     * @throws IOException
+     */
     protected void writeHttpEntityToDispatcher(final ProxyContext context, final HttpEntity httpEntity) throws ReverseProxyException, IOException
     {
         Source source = new HttpEntitySource(httpEntity);
@@ -226,6 +268,11 @@ public class SerializeHttpEntityContentC
         }
     }
 
+    /**
+     * Creates a new {@link ContentRewritingContext} which is to be used by the resolved {@link ContentRewriter}.
+     * @param proxyContext
+     * @return
+     */
     protected ContentRewritingContext createContentRewritingContext(final ProxyContext proxyContext)
     {
         SimpleContentRewritingContext contentRewritingContext = new SimpleContentRewritingContext();
@@ -237,6 +284,12 @@ public class SerializeHttpEntityContentC
         return contentRewritingContext;
     }
 
+    /**
+     * Returns true if the <code>Content-Encoding</code> HTTP response header from the remote content is "gzip".
+     * Otherwise, it returns false.
+     * @param httpEntity
+     * @return
+     */
     private boolean isGzipEncodedContent(final HttpEntity httpEntity) 
     {
         boolean gzipEncoded = false;

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/GenericReverseProxyFilter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/GenericReverseProxyFilter.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/GenericReverseProxyFilter.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/GenericReverseProxyFilter.java Mon Dec 22 23:23:15 2014
@@ -24,6 +24,7 @@ import java.util.Set;
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
+import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
@@ -46,40 +47,86 @@ import org.apache.portals.applications.w
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Generic reverse proxy servlet filter invoking {@link ReverseProxyService} injected.
+ * <p>
+ * Unlike servlets, servlet filters cannot know the filter mapping path prefix by itself.
+ * So, this filter should be configured with <code>filterPath</code> init parameters
+ * in order to get the link rewriting and redirection done properly with the prefix.
+ * For example, if this filter is mapped to '/rproxyfilter/*', then you should add an init parameter
+ * like the following:
+ * <xmp>
+ *   <init-param>
+ *     <param-name>filterPath</param-name>
+ *     <param-value>/rproxyfilter</param-value>
+ *   </init-param>
+ * </xmp>
+ * </p>
+ */
 public class GenericReverseProxyFilter implements Filter
 {
 
-    private static final Set<String> AVAILABLE_HTTP_METHOD_SET = 
-                    new HashSet<String>(Arrays.asList(HttpGet.METHOD_NAME, 
-                                                      HttpHead.METHOD_NAME, 
-                                                      HttpPost.METHOD_NAME, 
-                                                      HttpPut.METHOD_NAME, 
-                                                      HttpDelete.METHOD_NAME,
-                                                      HttpOptions.METHOD_NAME,
-                                                      HttpTrace.METHOD_NAME));
+    /**
+     * Default allowed HTTP methods.
+     */
+    private static final Set<String> DEFAULT_ALLOWED_HTTP_METHODS = 
+        new HashSet<String>(Arrays.asList(HttpGet.METHOD_NAME, 
+                                          HttpHead.METHOD_NAME, 
+                                          HttpPost.METHOD_NAME, 
+                                          HttpPut.METHOD_NAME, 
+                                          HttpDelete.METHOD_NAME,
+                                          HttpOptions.METHOD_NAME,
+                                          HttpTrace.METHOD_NAME));
 
     private static Logger log = LoggerFactory.getLogger(GenericReverseProxyFilter.class);
 
+    /**
+     * The {@link ServletConfig} instance for this filter.
+     */
     private FilterConfig filterConfig;
 
+    /**
+     * Internal {@link ReverseProxyService} to invoke while processing reverse proxy requests.
+     */
     private ReverseProxyService proxyService;
 
+    /**
+     * The filter mapping path prefix.
+     * <p>
+     * For example, if this filter is mapped to '/rproxyfilter/*',
+     * then this property should be "/rproxyfilter".
+     * </p>
+     */
     private String filterPath;
 
+    /**
+     * Zero-argument default constructor.
+     */
     public GenericReverseProxyFilter()
     {
     }
 
+    /**
+     * Returns the internal {@link ReverseProxyService} instance.
+     * @return
+     */
     public ReverseProxyService getProxyService()
     {
         return proxyService;
     }
 
+    /**
+     * Sets the internal {@link ReverseProxyService} instance.
+     * @param proxyService
+     */
     public void setProxyService(ReverseProxyService proxyService)
     {
         this.proxyService = proxyService;
     }
 
+    /**
+     * Initializes this servlet filter.
+     */
     public void init(FilterConfig filterConfig) throws ServletException
     {
         this.filterConfig = filterConfig;
@@ -87,6 +134,9 @@ public class GenericReverseProxyFilter i
         filterPath = StringUtils.trim(filterConfig.getInitParameter("filterPath"));
     }
 
+    /**
+     * Invokes the internal {@link ReverseProxyService} on allowed HTTP requests.
+     */
     public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException
     {
         if (!(req instanceof HttpServletRequest) || !(res instanceof HttpServletResponse))
@@ -98,7 +148,7 @@ public class GenericReverseProxyFilter i
         HttpServletRequest request = (HttpServletRequest) req;
         HttpServletResponse response = (HttpServletResponse) res;
 
-        if (!AVAILABLE_HTTP_METHOD_SET.contains(request.getMethod()))
+        if (!DEFAULT_ALLOWED_HTTP_METHODS.contains(request.getMethod()))
         {
             chain.doFilter(request, response);
         }
@@ -156,20 +206,38 @@ public class GenericReverseProxyFilter i
         }
     }
 
+    /**
+     * Destroys this servlet filter.
+     */
     public void destroy()
     {
     }
 
+    /**
+     * Returns the {@link FilterConfig} of this servlet filter.
+     * @return
+     */
     protected FilterConfig getFilterConfig()
     {
         return filterConfig;
     }
 
+    /**
+     * Returns the servlet filter mapping path prefix.
+     * For example, if the servlet filter is mapped to '/rproxyfilter/*', then
+     * this method is supposed to return '/rproxyfilter'.
+     * @return
+     */
     protected String getFilterPath()
     {
         return filterPath;
     }
 
+    /**
+     * Returns the concatenation of the servlet context path 
+     * (see {@link javax.servlet.ServletContext#getContext(String)}
+     * and the filterPath (see {@link #getFilterPath()}).
+     */
     protected String getRequestBasePath(HttpServletRequest request)
     {
         StringBuilder sb = new StringBuilder();

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/SimpleReverseProxyFilter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/SimpleReverseProxyFilter.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/SimpleReverseProxyFilter.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/SimpleReverseProxyFilter.java Mon Dec 22 23:23:15 2014
@@ -17,8 +17,10 @@
 package org.apache.portals.applications.webcontent2.proxy.filter;
 
 import javax.servlet.FilterConfig;
+import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 
+import org.apache.commons.chain.Command;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
@@ -30,6 +32,10 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.util.ProxyCommandUtils;
 import org.apache.portals.applications.webcontent2.proxy.util.YamlConfigUtils;
 
+/**
+ * Simple reverse proxy servlet filter implementation as an example and
+ * a base class to be overriden.
+ */
 public class SimpleReverseProxyFilter extends GenericReverseProxyFilter
 {
 
@@ -40,11 +46,18 @@ public class SimpleReverseProxyFilter ex
     private HttpClientContextBuilder httpClientContextBuilder;
     private ProxyProcessingChain proxyServiceCommand;
 
+    /**
+     * Zero-argument default constructor.
+     */
     public SimpleReverseProxyFilter()
     {
         super();
     }
 
+    /**
+     * Creates the root reverse proxy processing chain instance,
+     * and initializes all the {@link Command}s inside the chain.
+     */
     @Override
     public void init(FilterConfig filterConfig) throws ServletException
     {
@@ -57,6 +70,10 @@ public class SimpleReverseProxyFilter ex
         setProxyService(proxyService);
     }
 
+    /**
+     * Returns the internal {@link ProxyMappingRegistry} instance.
+     * @return
+     */
     public ProxyMappingRegistry getProxyMappingRegistry()
     {
         if (proxyMappingRegistry == null)
@@ -70,11 +87,19 @@ public class SimpleReverseProxyFilter ex
         return proxyMappingRegistry;
     }
 
+    /**
+     * Sets the internal {@link ProxyMappingRegistry} instance.
+     * @param proxyMappingRegistry
+     */
     public void setProxyMappingRegistry(ProxyMappingRegistry proxyMappingRegistry)
     {
         this.proxyMappingRegistry = proxyMappingRegistry;
     }
 
+    /**
+     * Returns the internal {@link HttpClientBuilder} instance.
+     * @return
+     */
     public HttpClientBuilder getHttpClientBuilder()
     {
         if (httpClientBuilder == null)
@@ -85,21 +110,36 @@ public class SimpleReverseProxyFilter ex
         return httpClientBuilder;
     }
 
+    /**
+     * Sets the internal {@link HttpClientBuilder} instance.
+     * @param httpClientBuilder
+     */
     public void setHttpClientBuilder(HttpClientBuilder httpClientBuilder)
     {
         this.httpClientBuilder = httpClientBuilder;
     }
 
+    /**
+     * Returns the internal {@link HttpClientContextBuilder} instance.
+     * @return
+     */
     public HttpClientContextBuilder getHttpClientContextBuilder()
     {
         return httpClientContextBuilder;
     }
 
+    /**
+     * Sets the internal {@link HttpClientContextBuilder} instance.
+     * @param httpClientContextBuilder
+     */
     public void setHttpClientContextBuilder(HttpClientContextBuilder httpClientContextBuilder)
     {
         this.httpClientContextBuilder = httpClientContextBuilder;
     }
 
+    /**
+     * Disposes all the {@link Command}s in the root reverse proxy processing chain.
+     */
     @Override
     public void destroy()
     {
@@ -107,6 +147,11 @@ public class SimpleReverseProxyFilter ex
         super.destroy();
     }
 
+    /**
+     * {@link #init(ServletConfig)} method invokes this method to
+     * create the root reverse proxy processing chain ({@link ProxyProcessingChain}).
+     * @return
+     */
     protected ProxyProcessingChain createProxyServiceCommand() {
         return ProxyServices.createDefault().build(getProxyMappingRegistry(), getHttpClientBuilder(), getHttpClientContextBuilder());
     }

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java Mon Dec 22 23:23:15 2014
@@ -34,19 +34,48 @@ import org.apache.portals.applications.w
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Default text line based content rewriter implementation with basic link rewriting features.
+ * <p>
+ * This implementation uses a regular expression (see {@link #LINK_PATTERN}) to find
+ * all the DOM elements containing any of <code>href</code>, <code>src</code> and <code>action</code>
+ * attributes and rewrite those URI attribute values by a resolved {@link ProxyMapping} from the
+ * internal {@link ProxyMappingRegistry} in the current reverse proxy processing context.
+ * </p>
+ */
 public class DefaultReverseProxyTextLineContentRewriter extends AbstractTextLineContentRewriter
 {
 
     private static Logger log = LoggerFactory.getLogger(DefaultReverseProxyTextLineContentRewriter.class);
 
+    /**
+     * The regular expression pattern to find and replace URI attribute values in DOM elements.
+     */
     protected static final Pattern LINK_PATTERN = 
                     Pattern.compile("(\\s|^)(href\\s*=\\s*|src\\s*=\\s*|action\\s*=\\s*|url\\s*\\(\\s*)((\"([^\"]*)\")|('([^']*)'))", Pattern.CASE_INSENSITIVE);
 
-
+    /**
+     * External URL resources which are not generated from the repository resources.
+     */
+    private static final String[] DEFAULT_NONREWRITABLE_URL_PREFIX = { "#", "javascript:", "mailto:", "data:", "webdav:", "ftp:", "callto:", "tel:", "sms:" };
+
+    /**
+     * Zero-argument default constructor.
+     */
     public DefaultReverseProxyTextLineContentRewriter()
     {
     }
 
+    /**
+     * {@inheritDoc}
+     * <p>
+     * This implementation uses a regular expression (see {@link #LINK_PATTERN}) to find
+     * all the DOM elements containing any of <code>href</code>, <code>src</code> and <code>action</code>
+     * attributes and rewrite those URI attribute values (see {@link #rewriteURI(String, ContentRewritingContext)})
+     * by a resolved {@link ProxyMapping} from the internal {@link ProxyMappingRegistry}
+     * in the current reverse proxy processing context.
+     * </p>
+     */
     @Override
     protected String rewriteLine(String line, ContentRewritingContext context) throws ContentRewritingException, IOException
     {
@@ -92,6 +121,13 @@ public class DefaultReverseProxyTextLine
         }
     }
 
+    /**
+     * Rewrites the given <code>uri</code> by resolving a {@link ProxyMapping} from the internal
+     * {@link ProxyMappingRegistry} in the current {@link ContentRewritingContext} and {@link ProxyContext}.
+     * @param uri
+     * @param context
+     * @return
+     */
     protected String rewriteURI(String uri, ContentRewritingContext context)
     {
         if (StringUtils.isBlank(uri))
@@ -172,19 +208,26 @@ public class DefaultReverseProxyTextLine
         return uri;
     }
 
+    /**
+     * Returns true if the given <code>uri</code> can be rewritten by this. Otherwise it returns false.
+     * @param uri
+     * @return
+     */
     protected boolean isRewritableURI(String uri)
     {
-        // mailto: URIs often contain invalid characters in web pages to avoid spams
-        // and #, javascript: and data: URIs do not need to be parsed at all.
-        // These should be avoided in URI rewriting.
-        if (StringUtils.startsWith(uri, "#") 
-                        || StringUtils.startsWith(uri, "javascript:")
-                        || StringUtils.startsWith(uri, "mailto:")
-                        || StringUtils.startsWith(uri, "data:"))
+        if (StringUtils.isBlank(uri))
         {
             return false;
         }
 
+        for (String prefix : DEFAULT_NONREWRITABLE_URL_PREFIX)
+        {
+            if (uri.startsWith(prefix))
+            {
+                return false;
+            }
+        }
+
         return true;
     }
 }

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/GenericReverseProxyServlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/GenericReverseProxyServlet.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/GenericReverseProxyServlet.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/GenericReverseProxyServlet.java Mon Dec 22 23:23:15 2014
@@ -48,7 +48,10 @@ public class GenericReverseProxyServlet
 
     private static final long serialVersionUID = 1L;
 
-    private static final Set<String> AVAILABLE_HTTP_METHOD_SET = 
+    /**
+     * Default allowed HTTP methods.
+     */
+    private static final Set<String> DEFAULT_ALLOWED_HTTP_METHODS = 
         new HashSet<String>(Arrays.asList(HttpGet.METHOD_NAME, 
                                           HttpHead.METHOD_NAME, 
                                           HttpPost.METHOD_NAME, 
@@ -59,22 +62,39 @@ public class GenericReverseProxyServlet
 
     private static Logger log = LoggerFactory.getLogger(GenericReverseProxyServlet.class);
 
+    /**
+     * Internal {@link ReverseProxyService} to invoke while processing reverse proxy requests.
+     */
     private ReverseProxyService proxyService;
 
+    /**
+     * Zero-constructor default constructor.
+     */
     public GenericReverseProxyServlet()
     {
     }
 
+    /**
+     * Returns the internal {@link ReverseProxyService} instance.
+     * @return
+     */
     public ReverseProxyService getProxyService()
     {
         return proxyService;
     }
 
+    /**
+     * Sets the internal {@link ReverseProxyService} instance.
+     * @param proxyService
+     */
     public void setProxyService(ReverseProxyService proxyService)
     {
         this.proxyService = proxyService;
     }
 
+    /**
+     * Invokes the internal {@link ReverseProxyService} on allowed HTTP requests.
+     */
     @Override
     protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
     {
@@ -126,8 +146,14 @@ public class GenericReverseProxyServlet
         }
     }
 
+    /**
+     * Returns true if the HTTP method used by <code>request</code> is allowed by this.
+     * Otherwise returns false.
+     * @param request
+     * @return
+     */
     protected boolean isAllowedHttpMethod(HttpServletRequest request)
     {
-        return AVAILABLE_HTTP_METHOD_SET.contains(request.getMethod());
+        return DEFAULT_ALLOWED_HTTP_METHODS.contains(request.getMethod());
     }
 }

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=1647444&r1=1647443&r2=1647444&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 Mon Dec 22 23:23:15 2014
@@ -19,6 +19,7 @@ package org.apache.portals.applications.
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 
+import org.apache.commons.chain.Command;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
@@ -31,25 +32,50 @@ import org.apache.portals.applications.w
 import org.apache.portals.applications.webcontent2.proxy.util.YamlConfigUtils;
 
 /**
- * Simple reverse proxy servlet implementation as an example.
+ * Simple reverse proxy servlet implementation as an example and a base class to be overriden.
  */
 public class SimpleReverseProxyServlet extends GenericReverseProxyServlet
 {
 
     private static final long serialVersionUID = 1L;
 
+    /**
+     * Reverse proxy mapping initialization parameter name.
+     */
     public static final String MAPPINGS_PARAM_NAME = "mappings";
 
+    /**
+     * Internal reverse proxy mapping registry.
+     */
     private ProxyMappingRegistry proxyMappingRegistry;
+
+    /**
+     * Internal {@link HttpClientBuilder} instance.
+     */
     private HttpClientBuilder httpClientBuilder;
+
+    /**
+     * Internal {@link HttpClientContextBuilder} instance.
+     */
     private HttpClientContextBuilder httpClientContextBuilder;
+
+    /**
+     * Internal root reverse proxy processing chain instance.
+     */
     private ProxyProcessingChain proxyServiceCommand;
 
+    /**
+     * Zero-argument default constructor.
+     */
     public SimpleReverseProxyServlet()
     {
         super();
     }
 
+    /**
+     * Creates the root reverse proxy processing chain instance,
+     * and initializes all the {@link Command}s inside the chain.
+     */
     @Override
     public void init(ServletConfig servletConfig) throws ServletException
     {
@@ -62,6 +88,10 @@ public class SimpleReverseProxyServlet e
         setProxyService(proxyService);
     }
 
+    /**
+     * Returns the internal {@link ProxyMappingRegistry} instance.
+     * @return
+     */
     public ProxyMappingRegistry getProxyMappingRegistry()
     {
         if (proxyMappingRegistry == null)
@@ -75,11 +105,19 @@ public class SimpleReverseProxyServlet e
         return proxyMappingRegistry;
     }
 
+    /**
+     * Sets the internal {@link ProxyMappingRegistry} instance.
+     * @param proxyMappingRegistry
+     */
     public void setProxyMappingRegistry(ProxyMappingRegistry proxyMappingRegistry)
     {
         this.proxyMappingRegistry = proxyMappingRegistry;
     }
 
+    /**
+     * Returns the internal {@link HttpClientBuilder} instance.
+     * @return
+     */
     public HttpClientBuilder getHttpClientBuilder()
     {
         if (httpClientBuilder == null)
@@ -90,21 +128,36 @@ public class SimpleReverseProxyServlet e
         return httpClientBuilder;
     }
 
+    /**
+     * Sets the internal {@link HttpClientBuilder} instance.
+     * @param httpClientBuilder
+     */
     public void setHttpClientBuilder(HttpClientBuilder httpClientBuilder)
     {
         this.httpClientBuilder = httpClientBuilder;
     }
 
+    /**
+     * Returns the internal {@link HttpClientContextBuilder} instance.
+     * @return
+     */
     public HttpClientContextBuilder getHttpClientContextBuilder()
     {
         return httpClientContextBuilder;
     }
 
+    /**
+     * Sets the internal {@link HttpClientContextBuilder} instance.
+     * @param httpClientContextBuilder
+     */
     public void setHttpClientContextBuilder(HttpClientContextBuilder httpClientContextBuilder)
     {
         this.httpClientContextBuilder = httpClientContextBuilder;
     }
 
+    /**
+     * Disposes all the {@link Command}s in the root reverse proxy processing chain.
+     */
     @Override
     public void destroy()
     {
@@ -112,6 +165,11 @@ public class SimpleReverseProxyServlet e
         super.destroy();
     }
 
+    /**
+     * {@link #init(ServletConfig)} method invokes this method to
+     * create the root reverse proxy processing chain ({@link ProxyProcessingChain}).
+     * @return
+     */
     protected ProxyProcessingChain createProxyServiceCommand() {
         return ProxyServices.createDefault().build(getProxyMappingRegistry(), getHttpClientBuilder(), getHttpClientContextBuilder());
     }

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/CharArraySegment.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/CharArraySegment.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/CharArraySegment.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/CharArraySegment.java Mon Dec 22 23:23:15 2014
@@ -19,7 +19,7 @@ package org.apache.portals.applications.
 import javax.swing.text.Segment;
 
 /**
- * CharArraySegment
+ * CharArraySegment.
  * <P>
  * Implements {@link CharSequence} interface by leveraging {@link Segment} class.
  * </P>
@@ -32,16 +32,29 @@ import javax.swing.text.Segment;
 public class CharArraySegment extends Segment implements CharSequence
 {
 
+    /**
+     * Zero-argument default constructor.
+     */
     public CharArraySegment()
     {
         super();
     }
 
+    /**
+     * Constructs a {@link Segment} from the <code>array</code> by selecting a range.
+     * @param array
+     * @param offset
+     * @param count
+     */
     public CharArraySegment(char[] array, int offset, int count)
     {
         super(array, offset, count);
     }
 
+    /**
+     * Constructs a {@link Segment} from the given string.
+     * @param s
+     */
     public CharArraySegment(String s)
     {
         super(s.toCharArray(), 0, s.length());
@@ -57,11 +70,19 @@ public class CharArraySegment extends Se
         return array[offset + index];
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public int length()
     {
         return count;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public CharSequence subSequence(int start, int end)
     {
         if (start < 0)

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/ProxyCommandUtils.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/ProxyCommandUtils.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/ProxyCommandUtils.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/ProxyCommandUtils.java Mon Dec 22 23:23:15 2014
@@ -23,6 +23,10 @@ import org.apache.portals.applications.w
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Utility to invoke the life cycle methods easily on each {@link AbstractProxyCommand}
+ * in a {@link ProxyProcessingChain}.
+ */
 public class ProxyCommandUtils
 {
 
@@ -32,6 +36,10 @@ public class ProxyCommandUtils
     {
     }
 
+    /**
+     * Invokes {@link AbstractProxyCommand#initialize()} on each item in the <code>chain</code>.
+     * @param chain
+     */
     public static void initializeAllCommands(ProxyProcessingChain chain)
     {
         if (chain == null)
@@ -47,6 +55,10 @@ public class ProxyCommandUtils
         }
     }
 
+    /**
+     * Invokes {@link AbstractProxyCommand#destroy()} on each item in the <code>chain</code>.
+     * @param chain
+     */
     public static void destroyAllCommands(ProxyProcessingChain chain)
     {
         if (chain == null)

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/RequestUtils.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/RequestUtils.java?rev=1647444&r1=1647443&r2=1647444&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/RequestUtils.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/RequestUtils.java Mon Dec 22 23:23:15 2014
@@ -20,6 +20,15 @@ import javax.servlet.http.HttpServletReq
 
 import org.apache.portals.applications.webcontent2.proxy.RequestContext;
 
+/**
+ * Utility to read the context path, request URI, servlet path, path info, etc.
+ * from an {@link javax.servlet.http.HttpServletRequest}.
+ * This utility does care both situations: whether or not the current request was dispatched.
+ * So, with this utility, you don't have to read servlet request attributes manually.
+ * <p>
+ * <em>Note:</em> Please see the Java Servlet Specification for the detail on the related request attributes.
+ * </p>
+ */
 public class RequestUtils
 {
 
@@ -27,6 +36,17 @@ public class RequestUtils
     {
     }
 
+    /**
+     * Finds and returns the servlet context path in the following order.
+     * <ol>
+     * <li>returns <code>javax.servlet.include.context_path</code> request attribute if found.</li>
+     * <li>returns <code>javax.servlet.forward.context_path</code> request attribute if found.</li>
+     * <li>returns {@link javax.servlet.http.HttpServletRequest#getContextPath().</li>
+     * </ol>
+     * 
+     * @param request
+     * @return
+     */
     public static String getContextPath(HttpServletRequest request)
     {
         String contextPath = (String) request.getAttribute("javax.servlet.include.context_path");
@@ -44,6 +64,16 @@ public class RequestUtils
         return request.getContextPath();
     }
 
+    /**
+     * Finds and returns the request URI in the following order.
+     * <ol>
+     * <li>returns <code>javax.servlet.include.request_uri</code> request attribute if found.</li>
+     * <li>returns <code>javax.servlet.forward.request_uri</code> request attribute if found.</li>
+     * <li>returns {@link javax.servlet.http.HttpServletRequest#getRequestURI().</li>
+     * </ol>
+     * @param request
+     * @return
+     */
     public static String getRequestURI(HttpServletRequest request)
     {
         String requestURI = (String) request.getAttribute("javax.servlet.include.request_uri");
@@ -61,6 +91,16 @@ public class RequestUtils
         return request.getRequestURI();
     }
 
+    /**
+     * Finds and returns the request URI in the following order.
+     * <ol>
+     * <li>returns <code>javax.servlet.include.servlet_path</code> request attribute if found.</li>
+     * <li>returns <code>javax.servlet.forward.servlet_path</code> request attribute if found.</li>
+     * <li>returns {@link javax.servlet.http.HttpServletRequest#getServletPath().</li>
+     * </ol>
+     * @param request
+     * @return
+     */
     public static String getServletPath(HttpServletRequest request)
     {
         String servletPath = (String) request.getAttribute("javax.servlet.include.servlet_path");
@@ -78,6 +118,16 @@ public class RequestUtils
         return request.getServletPath();
     }
 
+    /**
+     * Finds and returns the request URI in the following order.
+     * <ol>
+     * <li>returns <code>javax.servlet.include.path_info</code> request attribute if found.</li>
+     * <li>returns <code>javax.servlet.forward.path_info</code> request attribute if found.</li>
+     * <li>returns {@link javax.servlet.http.HttpServletRequest#getPathInfo().</li>
+     * </ol>
+     * @param request
+     * @return
+     */
     public static String getPathInfo(HttpServletRequest request)
     {
         String pathInfo = (String) request.getAttribute("javax.servlet.include.path_info");
@@ -95,6 +145,14 @@ public class RequestUtils
         return request.getPathInfo();
     }
 
+    /**
+     * Returns true if the current request was dispatched by either
+     * {@link javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)}
+     * or {@link javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)}.
+     * Otherwise, it should return false.
+     * @param requestContext
+     * @return
+     */
     public static boolean isDispatched(RequestContext requestContext)
     {
         return (requestContext.getAttribute("javax.servlet.include.context_path") != null 



Mime
View raw message