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 2009/11/05 16:39:00 UTC
svn commit: r833059 - in
/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent:
proxy/ proxy/impl/ rewriter/
Author: woonsan
Date: Thu Nov 5 15:38:39 2009
New Revision: 833059
URL: http://svn.apache.org/viewvc?rev=833059&view=rev
Log:
APA-18: Adding cookie path rewriting inclusion/exclusion options.
Modified:
portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/HttpReverseProxyPathMapper.java
portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperImpl.java
portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperProviderImpl.java
portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java
portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java
portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java
Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/HttpReverseProxyPathMapper.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/HttpReverseProxyPathMapper.java?rev=833059&r1=833058&r2=833059&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/HttpReverseProxyPathMapper.java (original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/HttpReverseProxyPathMapper.java Thu Nov 5 15:38:39 2009
@@ -17,6 +17,7 @@
package org.apache.portals.applications.webcontent.proxy;
import java.util.Map;
+import java.util.Set;
/**
@@ -73,4 +74,16 @@
*/
public Map<String, String> getDefaultRequestCookies();
+ /**
+ * Returns the name set of cookies which path should be rewritten.
+ * @return
+ */
+ public Set<String> getRewriteCookiePathIncludes();
+
+ /**
+ * Returns the name set of cookies which path should not be rewritten.
+ * @return
+ */
+ public Set<String> getRewriteCookiePathExcludes();
+
}
\ No newline at end of file
Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperImpl.java?rev=833059&r1=833058&r2=833059&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperImpl.java (original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperImpl.java Thu Nov 5 15:38:39 2009
@@ -17,6 +17,7 @@
package org.apache.portals.applications.webcontent.proxy.impl;
import java.util.Map;
+import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.portals.applications.webcontent.proxy.HttpReverseProxyPathMapper;
@@ -35,20 +36,27 @@
private Map<String, String> defaultRequestHeaders;
private Map<String, String> defaultRequestCookies;
+ private Set<String> rewriteCookiePathIncludes;
+ private Set<String> rewriteCookiePathExcludes;
+
private int hash;
public DefaultHttpReverseProxyPathMapperImpl(String name, String localBasePath, String remoteBaseURL)
{
- this(name, localBasePath, remoteBaseURL, null, null);
+ this(name, localBasePath, remoteBaseURL, null, null, null, null);
}
- public DefaultHttpReverseProxyPathMapperImpl(String name, String localBasePath, String remoteBaseURL, Map<String, String> defaultRequestHeaders, Map<String, String> defaultRequestCookies)
+ public DefaultHttpReverseProxyPathMapperImpl(String name, String localBasePath, String remoteBaseURL,
+ Map<String, String> defaultRequestHeaders, Map<String, String> defaultRequestCookies,
+ Set<String> rewriteCookiePathIncludes, Set<String> rewriteCookiePathExcludes)
{
this.name = name;
this.localBasePath = localBasePath;
this.remoteBaseURL = remoteBaseURL;
this.defaultRequestHeaders = defaultRequestHeaders;
this.defaultRequestCookies = defaultRequestCookies;
+ this.rewriteCookiePathIncludes = rewriteCookiePathIncludes;
+ this.rewriteCookiePathExcludes = rewriteCookiePathExcludes;
hash = new StringBuilder(40).append(name).append(':').append(localBasePath).append(':').append(remoteBaseURL).toString().hashCode();
}
@@ -123,4 +131,14 @@
return false;
}
+ public Set<String> getRewriteCookiePathIncludes()
+ {
+ return rewriteCookiePathIncludes;
+ }
+
+ public Set<String> getRewriteCookiePathExcludes()
+ {
+ return rewriteCookiePathExcludes;
+ }
+
}
Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperProviderImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperProviderImpl.java?rev=833059&r1=833058&r2=833059&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperProviderImpl.java (original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperProviderImpl.java Thu Nov 5 15:38:39 2009
@@ -220,7 +220,9 @@
localBasePath,
remoteBaseURL,
proxyPathMapper.getDefaultRequestHeaders(),
- proxyPathMapper.getDefaultRequestCookies());
+ proxyPathMapper.getDefaultRequestCookies(),
+ proxyPathMapper.getRewriteCookiePathIncludes(),
+ proxyPathMapper.getRewriteCookiePathExcludes());
RewriterController rewriterController = rewriterControllerMap.get(proxyPathMapper);
Ruleset rewriterRules = rewriterRulesetMap.get(proxyPathMapper);
@@ -316,7 +318,9 @@
localBasePath,
remoteBaseURL,
proxyPathMapper.getDefaultRequestHeaders(),
- proxyPathMapper.getDefaultRequestCookies());
+ proxyPathMapper.getDefaultRequestCookies(),
+ proxyPathMapper.getRewriteCookiePathIncludes(),
+ proxyPathMapper.getRewriteCookiePathExcludes());
RewriterController rewriterController = rewriterControllerMap.get(proxyPathMapper);
Ruleset rewriterRules = rewriterRulesetMap.get(proxyPathMapper);
Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java?rev=833059&r1=833058&r2=833059&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java (original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java Thu Nov 5 15:38:39 2009
@@ -199,9 +199,32 @@
}
}
+ Set<String> rewriteCookiePathIncludes = null;
+ String [] items = pathPassConf.getStringArray("response.cookie.path.rewrite.include");
+ if (items.length > 0)
+ {
+ rewriteCookiePathIncludes = new HashSet<String>();
+ for (String item : items)
+ {
+ rewriteCookiePathIncludes.add(item);
+ }
+ }
+
+ Set<String> rewriteCookiePathExcludes = null;
+ items = pathPassConf.getStringArray("response.cookie.path.rewrite.exclude");
+ if (items.length > 0)
+ {
+ rewriteCookiePathExcludes = new HashSet<String>();
+ for (String item : items)
+ {
+ rewriteCookiePathExcludes.add(item);
+ }
+ }
+
HttpReverseProxyPathMapper proxyPathMapper =
new DefaultHttpReverseProxyPathMapperImpl(pathName, localBasePath, remoteBaseURL,
- defaultRequestHeaders, defaultRequestCookies);
+ defaultRequestHeaders, defaultRequestCookies,
+ rewriteCookiePathIncludes, rewriteCookiePathExcludes);
proxyPathMappers.add(proxyPathMapper);
Configuration rewritersConf = pathPassConf.subset("rewriter");
@@ -747,7 +770,7 @@
try
{
- setBeanProperty(bean, propName, propValues);
+ BeanUtils.setProperty(bean, propName, propValues);
}
catch (Exception e)
{
@@ -795,16 +818,4 @@
return ruleset;
}
- private void setBeanProperty(Object bean, String propName, String [] propValues)
- {
- try
- {
- BeanUtils.setProperty(bean, propName, propValues);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
}
Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java?rev=833059&r1=833058&r2=833059&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java (original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java Thu Nov 5 15:38:39 2009
@@ -28,6 +28,7 @@
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@@ -437,7 +438,7 @@
if (!responseSetCookies.isEmpty())
{
- addResponseCookies(response, responseSetCookies, rewriterContextPath + proxyPathMapper.getLocalBasePath());
+ addResponseCookies(response, responseSetCookies, proxyPathMapper, rewriterContextPath);
}
response.sendRedirect(redirectLocation);
@@ -457,7 +458,7 @@
if (!responseSetCookies.isEmpty())
{
- addResponseCookies(response, responseSetCookies, rewriterContextPath + proxyPathMapper.getLocalBasePath());
+ addResponseCookies(response, responseSetCookies, proxyPathMapper, rewriterContextPath);
}
return;
@@ -513,7 +514,7 @@
if (!responseSetCookies.isEmpty())
{
- addResponseCookies(response, responseSetCookies, rewriterContextPath + proxyPathMapper.getLocalBasePath());
+ addResponseCookies(response, responseSetCookies, proxyPathMapper, rewriterContextPath);
}
// Send the content to the client
@@ -562,11 +563,20 @@
}
}
- private void addResponseCookies(HttpServletResponse response, List<org.apache.http.cookie.Cookie> responseSetCookies, String cookiePath)
+ private void addResponseCookies(HttpServletResponse response, List<org.apache.http.cookie.Cookie> responseSetCookies, HttpReverseProxyPathMapper proxyPathMapper, String rewriterContextPath)
{
+ Set<String> includes = proxyPathMapper.getRewriteCookiePathIncludes();
+ Set<String> excludes = proxyPathMapper.getRewriteCookiePathExcludes();
+ boolean includesEmpty = (includes == null || includes.isEmpty());
+ boolean excludesEmpty = (excludes == null || excludes.isEmpty());
+ boolean allEmpty = (includesEmpty && excludesEmpty);
+
+ String rewrittenCookiePath = rewriterContextPath + proxyPathMapper.getLocalBasePath();
+
for (org.apache.http.cookie.Cookie cookie : responseSetCookies)
{
- Cookie responseCookie = new Cookie(cookie.getName(), cookie.getValue());
+ String cookieName = cookie.getName();
+ Cookie responseCookie = new Cookie(cookieName, cookie.getValue());
responseCookie.setComment(cookie.getComment());
Date expireDate = cookie.getExpiryDate();
@@ -576,10 +586,14 @@
responseCookie.setMaxAge(maxAgeSeconds);
}
- responseCookie.setPath(cookiePath);
responseCookie.setSecure(cookie.isSecure());
responseCookie.setVersion(cookie.getVersion());
+ if ((allEmpty) || (!includesEmpty && includes.contains(cookieName)) || (!excludesEmpty && !excludes.contains(cookieName)))
+ {
+ responseCookie.setPath(rewrittenCookiePath);
+ }
+
response.addCookie(responseCookie);
}
}
Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java?rev=833059&r1=833058&r2=833059&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java (original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/rewriter/MappingRewriterController.java Thu Nov 5 15:38:39 2009
@@ -19,6 +19,7 @@
import java.io.File;
import java.io.InputStream;
import java.io.Reader;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -195,9 +196,16 @@
if (basicRewriterProps != null)
{
- for (Map.Entry<String, String []> entry : basicRewriterProps.entrySet())
+ try
{
- setBeanProperty(rewriter, entry.getKey(), entry.getValue());
+ for (Map.Entry<String, String []> entry : basicRewriterProps.entrySet())
+ {
+ BeanUtils.setProperty(rewriter, entry.getKey(), entry.getValue());
+ }
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new RuntimeException(e);
}
}
@@ -215,7 +223,7 @@
{
for (Map.Entry<String, String []> entry : rulesetRewriterProps.entrySet())
{
- setBeanProperty(rewriter, entry.getKey(), entry.getValue());
+ BeanUtils.setProperty(rewriter, entry.getKey(), entry.getValue());
}
}
@@ -248,7 +256,7 @@
{
for (Map.Entry<String, String []> entry : parserAdaptorProps.entrySet())
{
- setBeanProperty(parserAdaptor, entry.getKey(), entry.getValue());
+ BeanUtils.setProperty(parserAdaptor, entry.getKey(), entry.getValue());
}
}
}
@@ -399,17 +407,5 @@
{
return null;
}
-
- private void setBeanProperty(Object bean, String propName, String [] propValues)
- {
- try
- {
- BeanUtils.setProperty(bean, propName, propValues);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
}
\ No newline at end of file