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/10/30 10:10:59 UTC
svn commit: r831234 -
/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java
Author: woonsan
Date: Fri Oct 30 09:10:59 2009
New Revision: 831234
URL: http://svn.apache.org/viewvc?rev=831234&view=rev
Log:
APA-18: Setting path for proxy response cookies.
Modified:
portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java
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=831234&r1=831233&r2=831234&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 Fri Oct 30 09:10:59 2009
@@ -24,12 +24,14 @@
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
+import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
+import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@@ -61,6 +63,7 @@
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.impl.cookie.BasicClientCookie;
@@ -226,8 +229,24 @@
proxyTargetURL = new StringBuilder(proxyTargetURL.length() + 1 + queryString.length()).append(proxyTargetURL).append('?').append(queryString).toString();
}
+ final List<org.apache.http.cookie.Cookie> responseSetCookies = new ArrayList<org.apache.http.cookie.Cookie>();
// create http client for each request...
- DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, clientParams);
+ DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, clientParams)
+ {
+ @Override
+ protected CookieStore createCookieStore()
+ {
+ return new BasicCookieStore()
+ {
+ @Override
+ public void addCookie(org.apache.http.cookie.Cookie cookie)
+ {
+ responseSetCookies.add(cookie);
+ }
+ };
+ }
+ };
+
// redirection should be adjusted with local host header...
httpClient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
@@ -464,6 +483,9 @@
if (rewritable && StringUtils.equalsIgnoreCase(headerName, HTTP.CONTENT_LEN))
continue;
+ if (StringUtils.startsWithIgnoreCase(headerName, "Set-Cookie"))
+ continue;
+
String headerValue = header.getValue();
if (StringUtils.equalsIgnoreCase(headerName, HTTP.TARGET_HOST))
@@ -478,10 +500,27 @@
String rewriterContextPath = localBaseURL;
- if (rewriterContextPath == null) {
+ if (rewriterContextPath == null)
+ {
rewriterContextPath = request.getContextPath() + request.getServletPath();
}
+ for (org.apache.http.cookie.Cookie cookie : responseSetCookies)
+ {
+ Cookie responseCookie = new Cookie(cookie.getName(), cookie.getValue());
+ responseCookie.setComment(cookie.getComment());
+ Date expireDate = cookie.getExpiryDate();
+ if (expireDate != null)
+ {
+ int maxAgeSeconds = (int) ((expireDate.getTime() - System.currentTimeMillis()) / 1000L);
+ responseCookie.setMaxAge(maxAgeSeconds);
+ }
+ responseCookie.setPath(rewriterContextPath + proxyPathMapper.getLocalBasePath());
+ responseCookie.setSecure(cookie.isSecure());
+ responseCookie.setVersion(cookie.getVersion());
+ response.addCookie(responseCookie);
+ }
+
// Send the content to the client
writeHttpEntityToClient(response, httpEntity, proxyPathMapper, rewriterContextPath, localPathInfo, rewriter, parserAdaptor);
}