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/08/24 07:28:34 UTC

svn commit: r1620110 [1/2] - in /portals/applications/webcontent/trunk: content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/ content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/ portl...

Author: woonsan
Date: Sun Aug 24 05:28:33 2014
New Revision: 1620110

URL: http://svn.apache.org/r1620110
Log:
APA-60: Adding default reverse proxy content rewriter.

Added:
    portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/StreamSink.java
    portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/StreamSource.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/
    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/util/CharArraySegment.java
    portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/ProxyCommandChainTest.java
      - copied, changed from r1620099, portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/CommonsChainTest.java
    portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/rewriter/
    portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriterTest.java
    portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/org/
    portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/org/apache/
    portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/org/apache/portals/
    portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/org/apache/portals/applications/
    portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/org/apache/portals/applications/webcontent2/
    portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/org/apache/portals/applications/webcontent2/proxy/
    portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/org/apache/portals/applications/webcontent2/proxy/rewriter/
    portals/applications/webcontent/trunk/reverse-proxy/src/test/resources/org/apache/portals/applications/webcontent2/proxy/rewriter/content-rewriter-test1.html
    portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/ReverseProxyServlet-mappings.yaml
Removed:
    portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/CommonsChainTest.java
Modified:
    portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/AbstractTextLineContentRewriter.java
    portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/TextLineContentRewriterTest.java
    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/ProxyMapping.java
    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/command/AddCookiesToResponseCommand.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/InitHttpRequestCommand.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/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/impl/AbstractProxyCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/AbstractProxyMapping.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/ProxyContext.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/RegexProxyMapping.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ServletRequestContext.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
    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/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommandTest.java
    portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/impl/RegexProxyMappingTest.java
    portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtilsTest.java
    portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/web.xml
    portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/index.jsp

Modified: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/AbstractTextLineContentRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/AbstractTextLineContentRewriter.java?rev=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/AbstractTextLineContentRewriter.java (original)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/AbstractTextLineContentRewriter.java Sun Aug 24 05:28:33 2014
@@ -53,7 +53,7 @@ public abstract class AbstractTextLineCo
 
             for (LineIterator lineIt = IOUtils.lineIterator(reader); lineIt.hasNext();)
             {
-                line = rewriteLine(lineIt.nextLine());
+                line = rewriteLine(lineIt.nextLine(), context);
                 out.println(line);
             }
 
@@ -68,6 +68,6 @@ public abstract class AbstractTextLineCo
         }
     }
 
-    protected abstract String rewriteLine(String line) throws ContentRewritingException, IOException;
+    protected abstract String rewriteLine(String line, ContentRewritingContext context) throws ContentRewritingException, IOException;
 
 }

