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/25 03:55:24 UTC
svn commit: r1620251 - in /portals/applications/webcontent/trunk:
content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/
content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/
cont...
Author: woonsan
Date: Mon Aug 25 01:55:23 2014
New Revision: 1620251
URL: http://svn.apache.org/r1620251
Log:
APA-66: adding more tests for htmlcleaner content rewriter and adjusting related apis
Added:
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultProxyProcessingChainBuilder.java
Modified:
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/DefaultSerializerFactory.java
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/HtmlCleanerContentRewriter.java
portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/SerializerFactory.java
portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/HtmlCleanerContentRewriterTest.java
portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/rewriter/guidelines.html
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultReverseProxyPortlet.java
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.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/filter/SimpleReverseProxyFilter.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java
Modified: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/DefaultSerializerFactory.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/DefaultSerializerFactory.java?rev=1620251&r1=1620250&r2=1620251&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/DefaultSerializerFactory.java (original)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/DefaultSerializerFactory.java Mon Aug 25 01:55:23 2014
@@ -17,6 +17,7 @@
package org.apache.portals.applications.webcontent2.rewriter.htmlcleaner;
import org.apache.commons.beanutils.ConstructorUtils;
+import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.Serializer;
public class DefaultSerializerFactory implements SerializerFactory
@@ -48,8 +49,13 @@ public class DefaultSerializerFactory im
this.arguments = arguments;
}
- public Serializer createSerializer() throws Exception
+ public Serializer createSerializer(HtmlCleaner cleaner) throws Exception
{
+ if (arguments == null)
+ {
+ arguments = new Object [] { cleaner.getProperties() };
+ }
+
return (Serializer) ConstructorUtils.invokeConstructor(serializerClass, arguments);
}
}
Modified: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/HtmlCleanerContentRewriter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/HtmlCleanerContentRewriter.java?rev=1620251&r1=1620250&r2=1620251&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/HtmlCleanerContentRewriter.java (original)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/HtmlCleanerContentRewriter.java Mon Aug 25 01:55:23 2014
@@ -21,10 +21,14 @@ import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.ArrayUtils;
import org.apache.portals.applications.webcontent2.rewriter.ContentRewriter;
import org.apache.portals.applications.webcontent2.rewriter.ContentRewritingContext;
import org.apache.portals.applications.webcontent2.rewriter.ContentRewritingException;
@@ -35,49 +39,166 @@ import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.Serializer;
import org.htmlcleaner.TagNode;
import org.htmlcleaner.TagNodeVisitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class HtmlCleanerContentRewriter implements ContentRewriter
{
- private final HtmlCleaner cleaner;
- private final SerializerFactory serializerFactory;
- private TagNodeVisitor tagNodeVisitor;
- public HtmlCleanerContentRewriter(final HtmlCleaner cleaner, final SerializerFactory serializerFactory)
+ private static Logger log = LoggerFactory.getLogger(HtmlCleanerContentRewriter.class);
+
+ private HtmlCleaner cleaner;
+ private SerializerFactory serializerFactory;
+ private String sinkEncoding = "UTF-8";
+ private String rootTagName;
+ private boolean innerRootTagOnly;
+ private String [] transformationInfos;
+ private List<TagNodeVisitor> tagNodeVisitors;
+
+ public HtmlCleanerContentRewriter()
+ {
+ }
+
+ public SerializerFactory getSerializerFactory()
+ {
+ return serializerFactory;
+ }
+
+ public void setSerializerFactory(SerializerFactory serializerFactory)
{
- this.cleaner = cleaner;
this.serializerFactory = serializerFactory;
}
- public void setCleanerTransformations(CleanerTransformations cleanerTransformations) {
- cleaner.getProperties().setCleanerTransformations(cleanerTransformations);
+ public String getSinkEncoding()
+ {
+ return sinkEncoding;
+ }
+
+ public void setSinkEncoding(String sinkEncoding)
+ {
+ this.sinkEncoding = sinkEncoding;
+ }
+
+ public String getRootTagName()
+ {
+ return rootTagName;
+ }
+
+ public void setRootTagName(String rootTagName)
+ {
+ this.rootTagName = rootTagName;
+ }
+
+ public boolean isInnerRootTagOnly()
+ {
+ return innerRootTagOnly;
+ }
+
+ public void setInnerRootTagOnly(boolean innerRootTagOnly)
+ {
+ this.innerRootTagOnly = innerRootTagOnly;
+ }
+
+ public CleanerTransformations getCleanerTransformations()
+ {
+ return getHtmlCleaner().getProperties().getCleanerTransformations();
}
- public void setCleanerTransformations(final String [] transformationInfos) {
- Map<String, String> transInfos = new TreeMap<String, String>();
+ public void setCleanerTransformations(CleanerTransformations cleanerTransformations)
+ {
+ getHtmlCleaner().getProperties().setCleanerTransformations(cleanerTransformations);
+ }
+
+ public String [] getCleanerTransformationStringArray()
+ {
+ if (transformationInfos == null)
+ {
+ return ArrayUtils.EMPTY_STRING_ARRAY;
+ }
+
+ String [] transInfos = new String[transformationInfos.length];
+ System.arraycopy(transformationInfos, 0, transInfos, 0, transformationInfos.length);
+ return transInfos;
+ }
+
+ public void setCleanerTransformationStringArray(final String [] transInfos)
+ {
+ if (transInfos == null)
+ {
+ transformationInfos = ArrayUtils.EMPTY_STRING_ARRAY;
+ }
+ else
+ {
+ transformationInfos = new String[transInfos.length];
+ System.arraycopy(transInfos, 0, transformationInfos, 0, transInfos.length);
+ }
+
+ Map<String, String> transInfosMap = new TreeMap<String, String>();
for (String transInfo : transformationInfos)
{
int index = transInfo.indexOf('=');
String key = index <= 0 ? transInfo : transInfo.substring(0, index);
String value = index <= 0 ? null : transInfo.substring(index + 1);
- transInfos.put(key, value);
+ transInfosMap.put(key, value);
}
- setCleanerTransformations(new CleanerTransformations(transInfos));
+ setCleanerTransformations(new CleanerTransformations(transInfosMap));
}
- public void setTagNodeVisitor(TagNodeVisitor tagNodeVisitor)
+ public List<TagNodeVisitor> getTagNodeVisitors()
{
- this.tagNodeVisitor = tagNodeVisitor;
+ if (tagNodeVisitors == null)
+ {
+ return Collections.emptyList();
+ }
+
+ return Collections.unmodifiableList(tagNodeVisitors);
+ }
+
+ public void setTagNodeVisitors(List<TagNodeVisitor> tagNodeVisitors)
+ {
+ this.tagNodeVisitors = new ArrayList<TagNodeVisitor>();
+
+ if (tagNodeVisitors != null)
+ {
+ this.tagNodeVisitors.addAll(tagNodeVisitors);
+ }
+ }
+
+ public void addTagNodeVisitor(TagNodeVisitor tagNodeVisitor)
+ {
+ if (tagNodeVisitors == null)
+ {
+ tagNodeVisitors = new ArrayList<TagNodeVisitor>();
+ }
+
+ tagNodeVisitors.add(tagNodeVisitor);
+ }
+
+ public void removeTagNodeVisitor(TagNodeVisitor tagNodeVisitor)
+ {
+ if (tagNodeVisitors != null)
+ {
+ tagNodeVisitors.remove(tagNodeVisitor);
+ }
+ }
+
+ public void removeAllTagNodeVisitors()
+ {
+ if (tagNodeVisitors != null)
+ {
+ tagNodeVisitors.clear();
+ }
}
public void rewrite(Source source, Sink sink, ContentRewritingContext context) throws ContentRewritingException, IOException
{
Serializer serializer = null;
- try
+ try
{
- serializer = serializerFactory.createSerializer();
+ serializer = serializerFactory.createSerializer(getHtmlCleaner());
}
catch (Exception e)
{
@@ -89,21 +210,37 @@ public class HtmlCleanerContentRewriter
Writer writer = null;
BufferedWriter bw = null;
- try
+ try
{
reader = source.getReader();
br = new BufferedReader(reader);
writer = sink.getWriter();
bw = new BufferedWriter(writer);
- TagNode tagNode = cleaner.clean(br);
+ TagNode rootTagNode = getHtmlCleaner().clean(br);
- if (tagNodeVisitor != null)
+ if (getRootTagName() != null)
{
- tagNode.traverse(tagNodeVisitor);
+ TagNode [] tagNodes = rootTagNode.getElementsByName(getRootTagName(), true);
+
+ if (tagNodes.length > 0 ) {
+ rootTagNode = tagNodes[0];
+ }
}
- serializer.write(tagNode, writer, "UTF-8");
+ for (TagNodeVisitor tagNodeVisitor : getTagNodeVisitors())
+ {
+ rootTagNode.traverse(tagNodeVisitor);
+ }
+
+ if (isInnerRootTagOnly())
+ {
+ writer.write(getHtmlCleaner().getInnerHtml(rootTagNode));
+ }
+ else
+ {
+ serializer.write(rootTagNode, writer, getSinkEncoding());
+ }
}
finally
{
@@ -113,4 +250,22 @@ public class HtmlCleanerContentRewriter
IOUtils.closeQuietly(writer);
}
}
+
+ protected HtmlCleaner getHtmlCleaner()
+ {
+ if (cleaner == null)
+ {
+ cleaner = createHtmlCleaner();
+ }
+
+ return cleaner;
+ }
+
+ protected HtmlCleaner createHtmlCleaner()
+ {
+ HtmlCleaner htmlCleaner = new HtmlCleaner();
+ htmlCleaner.getProperties().setOmitXmlDeclaration(true);
+ htmlCleaner.getProperties().setOmitDoctypeDeclaration(true);
+ return htmlCleaner;
+ }
}
Modified: portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/SerializerFactory.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/SerializerFactory.java?rev=1620251&r1=1620250&r2=1620251&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/SerializerFactory.java (original)
+++ portals/applications/webcontent/trunk/content-rewriter/src/main/java/org/apache/portals/applications/webcontent2/rewriter/htmlcleaner/SerializerFactory.java Mon Aug 25 01:55:23 2014
@@ -16,9 +16,10 @@
*/
package org.apache.portals.applications.webcontent2.rewriter.htmlcleaner;
+import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.Serializer;
public interface SerializerFactory
{
- public Serializer createSerializer() throws Exception;
+ public Serializer createSerializer(HtmlCleaner cleaner) throws Exception;
}
Modified: portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/HtmlCleanerContentRewriterTest.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/HtmlCleanerContentRewriterTest.java?rev=1620251&r1=1620250&r2=1620251&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/HtmlCleanerContentRewriterTest.java (original)
+++ portals/applications/webcontent/trunk/content-rewriter/src/test/java/org/apache/portals/applications/webcontent2/rewriter/HtmlCleanerContentRewriterTest.java Mon Aug 25 01:55:23 2014
@@ -33,7 +33,6 @@ import org.apache.commons.lang.StringUti
import org.apache.portals.applications.webcontent2.rewriter.htmlcleaner.DefaultSerializerFactory;
import org.apache.portals.applications.webcontent2.rewriter.htmlcleaner.HtmlCleanerContentRewriter;
import org.apache.portals.applications.webcontent2.rewriter.impl.SimpleContentRewritingContext;
-import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.HtmlNode;
import org.htmlcleaner.SimpleHtmlSerializer;
import org.htmlcleaner.TagNode;
@@ -48,6 +47,16 @@ public class HtmlCleanerContentRewriterT
private static Logger log = LoggerFactory.getLogger(HtmlCleanerContentRewriterTest.class);
+ private static String [] HTMLCLEANER_TRNSFORM_INFO =
+ {
+ "cfoutput",
+ "c:block=div,false",
+ "font=span,true",
+ "font.size",
+ "font.face",
+ "font.style=${style};font-family=${face};font-size=${size};"
+ };
+
private Source source;
private Sink sink;
private ByteArrayOutputStream sinkTeeOut;
@@ -81,21 +90,17 @@ public class HtmlCleanerContentRewriterT
}
};
- HtmlCleaner cleaner = new HtmlCleaner();
- cleaner.getProperties().setOmitXmlDeclaration(true);
-
DefaultSerializerFactory serializerFactory = new DefaultSerializerFactory();
serializerFactory.setSerializerClass(SimpleHtmlSerializer.class);
- serializerFactory.setArguments(new Object [] { cleaner.getProperties() });
-
- contentRewriter = new HtmlCleanerContentRewriter(cleaner, serializerFactory);
- String [] transInfos =
- StringUtils.split("cfoutput|c:block=div,false|font=span,true|font.size|font.face|font.style=${style};font-family=${face};font-size=${size};", "|");
- contentRewriter.setCleanerTransformations(transInfos);
+ contentRewriter = new HtmlCleanerContentRewriter();
+ contentRewriter.setSerializerFactory(serializerFactory);
+ contentRewriter.setRootTagName("body");
+ contentRewriter.setInnerRootTagOnly(true);
+ contentRewriter.setCleanerTransformationStringArray(HTMLCLEANER_TRNSFORM_INFO);
final String siteUrl = "http://www.example.com/";
- contentRewriter.setTagNodeVisitor(new TagNodeVisitor()
+ contentRewriter.addTagNodeVisitor(new TagNodeVisitor()
{
public boolean visit(TagNode tagNode, HtmlNode htmlNode)
{
@@ -133,7 +138,6 @@ public class HtmlCleanerContentRewriterT
String output = sinkTeeOut.toString();
log.debug("OUTPUT: {}", output);
- assertTrue(output.contains("<link rel=\"stylesheet\" href=\"http://www.example.com/css/print.css\" type=\"text/css\" media=\"print\" />"));
assertFalse(output.contains("name=\"Project_Guidelines\""));
assertTrue(output.contains("<a href=\"http://www.example.com/roles.html\">Roles and Responsibilities</a>"));
assertTrue(output.contains("general@portals <a href=\"http://www.example.com/mail-lists.html#general\">"));
Modified: portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/rewriter/guidelines.html
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/rewriter/guidelines.html?rev=1620251&r1=1620250&r2=1620251&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/rewriter/guidelines.html (original)
+++ portals/applications/webcontent/trunk/content-rewriter/src/test/resources/org/apache/portals/applications/webcontent2/rewriter/guidelines.html Mon Aug 25 01:55:23 2014
@@ -5,6 +5,9 @@
<title>The Apache Portals Site - Project Guidelines</title>
<link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
<meta name="author" content="Apache Portals Project" />
+<style>
+body { background-color: white; }
+</style>
</head>
<body>
Modified: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultReverseProxyPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultReverseProxyPortlet.java?rev=1620251&r1=1620250&r2=1620251&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultReverseProxyPortlet.java (original)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/DefaultReverseProxyPortlet.java Mon Aug 25 01:55:23 2014
@@ -26,6 +26,7 @@ public class DefaultReverseProxyPortlet
public DefaultReverseProxyPortlet()
{
+ super();
}
public ReverseProxyService getProxyService()
@@ -37,6 +38,4 @@ public class DefaultReverseProxyPortlet
{
this.proxyService = proxyService;
}
-
-
}
Modified: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java?rev=1620251&r1=1620250&r2=1620251&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 Mon Aug 25 01:55:23 2014
@@ -48,7 +48,7 @@ public class SimpleReverseProxyPortlet e
{
super.init(portletConfig);
- proxyServiceCommand = ProxyServices.createDefault(getProxyMappingRegistry(), getHttpClientBuilder()).build();
+ proxyServiceCommand = ProxyServices.createDefault().build(getProxyMappingRegistry(), getHttpClientBuilder());
ProxyCommandUtils.initializeAllCommands(proxyServiceCommand);
DefaultReverseProxyService proxyService = new DefaultReverseProxyService(proxyServiceCommand);
Added: 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=1620251&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultProxyProcessingChainBuilder.java (added)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultProxyProcessingChainBuilder.java Mon Aug 25 01:55:23 2014
@@ -0,0 +1,114 @@
+/*
+ * 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 org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
+import org.apache.portals.applications.webcontent2.proxy.command.AddCookiesToResponseCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.AddHeaderToHttpRequestCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.AddHeadersToResponseCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.CleanupCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.ExecuteHttpClientCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.HandleNotModifiedCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.HandleRedirectionCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.InitHttpClientCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.InitHttpRequestCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.InitializationCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.ResolveContentRewriterCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.ResolveLocalPathCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.ResolveProxyMappingCommand;
+import org.apache.portals.applications.webcontent2.proxy.command.ResolveRemoteURICommand;
+import org.apache.portals.applications.webcontent2.proxy.command.SerializeHttpEntityContentCommand;
+import org.apache.portals.applications.webcontent2.proxy.impl.DefaultURICleaner;
+import org.apache.portals.applications.webcontent2.proxy.impl.ProxyProcessingChain;
+
+public class DefaultProxyProcessingChainBuilder extends ProxyProcessingChainBuilder
+{
+
+ public DefaultProxyProcessingChainBuilder()
+ {
+ super();
+ }
+
+ public ProxyProcessingChain build(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder)
+ {
+ removeAllCommands();
+
+ addCommand(createDefaultPreprocessingCommand(proxyMappingRegistry, httpClientBuilder));
+ addCommand(createDefaultProcessingCommand(proxyMappingRegistry, httpClientBuilder));
+ addCommand(createDefaultPostprocessingCommand(proxyMappingRegistry, httpClientBuilder));
+
+ return super.build(proxyMappingRegistry, httpClientBuilder);
+ }
+
+ protected ProxyProcessingChain createDefaultPreprocessingCommand(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder)
+ {
+ ProxyProcessingChain preprocessingChain = new ProxyProcessingChain();
+ InitializationCommand initializationCommand = new InitializationCommand();
+ preprocessingChain.addCommand(initializationCommand);
+ return preprocessingChain;
+ }
+
+ protected ProxyProcessingChain createDefaultProcessingCommand(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder)
+ {
+ ProxyProcessingChain processingChain = new ProxyProcessingChain();
+
+ ResolveLocalPathCommand resolveLocalPathCommand = new ResolveLocalPathCommand();
+
+ ResolveProxyMappingCommand resolveProxyMappingCommand = new ResolveProxyMappingCommand(proxyMappingRegistry);
+
+ ResolveRemoteURICommand resolveRemoteURICommand = new ResolveRemoteURICommand();
+ resolveRemoteURICommand.setUriCleaner(new DefaultURICleaner());
+
+ InitHttpClientCommand initHttpClientCommand = new InitHttpClientCommand();
+ initHttpClientCommand.setHttpClientBuilder(httpClientBuilder);
+
+ InitHttpRequestCommand initHttpRequestCommand = new InitHttpRequestCommand();
+ AddHeaderToHttpRequestCommand addHeaderToHttpRequestCommand = new AddHeaderToHttpRequestCommand();
+ ExecuteHttpClientCommand executeHttpClientCommand = new ExecuteHttpClientCommand();
+ ResolveContentRewriterCommand resolveContentRewriterCommand = new ResolveContentRewriterCommand();
+ AddHeadersToResponseCommand addHeadersToResponseCommand = new AddHeadersToResponseCommand();
+ AddCookiesToResponseCommand addCookiesToResponseCommand = new AddCookiesToResponseCommand();
+ HandleRedirectionCommand handleRedirectionCommand = new HandleRedirectionCommand();
+ HandleNotModifiedCommand handleNotModifiedCommand = new HandleNotModifiedCommand();
+ SerializeHttpEntityContentCommand serializeHttpEntityContentCommand = new SerializeHttpEntityContentCommand();
+
+ processingChain.addCommand(resolveLocalPathCommand);
+ processingChain.addCommand(resolveProxyMappingCommand);
+ processingChain.addCommand(resolveRemoteURICommand);
+ processingChain.addCommand(initHttpClientCommand);
+ processingChain.addCommand(initHttpRequestCommand);
+ processingChain.addCommand(addHeaderToHttpRequestCommand);
+ processingChain.addCommand(executeHttpClientCommand);
+ processingChain.addCommand(resolveContentRewriterCommand);
+ processingChain.addCommand(addHeadersToResponseCommand);
+ processingChain.addCommand(addCookiesToResponseCommand);
+ processingChain.addCommand(handleRedirectionCommand);
+ processingChain.addCommand(handleNotModifiedCommand);
+ processingChain.addCommand(serializeHttpEntityContentCommand);
+
+ return processingChain;
+ }
+
+ protected ProxyProcessingChain createDefaultPostprocessingCommand(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder)
+ {
+ ProxyProcessingChain postprocessingChain = new ProxyProcessingChain();
+ CleanupCommand cleanupCommand = new CleanupCommand();
+ postprocessingChain.addCommand(cleanupCommand);
+ return postprocessingChain;
+ }
+}
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=1620251&r1=1620250&r2=1620251&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 Aug 25 01:55:23 2014
@@ -20,6 +20,8 @@ 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.ProxyMappingRegistry;
import org.apache.portals.applications.webcontent2.proxy.impl.ProxyProcessingChain;
public class ProxyProcessingChainBuilder
@@ -28,11 +30,11 @@ public class ProxyProcessingChainBuilder
private ProxyProcessingChain chain;
private List<Command> commands;
- protected ProxyProcessingChainBuilder()
+ public ProxyProcessingChainBuilder()
{
}
- public ProxyProcessingChain build()
+ public ProxyProcessingChain build(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder)
{
if (chain == null)
{
@@ -50,13 +52,7 @@ public class ProxyProcessingChainBuilder
return chain;
}
- public ProxyProcessingChain addProxyProcessingChain(ProxyProcessingChain subChain)
- {
- addCommand(subChain);
- return subChain;
- }
-
- public Command addCommand(Command command)
+ public void addCommand(Command command)
{
if (commands == null)
{
@@ -64,7 +60,21 @@ public class ProxyProcessingChainBuilder
}
commands.add(command);
+ }
+
+ public void removeCommand(Command command)
+ {
+ if (commands != null)
+ {
+ commands.remove(command);
+ }
+ }
- return command;
+ 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=1620251&r1=1620250&r2=1620251&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 Aug 25 01:55:23 2014
@@ -16,25 +16,6 @@
*/
package org.apache.portals.applications.webcontent2.proxy.builder;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
-import org.apache.portals.applications.webcontent2.proxy.command.AddCookiesToResponseCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.AddHeaderToHttpRequestCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.AddHeadersToResponseCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.CleanupCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.ExecuteHttpClientCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.HandleNotModifiedCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.HandleRedirectionCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.InitHttpClientCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.InitHttpRequestCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.InitializationCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.ResolveContentRewriterCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.ResolveLocalPathCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.ResolveProxyMappingCommand;
-import org.apache.portals.applications.webcontent2.proxy.command.ResolveRemoteURICommand;
-import org.apache.portals.applications.webcontent2.proxy.command.SerializeHttpEntityContentCommand;
-import org.apache.portals.applications.webcontent2.proxy.impl.DefaultURICleaner;
-import org.apache.portals.applications.webcontent2.proxy.impl.ProxyProcessingChain;
public class ProxyServices
{
@@ -43,72 +24,8 @@ public class ProxyServices
{
}
- public static ProxyProcessingChainBuilder createDefault(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder)
+ public static ProxyProcessingChainBuilder createDefault()
{
- ProxyProcessingChainBuilder builder = new ProxyProcessingChainBuilder();
-
- builder.addCommand(createDefaultPreprocessingCommand(proxyMappingRegistry, httpClientBuilder));
- builder.addCommand(createDefaultProcessingCommand(proxyMappingRegistry, httpClientBuilder));
- builder.addCommand(createDefaultPostprocessingCommand(proxyMappingRegistry, httpClientBuilder));
-
- return builder;
- }
-
- private static ProxyProcessingChain createDefaultPreprocessingCommand(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder)
- {
- ProxyProcessingChain preprocessingChain = new ProxyProcessingChain();
- InitializationCommand initializationCommand = new InitializationCommand();
- preprocessingChain.addCommand(initializationCommand);
- return preprocessingChain;
+ return new DefaultProxyProcessingChainBuilder();
}
-
- private static ProxyProcessingChain createDefaultProcessingCommand(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder)
- {
- ProxyProcessingChain processingChain = new ProxyProcessingChain();
-
- ResolveLocalPathCommand resolveLocalPathCommand = new ResolveLocalPathCommand();
-
- ResolveProxyMappingCommand resolveProxyMappingCommand = new ResolveProxyMappingCommand(proxyMappingRegistry);
-
- ResolveRemoteURICommand resolveRemoteURICommand = new ResolveRemoteURICommand();
- resolveRemoteURICommand.setUriCleaner(new DefaultURICleaner());
-
- InitHttpClientCommand initHttpClientCommand = new InitHttpClientCommand();
- initHttpClientCommand.setHttpClientBuilder(httpClientBuilder);
-
- InitHttpRequestCommand initHttpRequestCommand = new InitHttpRequestCommand();
- AddHeaderToHttpRequestCommand addHeaderToHttpRequestCommand = new AddHeaderToHttpRequestCommand();
- ExecuteHttpClientCommand executeHttpClientCommand = new ExecuteHttpClientCommand();
- ResolveContentRewriterCommand resolveContentRewriterCommand = new ResolveContentRewriterCommand();
- AddHeadersToResponseCommand addHeadersToResponseCommand = new AddHeadersToResponseCommand();
- AddCookiesToResponseCommand addCookiesToResponseCommand = new AddCookiesToResponseCommand();
- HandleRedirectionCommand handleRedirectionCommand = new HandleRedirectionCommand();
- HandleNotModifiedCommand handleNotModifiedCommand = new HandleNotModifiedCommand();
- SerializeHttpEntityContentCommand serializeHttpEntityContentCommand = new SerializeHttpEntityContentCommand();
-
- processingChain.addCommand(resolveLocalPathCommand);
- processingChain.addCommand(resolveProxyMappingCommand);
- processingChain.addCommand(resolveRemoteURICommand);
- processingChain.addCommand(initHttpClientCommand);
- processingChain.addCommand(initHttpRequestCommand);
- processingChain.addCommand(addHeaderToHttpRequestCommand);
- processingChain.addCommand(executeHttpClientCommand);
- processingChain.addCommand(resolveContentRewriterCommand);
- processingChain.addCommand(addHeadersToResponseCommand);
- processingChain.addCommand(addCookiesToResponseCommand);
- processingChain.addCommand(handleRedirectionCommand);
- processingChain.addCommand(handleNotModifiedCommand);
- processingChain.addCommand(serializeHttpEntityContentCommand);
-
- return processingChain;
- }
-
- private static ProxyProcessingChain createDefaultPostprocessingCommand(ProxyMappingRegistry proxyMappingRegistry, HttpClientBuilder httpClientBuilder)
- {
- ProxyProcessingChain postprocessingChain = new ProxyProcessingChain();
- CleanupCommand cleanupCommand = new CleanupCommand();
- postprocessingChain.addCommand(cleanupCommand);
- return postprocessingChain;
- }
-
}
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=1620251&r1=1620250&r2=1620251&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 Aug 25 01:55:23 2014
@@ -48,7 +48,7 @@ public class SimpleReverseProxyFilter ex
{
super.init(filterConfig);
- proxyServiceCommand = ProxyServices.createDefault(getProxyMappingRegistry(), getHttpClientBuilder()).build();
+ proxyServiceCommand = ProxyServices.createDefault().build(getProxyMappingRegistry(), getHttpClientBuilder());
ProxyCommandUtils.initializeAllCommands(proxyServiceCommand);
DefaultReverseProxyService proxyService = new DefaultReverseProxyService(proxyServiceCommand);
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=1620251&r1=1620250&r2=1620251&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 Aug 25 01:55:23 2014
@@ -53,7 +53,7 @@ public class SimpleReverseProxyServlet e
{
super.init(servletConfig);
- proxyServiceCommand = ProxyServices.createDefault(getProxyMappingRegistry(), getHttpClientBuilder()).build();
+ proxyServiceCommand = ProxyServices.createDefault().build(getProxyMappingRegistry(), getHttpClientBuilder());
ProxyCommandUtils.initializeAllCommands(proxyServiceCommand);
DefaultReverseProxyService proxyService = new DefaultReverseProxyService(proxyServiceCommand);