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 13:21:59 UTC

svn commit: r831280 - /portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java

Author: woonsan
Date: Fri Oct 30 12:21:58 2009
New Revision: 831280

URL: http://svn.apache.org/viewvc?rev=831280&view=rev
Log:
APA-18: Setting path for proxy response cookies for each case, including HTTP 302 case.

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=831280&r1=831279&r2=831280&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 12:21:58 2009
@@ -377,6 +377,13 @@
             HttpResponse httpResponse = httpClient.execute(httpRequest);
             httpEntity = httpResponse.getEntity();
             
+            String rewriterContextPath = localBaseURL;
+            
+            if (rewriterContextPath == null) 
+            {
+                rewriterContextPath = request.getContextPath() + request.getServletPath();
+            }
+            
             int statusCode = httpResponse.getStatusLine().getStatusCode();
             
             // Check if the proxy response is a redirect
@@ -425,11 +432,12 @@
                 }
                 else
                 {
-                    if (localBaseURL != null) {
-                        redirectLocation = localBaseURL + localPath;
-                    } else {
-                        redirectLocation = request.getContextPath() + request.getServletPath() + localPath;
-                    }
+                    redirectLocation = rewriterContextPath + localPath;
+                }
+                
+                if (!responseSetCookies.isEmpty())
+                {
+                    addResponseCookies(response, responseSetCookies, rewriterContextPath + proxyPathMapper.getLocalBasePath());
                 }
                 
                 response.sendRedirect(redirectLocation);
@@ -447,6 +455,11 @@
                 response.setIntHeader(HTTP.CONTENT_LEN, 0);
                 response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                 
+                if (!responseSetCookies.isEmpty())
+                {
+                    addResponseCookies(response, responseSetCookies, rewriterContextPath + proxyPathMapper.getLocalBasePath());
+                }
+                
                 return;
             }
             else
@@ -498,27 +511,9 @@
                         }
                     }
                     
-                    String rewriterContextPath = localBaseURL;
-                    
-                    if (rewriterContextPath == null) 
+                    if (!responseSetCookies.isEmpty())
                     {
-                        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);
+                        addResponseCookies(response, responseSetCookies, rewriterContextPath + proxyPathMapper.getLocalBasePath());
                     }
                     
                     // Send the content to the client
@@ -567,6 +562,28 @@
         }
     }
     
+    private void addResponseCookies(HttpServletResponse response, List<org.apache.http.cookie.Cookie> responseSetCookies, String cookiePath)
+    {
+        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(cookiePath);
+            responseCookie.setSecure(cookie.isSecure());
+            responseCookie.setVersion(cookie.getVersion());
+            
+            response.addCookie(responseCookie);
+        }
+    }
+
     private void writeHttpEntityToClient(HttpServletResponse response, 
                                          HttpEntity httpEntity, 
                                          HttpReverseProxyPathMapper proxyPathMapper,