Added: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/StreamSink.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/StreamSink.java?rev=1620110&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/StreamSink.java (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/StreamSink.java Sun Aug 24 05:28:33 2014
@@ -0,0 +1,92 @@
+/**
+ * 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.rewriter.impl;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import org.apache.portals.applications.webcontent2.rewriter.Sink;
+
+public class StreamSink implements Sink
+{
+
+    private OutputStream output;
+    private String encoding;
+    private Writer writer;
+
+    public StreamSink(OutputStream output)
+    {
+        this(output, null);
+    }
+
+    public StreamSink(OutputStream output, String encoding)
+    {
+        if (output == null)
+        {
+            throw new IllegalArgumentException("output must not be null.");
+        }
+
+        this.output = output;
+        this.encoding = encoding;
+    }
+
+    public StreamSink(Writer writer)
+    {
+        if (writer == null)
+        {
+            throw new IllegalArgumentException("writer must not be null.");
+        }
+
+        this.writer = writer;
+    }
+
+    public OutputStream getOutputStream() throws IOException
+    {
+        if (writer != null)
+        {
+            throw new IllegalStateException("getWriter() has already been called on this sink.");
+        }
+
+        return output;
+    }
+
+    public Writer getWriter() throws IOException
+    {
+        if (output != null)
+        {
+            throw new IllegalStateException("getOutputStream() has already been called on this sink.");
+        }
+
+        if (writer == null)
+        {
+            if (encoding == null)
+            {
+                writer = new OutputStreamWriter(output);
+            }
+            else
+            {
+                writer = new OutputStreamWriter(output, encoding);
+            }
+        }
+
+        return writer;
+    }
+}

Added: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/StreamSource.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/StreamSource.java?rev=1620110&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/StreamSource.java (added)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/impl/StreamSource.java Sun Aug 24 05:28:33 2014
@@ -0,0 +1,93 @@
+/**
+ * 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.rewriter.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.apache.portals.applications.webcontent2.rewriter.Source;
+
+public class StreamSource implements Source
+{
+
+    private InputStream input;
+    private String encoding;
+    private Reader reader;
+
+    public StreamSource(InputStream input)
+    {
+        this(input, null);
+    }
+
+    public StreamSource(InputStream input, String encoding)
+    {
+        if (input == null)
+        {
+            throw new IllegalArgumentException("input must not be null.");
+        }
+
+        this.input = input;
+        this.encoding = encoding;
+    }
+
+    public StreamSource(Reader reader)
+    {
+        if (reader == null)
+        {
+            throw new IllegalArgumentException("reader must not be null.");
+        }
+
+        this.reader = reader;
+    }
+
+    public InputStream getInputStream() throws IOException
+    {
+        if (reader != null)
+        {
+            throw new IllegalStateException("getReader() has already been called on this source.");
+        }
+
+        return input;
+    }
+
+    public Reader getReader() throws IOException
+    {
+        if (input != null)
+        {
+            throw new IllegalStateException("getInputStream() has already been called on this source.");
+        }
+
+        if (reader == null)
+        {
+            if (encoding == null)
+            {
+                reader = new InputStreamReader(input);
+            }
+            else
+            {
+                reader = new InputStreamReader(input, encoding);
+            }
+        }
+
+        return reader;
+    }
+
+}

Modified: portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/TextLineContentRewriterTest.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/TextLineContentRewriterTest.java?rev=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/TextLineContentRewriterTest.java (original)
+++ portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/TextLineContentRewriterTest.java Sun Aug 24 05:28:33 2014
@@ -70,7 +70,7 @@ public class TextLineContentRewriterTest
 
         contentRewriter = new AbstractTextLineContentRewriter() {
             @Override
-            protected String rewriteLine(String line) throws ContentRewritingException, IOException
+            protected String rewriteLine(String line, ContentRewritingContext context) throws ContentRewritingException, IOException
             {
                 return StringUtils.replace(line, "1.3", "2.0");
             }

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -109,7 +109,6 @@ public class SimpleReverseProxyPortlet e
 
         ResolveRemoteURICommand resolveRemoteURICommand = new ResolveRemoteURICommand();
         resolveRemoteURICommand.setUriCleaner(new DefaultURICleaner());
-        ResolveContentRewriterCommand resolveContentRewriterCommand = new ResolveContentRewriterCommand();
 
         InitHttpClientCommand initHttpClientCommand = new InitHttpClientCommand();
         initHttpClientCommand.setHttpClientBuilder(createHttpClientBuilder());
@@ -119,6 +118,7 @@ public class SimpleReverseProxyPortlet e
         ExecuteHttpClientCommand executeHttpClientCommand = new ExecuteHttpClientCommand();
         HandleRedirectionCommand handleRedirectionCommand = new HandleRedirectionCommand();
         HandleNotModifiedCommand handleNotModifiedCommand = new HandleNotModifiedCommand();
+        ResolveContentRewriterCommand resolveContentRewriterCommand = new ResolveContentRewriterCommand();
         AddHeadersToResponseCommand addHeadersToResponseCommand = new AddHeadersToResponseCommand();
         AddCookiesToResponseCommand addCookiesToResponseCommand = new AddCookiesToResponseCommand();
         SerializeHttpEntityContentCommand serializeHttpEntityContentCommand = new SerializeHttpEntityContentCommand();
@@ -126,13 +126,13 @@ public class SimpleReverseProxyPortlet e
         processingChain.addCommand(resolveLocalPathCommand);
         processingChain.addCommand(resolveProxyMappingCommand);
         processingChain.addCommand(resolveRemoteURICommand);
-        processingChain.addCommand(resolveContentRewriterCommand);
         processingChain.addCommand(initHttpClientCommand);
         processingChain.addCommand(initHttpRequestCommand);
         processingChain.addCommand(addHeaderToHttpRequestCommand);
         processingChain.addCommand(executeHttpClientCommand);
         processingChain.addCommand(handleRedirectionCommand);
         processingChain.addCommand(handleNotModifiedCommand);
+        processingChain.addCommand(resolveContentRewriterCommand);
         processingChain.addCommand(addHeadersToResponseCommand);
         processingChain.addCommand(addCookiesToResponseCommand);
         processingChain.addCommand(serializeHttpEntityContentCommand);

Modified: portals/applications/webcontent/trunk/reverse-proxy/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/pom.xml?rev=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/pom.xml (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/pom.xml Sun Aug 24 05:28:33 2014
@@ -113,7 +113,7 @@
   <profiles>
 
     <!--
-      You can run `mvn -Prun clean veryfy' for easier testing at http://localhost:8080/.
+      You can run `mvn -Prun clean veryfy' for easier testing at http://localhost:8080/webcontent2/.
       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"
@@ -164,7 +164,7 @@
               </execution>
             </executions>
             <configuration>
-              <contextPath>/</contextPath>
+              <contextPath>/webcontent2</contextPath>
               <webAppSourceDirectory>${basedir}/src/test/webapp</webAppSourceDirectory>
               <classesDirectory>${basedir}/target/classes, ${basedir}/target/test-classes</classesDirectory>
               <systemProperties>

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/ProxyMapping.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/ProxyMapping.java?rev=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/ProxyMapping.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/ProxyMapping.java Sun Aug 24 05:28:33 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.portals.applications.webcontent2.proxy;
 
+import java.net.URI;
 import java.util.Map;
 
 import org.apache.portals.applications.webcontent2.rewriter.ContentRewriter;
@@ -28,11 +29,11 @@ public interface ProxyMapping
 
     public String resolveRemoteFromLocal(String localPath);
 
-    public boolean matchesRemote(String remoteURI);
+    public boolean matchesRemote(URI remoteURI);
 
-    public String resolveLocalFromRemote(String remoteURI);
+    public String resolveLocalFromRemote(URI remoteURI);
 
-    public ContentRewriter getContentRewriter();
+    public ContentRewriter getContentRewriter(String mimeType);
 
     public Object getAttribute(String name);
 

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.portals.applications.webcontent2.proxy;
 
+import java.net.URI;
 import java.util.Collection;
 
 
@@ -33,5 +34,5 @@ public interface ProxyMappingRegistry
 
     public ProxyMapping findProxyMappingByLocalPath(String localPath);
 
-    public ProxyMapping findProxyMappingByRemoteURI(String remoteURI);
+    public ProxyMapping findProxyMappingByRemoteURI(URI remoteURI);
 }

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -23,8 +23,8 @@ import java.util.List;
 
 import javax.servlet.http.Cookie;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.http.client.CookieStore;
+import org.apache.http.client.utils.URIUtils;
 import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
 import org.apache.portals.applications.webcontent2.proxy.impl.ProxyContext;
@@ -84,11 +84,8 @@ public class AddCookiesToResponseCommand
 
         if (cookiePath != null)
         {
-            URI remoteURI = URI.create(context.getRemoteURI());
-            String remotePath = remoteURI.getPath();
-            String baseURI = StringUtils.substringBefore(remoteURI.toString(), "?");
-            baseURI = baseURI.substring(0, baseURI.length() - remotePath.length());
-            String cookieRemoteURI = baseURI + cookiePath;
+            URI remoteURI = context.getRemoteURI();
+            URI cookieRemoteURI = URIUtils.resolve(remoteURI, cookiePath);
             cookiePath = context.getResolvedMapping().resolveLocalFromRemote(cookieRemoteURI);
         }
 

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -51,7 +51,7 @@ public class HandleNotModifiedCommand ex
         context.getRequestContext().setIntHeader(HTTP.CONTENT_LEN, 0);
         context.getRequestContext().setStatus(HttpServletResponse.SC_NOT_MODIFIED);
 
-        return false;
+        return true;
     }
 
 }

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -66,7 +66,7 @@ public class HandleRedirectionCommand ex
         // According to rfc2616, "Location" header value must be an absolute URI.
         // However, in case it is not, prepend the host URI of the proxy target URL.
         if (location.startsWith("/")) {
-            URI targetURI = URI.create(context.getRemoteURI());
+            URI targetURI = context.getRemoteURI();
             String scheme = targetURI.getScheme();
             int port = targetURI.getPort();
             StringBuilder uriBuilder = new StringBuilder(40).append(targetURI.getScheme()).append("://").append(targetURI.getHost());
@@ -79,18 +79,20 @@ public class HandleRedirectionCommand ex
             location = uriBuilder.toString();
         }
 
+        URI locationURI = URI.create(location);
+
         // Modify the redirect to go to this proxy servlet rather that the proxied host
-        String localPath = context.getResolvedMapping().resolveLocalFromRemote(location);
+        String localPath = context.getResolvedMapping().resolveLocalFromRemote(locationURI);
 
         // if the current proxy path mapper cannot map the remote location to local path, then
         // try to find out a possible path mapper instead one more...
         if (localPath == null)
         {
-            ProxyMapping proxyMapping = context.getProxyMappingRegistry().findProxyMappingByRemoteURI(location);
+            ProxyMapping proxyMapping = context.getProxyMappingRegistry().findProxyMappingByRemoteURI(locationURI);
 
             if (proxyMapping != null)
             {
-                localPath = proxyMapping.resolveLocalFromRemote(location);
+                localPath = proxyMapping.resolveLocalFromRemote(locationURI);
             }
         }
 
@@ -108,7 +110,7 @@ public class HandleRedirectionCommand ex
 
         context.getRequestContext().sendRedirect(redirectLocation);
 
-        return false;
+        return true;
     }
 
 }

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -17,6 +17,7 @@
 package org.apache.portals.applications.webcontent2.proxy.command;
 
 import java.io.IOException;
+import java.net.URI;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -46,7 +47,7 @@ public class InitHttpRequestCommand exte
         HttpRequestBase httpRequest = null;
 
         String method = context.getRequestContext().getMethod();
-        String remoteURI = context.getRemoteURI();
+        URI remoteURI = context.getRemoteURI();
 
         if (HttpGet.METHOD_NAME.equals(method))
         {

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -18,6 +18,9 @@ package org.apache.portals.applications.
 
 import java.io.IOException;
 
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.entity.ContentType;
 import org.apache.portals.applications.webcontent2.proxy.ProxyMapping;
 import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
 import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
@@ -30,10 +33,20 @@ public class ResolveContentRewriterComma
     @Override
     protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
     {
+        HttpResponse httpResponse = context.getHttpResponse();
+        HttpEntity httpEntity = httpResponse.getEntity();
+
+        ContentType contentType = ContentType.getOrDefault(httpEntity);
+        String mimeType = contentType.getMimeType();
+
         ProxyMapping resolvedMapping = context.getResolvedMapping();
 
-        ContentRewriter contentRewriter = resolvedMapping.getContentRewriter();
-        context.setContentRewriter(contentRewriter);
+        ContentRewriter contentRewriter = resolvedMapping.getContentRewriter(mimeType);
+
+        if (contentRewriter != null)
+        {
+            context.setContentRewriter(contentRewriter);
+        }
 
         return false;
     }

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -17,6 +17,7 @@
 package org.apache.portals.applications.webcontent2.proxy.command;
 
 import java.io.IOException;
+import java.net.URI;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -56,7 +57,7 @@ public class ResolveRemoteURICommand ext
             remoteURI = uriCleaner.clean(remoteURI);
         }
 
-        context.setRemoteURI(remoteURI);
+        context.setRemoteURI(URI.create(remoteURI));
 
         return false;
     }

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -31,6 +31,8 @@ import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.entity.ContentType;
+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;
 import org.apache.portals.applications.webcontent2.proxy.impl.GzippedSource;
@@ -84,6 +86,11 @@ public class SerializeHttpEntityContentC
         Source source = new HttpEntitySource(httpEntity);
         Sink sink = context.getRequestContext().getSink();
 
+        ContentType contentType = ContentType.getOrDefault(httpEntity);
+        String mimeType = contentType.getMimeType();
+        Charset charset = contentType.getCharset();
+        String charsetName = StringUtils.defaultIfEmpty((charset != null ? charset.name() : null), getDefaultCharacterEncoding());
+
         boolean gzipEncoded = isGzipEncodedContent(httpEntity);
 
         ContentRewriter contentRewriter = context.getContentRewriter();
@@ -120,11 +127,7 @@ public class SerializeHttpEntityContentC
         }
         else
         {
-            ContentType contentType = ContentType.getOrDefault(httpEntity);
-            Charset charset = contentType.getCharset();
-            String charsetName = StringUtils.defaultIfEmpty((charset != null ? charset.name() : null), getDefaultCharacterEncoding());
-
-            ContentRewritingContext rewritingContext = createContentRewritingContext();
+            ContentRewritingContext rewritingContext = createContentRewritingContext(context);
 
             if (gzipEncoded)
             {
@@ -143,6 +146,7 @@ public class SerializeHttpEntityContentC
         Sink sink = context.getRequestContext().getSink();
 
         ContentType contentType = ContentType.getOrDefault(httpEntity);
+        String mimeType = contentType.getMimeType();
         Charset charset = contentType.getCharset();
         String charsetName = StringUtils.defaultIfEmpty((charset != null ? charset.name() : null), getDefaultCharacterEncoding());
 
@@ -159,7 +163,7 @@ public class SerializeHttpEntityContentC
         {
             if (contentRewriter != null)
             {
-                ContentRewritingContext rewritingContext = createContentRewritingContext();
+                ContentRewritingContext rewritingContext = createContentRewritingContext(context);
 
                 if (gzipEncoded)
                 {
@@ -223,9 +227,14 @@ public class SerializeHttpEntityContentC
         }
     }
 
-    protected ContentRewritingContext createContentRewritingContext()
+    protected ContentRewritingContext createContentRewritingContext(final ProxyContext proxyContext)
     {
         SimpleContentRewritingContext contentRewritingContext = new SimpleContentRewritingContext();
+
+        contentRewritingContext.setAttribute(ProxyContext.class.getName(), proxyContext);
+        contentRewritingContext.setAttribute(ProxyMapping.class.getName(), proxyContext.getResolvedMapping());
+        contentRewritingContext.setAttribute(ProxyMappingRegistry.class.getName(), proxyContext.getProxyMappingRegistry());
+
         return contentRewritingContext;
     }
 

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/AbstractProxyCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/AbstractProxyCommand.java?rev=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/AbstractProxyCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/AbstractProxyCommand.java Sun Aug 24 05:28:33 2014
@@ -25,24 +25,13 @@ import org.apache.portals.applications.w
 public abstract class AbstractProxyCommand implements Command
 {
 
-    private Boolean forcedResult;
-
     public void initialize()
     {
     }
 
-    public final boolean execute(Context context) throws ReverseProxyException, IOException
+    public boolean execute(Context context) throws ReverseProxyException, IOException
     {
-        boolean savedResult = executeInternal((ProxyContext) context);
-
-        if (forcedResult != null)
-        {
-            return forcedResult.booleanValue();
-        }
-        else
-        {
-            return savedResult;
-        }
+        return executeInternal((ProxyContext) context);
     }
 
     protected abstract boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException;
@@ -50,15 +39,4 @@ public abstract class AbstractProxyComma
     public void destroy()
     {
     }
-
-    public Boolean getForcedResult()
-    {
-        return forcedResult;
-    }
-
-    public void setForcedResult(Boolean forcedResult)
-    {
-        this.forcedResult = forcedResult;
-    }
-
 }

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/AbstractProxyMapping.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/AbstractProxyMapping.java?rev=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/AbstractProxyMapping.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/AbstractProxyMapping.java Sun Aug 24 05:28:33 2014
@@ -27,7 +27,7 @@ public abstract class AbstractProxyMappi
 {
 
     private Map<String, Object> attributes;
-    private ContentRewriter contentRewriter;
+    private Map<String, ContentRewriter> contentRewriters;
 
     public Object getAttribute(String name)
     {
@@ -79,14 +79,34 @@ public abstract class AbstractProxyMappi
         }
     }
 
-    public ContentRewriter getContentRewriter()
+    public Map<String, ContentRewriter> getContentRewriters()
     {
-        return contentRewriter;
+        if (contentRewriters == null)
+        {
+            return Collections.emptyMap();
+        }
+
+        return Collections.unmodifiableMap(contentRewriters);
+    }
+
+    public void setContentRewriters(Map<String, ContentRewriter> contentRewriters)
+    {
+        this.contentRewriters = new HashMap<String, ContentRewriter>();
+
+        if (contentRewriters != null)
+        {
+            this.contentRewriters.putAll(contentRewriters);
+        }
     }
 
-    public void setContentRewriter(ContentRewriter contentRewriter)
+    public ContentRewriter getContentRewriter(String mimeType)
     {
-        this.contentRewriter = contentRewriter;
+        if (mimeType != null)
+        {
+            return getContentRewriters().get(mimeType);
+        }
+
+        return null;
     }
 
 }

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.portals.applications.webcontent2.proxy.impl;
 
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -74,7 +75,7 @@ public class DefaultProxyMappingRegistry
         return null;
     }
 
-    public ProxyMapping findProxyMappingByRemoteURI(String remoteURI)
+    public ProxyMapping findProxyMappingByRemoteURI(URI remoteURI)
     {
         if (remoteURI == null)
         {

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyContext.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyContext.java?rev=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyContext.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyContext.java Sun Aug 24 05:28:33 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.portals.applications.webcontent2.proxy.impl;
 
+import java.net.URI;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -39,7 +40,7 @@ public class ProxyContext extends Contex
     private ProxyMappingRegistry proxyMappingRegistry;
     private ProxyMapping resolvedMapping;
     private String localPath;
-    private String remoteURI;
+    private URI remoteURI;
     private HttpClient httpClient;
     private CookieStore cookieStore;
     private HttpRequestBase httpRequest;
@@ -95,12 +96,12 @@ public class ProxyContext extends Contex
         this.localPath = localPath;
     }
 
-    public String getRemoteURI()
+    public URI getRemoteURI()
     {
         return remoteURI;
     }
 
-    public void setRemoteURI(String remoteURI)
+    public void setRemoteURI(URI remoteURI)
     {
         this.remoteURI = remoteURI;
     }

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/RegexProxyMapping.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/RegexProxyMapping.java?rev=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/RegexProxyMapping.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/RegexProxyMapping.java Sun Aug 24 05:28:33 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.portals.applications.webcontent2.proxy.impl;
 
+import java.net.URI;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -95,15 +96,15 @@ public class RegexProxyMapping extends A
         return null;
     }
 
-    public boolean matchesRemote(String remoteURI)
+    public boolean matchesRemote(URI remoteURI)
     {
-        Matcher m = remotePatternObject.matcher(remoteURI);
+        Matcher m = remotePatternObject.matcher(remoteURI.toString());
         return m.matches();
     }
 
-    public String resolveLocalFromRemote(String remoteURI)
+    public String resolveLocalFromRemote(URI remoteURI)
     {
-        Matcher m = remotePatternObject.matcher(remoteURI);
+        Matcher m = remotePatternObject.matcher(remoteURI.toString());
 
         if (m.matches())
         {

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ServletRequestContext.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ServletRequestContext.java?rev=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ServletRequestContext.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ServletRequestContext.java Sun Aug 24 05:28:33 2014
@@ -67,24 +67,31 @@ public class ServletRequestContext imple
         {
             return requestBasePath;
         }
-        else
+
+        StringBuilder sb = new StringBuilder(20);
+
+        String contextPath = (String) request.getAttribute("javax.servlet.include.context_path");
+
+        if (contextPath == null)
         {
-            String contextPath = (String) request.getAttribute("javax.servlet.include.context_path");
+            contextPath = request.getContextPath();
+        }
 
-            if (contextPath == null)
-            {
-                return contextPath = request.getContextPath();
-            }
+        sb.append(contextPath);
 
-            String servletPath = (String) request.getAttribute("javax.servlet.include.servlet_path");
+        String servletPath = (String) request.getAttribute("javax.servlet.include.servlet_path");
 
-            if (servletPath == null)
-            {
-                servletPath = request.getServletPath();
-            }
+        if (servletPath == null)
+        {
+            servletPath = request.getServletPath();
+        }
 
-            return contextPath + servletPath;
+        if (servletPath != null)
+        {
+            sb.append(servletPath);
         }
+
+        return sb.toString();
     }
 
     public void setRequestBasePath(String requestBasePath)

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -16,13 +16,15 @@
  */
 package org.apache.portals.applications.webcontent2.proxy.impl;
 
+import java.net.URI;
+
 import org.apache.commons.lang.StringUtils;
 
 public class SimpleProxyMapping extends AbstractProxyMapping
 {
 
     private String localBasePath;
-    private String remoteBaseURI;
+    private URI remoteBaseURI;
 
     public SimpleProxyMapping()
     {
@@ -38,12 +40,12 @@ public class SimpleProxyMapping extends 
         this.localBasePath = localBasePath;
     }
 
-    public String getRemote()
+    public URI getRemote()
     {
         return remoteBaseURI;
     }
 
-    public void setRemote(String remoteBaseURI)
+    public void setRemote(URI remoteBaseURI)
     {
         this.remoteBaseURI = remoteBaseURI;
     }
@@ -63,16 +65,16 @@ public class SimpleProxyMapping extends 
         return null;
     }
 
-    public boolean matchesRemote(String remoteURI)
+    public boolean matchesRemote(URI remoteURI)
     {
-        return StringUtils.startsWith(remoteURI, remoteBaseURI);
+        return StringUtils.startsWith(remoteURI.toString(), remoteBaseURI.toString());
     }
 
-    public String resolveLocalFromRemote(String remoteURI)
+    public String resolveLocalFromRemote(URI remoteURI)
     {
         if (matchesRemote(remoteURI))
         {
-            return localBasePath + remoteURI.substring(remoteBaseURI.length());
+            return localBasePath + remoteURI.toString().substring(remoteBaseURI.toString().length());
         }
 
         return null;

Added: 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=1620110&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java (added)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/rewriter/DefaultReverseProxyTextLineContentRewriter.java Sun Aug 24 05:28:33 2014
@@ -0,0 +1,159 @@
+/*
+ * 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.rewriter;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.client.utils.URIUtils;
+import org.apache.portals.applications.webcontent2.proxy.ProxyMapping;
+import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
+import org.apache.portals.applications.webcontent2.proxy.RequestContext;
+import org.apache.portals.applications.webcontent2.proxy.impl.ProxyContext;
+import org.apache.portals.applications.webcontent2.proxy.util.CharArraySegment;
+import org.apache.portals.applications.webcontent2.rewriter.ContentRewritingContext;
+import org.apache.portals.applications.webcontent2.rewriter.ContentRewritingException;
+import org.apache.portals.applications.webcontent2.rewriter.impl.AbstractTextLineContentRewriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultReverseProxyTextLineContentRewriter extends AbstractTextLineContentRewriter
+{
+
+    private static Logger log = LoggerFactory.getLogger(DefaultReverseProxyTextLineContentRewriter.class);
+
+    protected static final Pattern LINK_PATTERN = 
+                    Pattern.compile("(\\s|^)(href\\s*=\\s*|src\\s*=\\s*|action\\s*=\\s*|url\\s*\\(\\s*)((\"([^\"]*)\")|('([^']*)'))", Pattern.CASE_INSENSITIVE);
+
+
+    public DefaultReverseProxyTextLineContentRewriter()
+    {
+    }
+
+    @Override
+    protected String rewriteLine(String line, ContentRewritingContext context) throws ContentRewritingException, IOException
+    {
+        CharSequence segment = new CharArraySegment(line);
+        Matcher matcher = null;
+
+        StringBuilder sbLine = new StringBuilder();
+        boolean anyFound = false;
+        String uri = null;
+
+        for (matcher = LINK_PATTERN.matcher(segment); matcher.find(); )
+        {
+            anyFound = true;
+
+            sbLine.append(segment.subSequence(0, matcher.start()))
+                .append(matcher.group(1))
+                .append(matcher.group(2));
+
+            uri = matcher.group(5);
+
+            if (uri != null)
+            {
+                sbLine.append('"').append(rewriteURI(uri, context)).append('"');
+            }
+            else
+            {
+                uri = matcher.group(7);
+                sbLine.append('\'').append(rewriteURI(uri, context)).append('\'');
+            }
+
+            segment = segment.subSequence(matcher.end(), segment.length());
+            matcher.reset(segment);
+        }
+
+        if (anyFound)
+        {
+            sbLine.append(segment);
+            return sbLine.toString();
+        }
+        else
+        {
+            return line;
+        }
+    }
+
+    protected String rewriteURI(String uri, ContentRewritingContext context)
+    {
+        if (StringUtils.isBlank(uri))
+        {
+            return uri;
+        }
+
+        URI uriObj = URI.create(uri);
+
+        String scheme = uriObj.getScheme();
+
+        if (scheme != null)
+        {
+            if (!StringUtils.equalsIgnoreCase(scheme, "http") && !StringUtils.equalsIgnoreCase(scheme, "https"))
+            {
+                // no http(s) url is not rewritten. e.g. data: or mail
+                return uri;
+            }
+        }
+
+        ProxyContext proxyContext = (ProxyContext) context.getAttribute(ProxyContext.class.getName());
+
+        if (proxyContext == null)
+        {
+            log.warn("ProxyContext not found! No rewriting for '{}'.", uri);
+            return uri;
+        }
+
+        RequestContext requestContext = proxyContext.getRequestContext();
+        ProxyMapping currentMapping = (ProxyMapping) context.getAttribute(ProxyMapping.class.getName());
+        ProxyMappingRegistry mappingRegistry = (ProxyMappingRegistry) context.getAttribute(ProxyMappingRegistry.class.getName());
+
+        URI remoteURI = URIUtils.resolve(proxyContext.getRemoteURI(), uriObj);
+
+        String localPath = null;
+
+        if (currentMapping.matchesRemote(remoteURI))
+        {
+            localPath = currentMapping.resolveLocalFromRemote(remoteURI);
+        }
+        else
+        {
+            for (ProxyMapping proxyMapping : mappingRegistry.getProxyMappings())
+            {
+                if (currentMapping == proxyMapping)
+                {
+                    continue;
+                }
+
+                if (proxyMapping.matchesRemote(remoteURI))
+                {
+                    localPath = proxyMapping.resolveLocalFromRemote(remoteURI);
+                    break;
+                }
+            }
+        }
+
+        if (localPath != null)
+        {
+            return new StringBuilder(80).append(requestContext.getRequestBasePath()).append(localPath).toString();
+        }
+
+        return uri;
+    }
+}

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -86,7 +86,8 @@ public class DefaultReverseProxyServlet 
         {
             try
             {
-                ProxyContext proxyContext = new ProxyContext(new ServletRequestContext(request, response));
+                ServletRequestContext requestContext = new ServletRequestContext(request, response);
+                ProxyContext proxyContext = new ProxyContext(requestContext);
                 proxyService.invoke(proxyContext);
             }
             catch (ReverseProxyException e)

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=1620110&r1=1620109&r2=1620110&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 Sun Aug 24 05:28:33 2014
@@ -114,7 +114,6 @@ public class SimpleReverseProxyServlet e
 
         ResolveRemoteURICommand resolveRemoteURICommand = new ResolveRemoteURICommand();
         resolveRemoteURICommand.setUriCleaner(new DefaultURICleaner());
-        ResolveContentRewriterCommand resolveContentRewriterCommand = new ResolveContentRewriterCommand();
 
         InitHttpClientCommand initHttpClientCommand = new InitHttpClientCommand();
         initHttpClientCommand.setHttpClientBuilder(createHttpClientBuilder());
@@ -124,6 +123,7 @@ public class SimpleReverseProxyServlet e
         ExecuteHttpClientCommand executeHttpClientCommand = new ExecuteHttpClientCommand();
         HandleRedirectionCommand handleRedirectionCommand = new HandleRedirectionCommand();
         HandleNotModifiedCommand handleNotModifiedCommand = new HandleNotModifiedCommand();
+        ResolveContentRewriterCommand resolveContentRewriterCommand = new ResolveContentRewriterCommand();
         AddHeadersToResponseCommand addHeadersToResponseCommand = new AddHeadersToResponseCommand();
         AddCookiesToResponseCommand addCookiesToResponseCommand = new AddCookiesToResponseCommand();
         SerializeHttpEntityContentCommand serializeHttpEntityContentCommand = new SerializeHttpEntityContentCommand();
@@ -131,13 +131,13 @@ public class SimpleReverseProxyServlet e
         processingChain.addCommand(resolveLocalPathCommand);
         processingChain.addCommand(resolveProxyMappingCommand);
         processingChain.addCommand(resolveRemoteURICommand);
-        processingChain.addCommand(resolveContentRewriterCommand);
         processingChain.addCommand(initHttpClientCommand);
         processingChain.addCommand(initHttpRequestCommand);
         processingChain.addCommand(addHeaderToHttpRequestCommand);
         processingChain.addCommand(executeHttpClientCommand);
         processingChain.addCommand(handleRedirectionCommand);
         processingChain.addCommand(handleNotModifiedCommand);
+        processingChain.addCommand(resolveContentRewriterCommand);
         processingChain.addCommand(addHeadersToResponseCommand);
         processingChain.addCommand(addCookiesToResponseCommand);
         processingChain.addCommand(serializeHttpEntityContentCommand);

Added: 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=1620110&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/CharArraySegment.java (added)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/CharArraySegment.java Sun Aug 24 05:28:33 2014
@@ -0,0 +1,90 @@
+/*
+ * 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 javax.swing.text.Segment;
+
+/**
+ * CharArraySegment
+ * <P>
+ * Implements {@link CharSequence} interface by leveraging {@link Segment} class.
+ * </P>
+ * <P>
+ * <EM>
+ * Note: Since Java 1.6, {@link Segment} implements {@link CharSequence} interface.
+ * </EM>
+ * </P>
+ */
+public class CharArraySegment extends Segment implements CharSequence
+{
+
+    public CharArraySegment()
+    {
+        super();
+    }
+
+    public CharArraySegment(char[] array, int offset, int count)
+    {
+        super(array, offset, count);
+    }
+
+    public CharArraySegment(String s)
+    {
+        super(s.toCharArray(), 0, s.length());
+    }
+
+    public char charAt(int index)
+    {
+        if (index < 0 || index >= count)
+        {
+            throw new IllegalArgumentException("Invalid index: " + index);
+        }
+
+        return array[offset + index];
+    }
+
+    public int length()
+    {
+        return count;
+    }
+
+    public CharSequence subSequence(int start, int end)
+    {
+        if (start < 0)
+        {
+            throw new IllegalArgumentException("Invalid start index: " + start);
+        }
+
+        if (end > count)
+        {
+            throw new IllegalArgumentException("Invalid end index: " + end);
+        }
+
+        if (start > end)
+        {
+            throw new IllegalArgumentException("Invalid start and end index: " + start + " > " + end);
+        }
+
+        CharArraySegment charArraySegment = new CharArraySegment();
+
+        charArraySegment.array = array;
+        charArraySegment.offset = offset + start;
+        charArraySegment.count = end - start;
+
+        return charArraySegment;
+    }
+}

Modified: 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=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java Sun Aug 24 05:28:33 2014
@@ -16,7 +16,6 @@
  */
 package org.apache.portals.applications.webcontent2.proxy.util;
 
-import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
@@ -50,7 +49,6 @@ public class YamlConfigUtils
 
         String mappingYaml = null;
         InputStream input = null;
-        BufferedInputStream bis = null;
 
         final String mappings = StrSubstitutor.replaceSystemProperties(yamlConfig);
         final String trimmedMappings = StringUtils.trim(mappings);
@@ -76,17 +74,16 @@ public class YamlConfigUtils
                     mappingYaml = mappings;
                 }
 
-                Yaml yaml = new Yaml(constructor);
+                if (mappingYaml == null && input != null)
+                {
+                    mappingYaml = IOUtils.toString(input, "UTF-8");
+                }
 
                 if (mappingYaml != null)
                 {
+                    Yaml yaml = new Yaml(constructor);
                     allObjects = yaml.loadAll(mappingYaml);
                 }
-                else if (input != null)
-                {
-                    bis = new BufferedInputStream(input);
-                    allObjects = yaml.loadAll(bis);
-                }
             }
             catch (Exception e)
             {
@@ -94,7 +91,6 @@ public class YamlConfigUtils
             }
             finally
             {
-                IOUtils.closeQuietly(bis);
                 IOUtils.closeQuietly(input);
             }
         }

Copied: portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/ProxyCommandChainTest.java (from r1620099, portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/CommonsChainTest.java)
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/ProxyCommandChainTest.java?p2=portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/ProxyCommandChainTest.java&p1=portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/CommonsChainTest.java&r1=1620099&r2=1620110&rev=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/CommonsChainTest.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/ProxyCommandChainTest.java Sun Aug 24 05:28:33 2014
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.portals.applications.webcontent2;
+package org.apache.portals.applications.webcontent2.proxy;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNul
 import static org.junit.Assert.assertTrue;
 
 import java.io.Closeable;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Arrays;
@@ -38,8 +39,10 @@ import org.apache.commons.chain.Chain;
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
 import org.apache.commons.chain.impl.CatalogBase;
-import org.apache.commons.chain.impl.ChainBase;
-import org.apache.commons.chain.impl.ContextBase;
+import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
+import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
+import org.apache.portals.applications.webcontent2.proxy.impl.ProxyContext;
+import org.apache.portals.applications.webcontent2.proxy.impl.ProxyProcessingChain;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -57,7 +60,7 @@ import org.junit.Test;
  * individually.
  * </P>
  */
-public class CommonsChainTest
+public class ProxyCommandChainTest
 {
 
     private Catalog catalog;
@@ -91,22 +94,14 @@ public class CommonsChainTest
         Command initCommand = new InitCommand();
         Command authCommand = new AuthCommand();
         Command renderingCommand = new RenderingCommand();
+        Command notInvokedCommand = new NotInvokedCommand();
         Command cleanupCommand = new CleanupCommand();
 
-        Chain preprocessingChain = new ChainBase(new Command [] { initCommand });
-        Chain processingChain = new ChainBase(new Command [] { authCommand, renderingCommand }) 
-        {
-            @Override
-            public boolean execute(Context context) throws Exception
-            {
-                super.execute(context);
-                // return false here in order to make sure to invoke the postprocessing chain.
-                return false;
-            }
-        };
-        Chain postprocessingChain = new ChainBase(new Command [] { cleanupCommand });
+        Chain preprocessingChain = new ProxyProcessingChain(new Command [] { initCommand });
+        Chain processingChain = new ProxyProcessingChain(new Command [] { authCommand, renderingCommand, notInvokedCommand });
+        Chain postprocessingChain = new ProxyProcessingChain(new Command [] { cleanupCommand });
 
-        Chain defaultChain = new ChainBase(new Command [] { preprocessingChain, processingChain, postprocessingChain });
+        Chain defaultChain = new ProxyProcessingChain(new Command [] { preprocessingChain, processingChain, postprocessingChain });
 
         commandsMap.put("default", defaultChain);
 
@@ -119,7 +114,7 @@ public class CommonsChainTest
     {
         Command defaultCommand = catalog.getCommand("default");
 
-        Context context = new ContextBase();
+        ProxyContext context = new ProxyContext(null);
         StringWriter sw = new StringWriter();
         context.put("out", new PrintWriter(sw));
         context.put("user.name", "John");
@@ -132,9 +127,11 @@ public class CommonsChainTest
         assertTrue(logs.contains("InitCommand has executed."));
         assertTrue(logs.contains("AuthCommand is about to execute."));
         assertTrue(logs.contains("AuthCommand has executed."));
+        assertTrue(logs.contains("RenderingCommand is about to execute."));
         assertTrue(logs.contains("RenderingCommand has executed."));
-        assertTrue(logs.contains("RenderingCommand has executed."));
-        assertTrue(logs.contains("CleanupCommand has executed."));
+        assertFalse(logs.contains("NotInvokedCommand is about to execute."));
+        assertFalse(logs.contains("NotInvokedCommand has executed."));
+        assertTrue(logs.contains("CleanupCommand is about to execute."));
         assertTrue(logs.contains("CleanupCommand has executed."));
         assertEquals("Hello, John!", sw.toString());
     }
@@ -145,7 +142,7 @@ public class CommonsChainTest
     {
         Command defaultCommand = catalog.getCommand("default");
 
-        Context context = new ContextBase();
+        ProxyContext context = new ProxyContext(null);
         StringWriter sw = new StringWriter();
         context.put("out", new PrintWriter(sw));
         context.put("user.name", "John");
@@ -160,9 +157,11 @@ public class CommonsChainTest
         assertTrue(logs.contains("InitCommand has executed."));
         assertTrue(logs.contains("AuthCommand is about to execute."));
         assertTrue(logs.contains("AuthCommand has executed."));
+        assertTrue(logs.contains("RenderingCommand is about to execute."));
         assertTrue(logs.contains("RenderingCommand has executed."));
-        assertTrue(logs.contains("RenderingCommand has executed."));
-        assertTrue(logs.contains("CleanupCommand has executed."));
+        assertFalse(logs.contains("NotInvokedCommand is about to execute."));
+        assertFalse(logs.contains("NotInvokedCommand has executed."));
+        assertTrue(logs.contains("CleanupCommand is about to execute."));
         assertTrue(logs.contains("CleanupCommand has executed."));
         assertEquals("Hello, John!", sw.toString());
     }
@@ -173,7 +172,7 @@ public class CommonsChainTest
     {
         Command defaultCommand = catalog.getCommand("default");
 
-        Context context = new ContextBase();
+        ProxyContext context = new ProxyContext(null);
         StringWriter sw = new StringWriter();
         context.put("out", new PrintWriter(sw));
         context.put("user.name", "John");
@@ -188,17 +187,20 @@ public class CommonsChainTest
         assertTrue(logs.contains("InitCommand has executed."));
         assertTrue(logs.contains("AuthCommand is about to execute."));
         assertTrue(logs.contains("AuthCommand has executed."));
+        assertFalse(logs.contains("RenderingCommand is about to execute."));
         assertFalse(logs.contains("RenderingCommand has executed."));
-        assertFalse(logs.contains("RenderingCommand has executed."));
-        assertTrue(logs.contains("CleanupCommand has executed."));
+        assertFalse(logs.contains("NotInvokedCommand is about to execute."));
+        assertFalse(logs.contains("NotInvokedCommand has executed."));
+        assertTrue(logs.contains("CleanupCommand is about to execute."));
         assertTrue(logs.contains("CleanupCommand has executed."));
         assertEquals("", sw.toString());
     }
 
-    private abstract class AbstractLoggableCommand implements Command
+    private abstract class AbstractLoggableCommand extends AbstractProxyCommand
     {
         @SuppressWarnings("unchecked")
-        public final boolean execute(Context context) throws Exception
+        @Override
+        public final boolean execute(Context context) throws ReverseProxyException, IOException
         {
             List<String> logs = (List<String>) context.get("logs");
 
@@ -209,18 +211,17 @@ public class CommonsChainTest
 
             try {
                 logs.add(getClass().getSimpleName() + " is about to execute.");
-                return executeInternal(context);
+                return super.execute(context);
             } finally {
                 logs.add(getClass().getSimpleName() + " has executed.");
             }
         }
-
-        abstract protected boolean executeInternal(Context context) throws Exception;
     }
 
     private class InitCommand extends AbstractLoggableCommand
     {
-        protected boolean executeInternal(Context context) throws Exception
+        @Override
+        protected boolean executeInternal(ProxyContext context) throws ReverseProxyException, IOException
         {
             return false;
         }
@@ -229,7 +230,8 @@ public class CommonsChainTest
     private class AuthCommand extends AbstractLoggableCommand
     {
         @SuppressWarnings("unchecked")
-        protected boolean executeInternal(Context context) throws Exception
+        @Override
+        protected boolean executeInternal(ProxyContext context) throws ReverseProxyException, IOException
         {
             final String roleAllowed = (String) context.get("role.allowed");
 
@@ -255,12 +257,22 @@ public class CommonsChainTest
 
     private class RenderingCommand extends AbstractLoggableCommand
     {
-        protected boolean executeInternal(Context context) throws Exception
+        @Override
+        protected boolean executeInternal(ProxyContext context) throws ReverseProxyException, IOException
         {
             PrintWriter out = (PrintWriter) context.get("out");
             out.print("Hello, " + context.get("user.name") + "!");
             out.flush();
 
+            return true;
+        }
+    }
+
+    private class NotInvokedCommand extends AbstractLoggableCommand
+    {
+        @Override
+        protected boolean executeInternal(ProxyContext context) throws ReverseProxyException, IOException
+        {
             return false;
         }
     }
@@ -268,7 +280,8 @@ public class CommonsChainTest
     private class CleanupCommand extends AbstractLoggableCommand
     {
         @SuppressWarnings("unchecked")
-        protected boolean executeInternal(Context context) throws Exception
+        @Override
+        protected boolean executeInternal(ProxyContext context) throws ReverseProxyException, IOException
         {
             Collection<Closeable> closeables = (Collection<Closeable>) context.get("closeables");
 

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommandTest.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommandTest.java?rev=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommandTest.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommandTest.java Sun Aug 24 05:28:33 2014
@@ -18,6 +18,8 @@ package org.apache.portals.applications.
 
 import static org.junit.Assert.assertEquals;
 
+import java.net.URI;
+
 import org.apache.http.impl.cookie.BasicClientCookie;
 import org.apache.portals.applications.webcontent2.proxy.impl.ProxyContext;
 import org.apache.portals.applications.webcontent2.proxy.impl.SimpleProxyMapping;
@@ -35,11 +37,11 @@ public class AddCookiesToResponseCommand
 
         SimpleProxyMapping mapping = new SimpleProxyMapping();
         mapping.setLocal("/apache/portals/");
-        mapping.setRemote("http://portals.apache.org/");
+        mapping.setRemote(URI.create("http://portals.apache.org/"));
         proxyContext.setResolvedMapping(mapping);
 
         proxyContext.setLocalPath("/apache/portals/docs/mission.html");
-        proxyContext.setRemoteURI("http://portals.apache.org/docs/mission.html");
+        proxyContext.setRemoteURI(URI.create("http://portals.apache.org/docs/mission.html"));
 
         BasicClientCookie cookie = new BasicClientCookie("MYSESSIONID", "1234567890");
         cookie.setPath("/");

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/impl/RegexProxyMappingTest.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/impl/RegexProxyMappingTest.java?rev=1620110&r1=1620109&r2=1620110&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/impl/RegexProxyMappingTest.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/impl/RegexProxyMappingTest.java Sun Aug 24 05:28:33 2014
@@ -19,6 +19,8 @@ package org.apache.portals.applications.
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.net.URI;
+
 import org.junit.Test;
 
 public class RegexProxyMappingTest
@@ -40,8 +42,8 @@ public class RegexProxyMappingTest
         assertEquals("http://portals.apache.org/", mapping.resolveRemoteFromLocal("/apache/portals/"));
         assertEquals("http://portals.apache.org/mission.html", mapping.resolveRemoteFromLocal("/apache/portals/mission.html"));
 
-        assertEquals("/apache/portals/", mapping.resolveLocalFromRemote("http://portals.apache.org/"));
-        assertEquals("/apache/portals/mission.html", mapping.resolveLocalFromRemote("http://portals.apache.org/mission.html"));
+        assertEquals("/apache/portals/", mapping.resolveLocalFromRemote(URI.create("http://portals.apache.org/")));
+        assertEquals("/apache/portals/mission.html", mapping.resolveLocalFromRemote(URI.create("http://portals.apache.org/mission.html")));
     }
 
 }