cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1040640 - in /cxf/branches/2.3.x-fixes: ./ rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
Date Tue, 30 Nov 2010 16:49:17 GMT
Author: dkulp
Date: Tue Nov 30 16:49:16 2010
New Revision: 1040640

URL: http://svn.apache.org/viewvc?rev=1040640&view=rev
Log:
Merged revisions 1040635 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1040635 | dkulp | 2010-11-30 11:45:34 -0500 (Tue, 30 Nov 2010) | 1 line
  
  [CXF-3100] Add cookies on retransmit
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=1040640&r1=1040639&r2=1040640&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
Tue Nov 30 16:49:16 2010
@@ -647,24 +647,7 @@ public class HTTPConduit 
         maintainSession = Boolean.TRUE.equals((Boolean)message.get(Message.MAINTAIN_SESSION));
         
         //If we have any cookies and we are maintaining sessions, then use them        
-        if (maintainSession && sessionCookies.size() > 0) {
-            List<String> cookies = null;
-            for (String s : headers.keySet()) {
-                if (HttpHeaderHelper.COOKIE.equalsIgnoreCase(s)) {
-                    cookies = headers.remove(s);
-                    break;
-                }
-            }
-            if (cookies == null) {
-                cookies = new ArrayList<String>();
-            } else {
-                cookies = new ArrayList<String>(cookies);
-            }
-            headers.put(HttpHeaderHelper.COOKIE, cookies);
-            for (Cookie c : sessionCookies.values()) {
-                cookies.add(c.requestCookieHeader());
-            }
-        }
+        addCookieHeadersToRequest(headers);
 
         // The trust decision is relegated to after the "flushing" of the
         // request headers.
@@ -694,6 +677,7 @@ public class HTTPConduit 
     }
     
     public void close(Message msg) throws IOException {
+
         InputStream in = msg.getContent(InputStream.class);
         try {
             if (in != null) {
@@ -806,6 +790,7 @@ public class HTTPConduit 
      * @throws MalformedURLException
      */
     private URL setupURL(Message message) throws MalformedURLException {
+
         String result = (String)message.get(Message.ENDPOINT_ADDRESS);
         String pathInfo = (String)message.get(Message.PATH_INFO);
         String queryString = (String)message.get(Message.QUERY_STRING);
@@ -1651,7 +1636,6 @@ public class HTTPConduit 
         // which must have been wrong, or we wouldn't be here again.
         // Otherwise, the server may be 401 looping us around the realms.
         if (authURLs.contains(currentURL.toString() + realm)) {
-
             if (LOG.isLoggable(Level.INFO)) {
                 LOG.log(Level.INFO, "Authorization loop detected on Conduit \""
                     + getConduitName()
@@ -1684,6 +1668,10 @@ public class HTTPConduit 
         Map<String, List<String>> headers = getSetProtocolHeaders(message);
         headers.put("Authorization",
                     createMutableList(up));
+
+        // also adding cookie headers when retransmitting in case of a "401 Unauthorized"
response
+        addCookieHeadersToRequest(headers);
+
         return retransmit(
                 connection, currentURL, message, cachedStream);
     }
@@ -1869,6 +1857,34 @@ public class HTTPConduit 
         headers.put("Proxy-Authorization",
                     createMutableList("Basic " + token));
     }
+
+    /**
+     * This method adds the cookie-headers to the request.
+     *  
+     * @param headers die Header des Requests
+     */
+    private void addCookieHeadersToRequest(Map<String, List<String>> headers)
{
+        //If we have any cookies and we are maintaining sessions, then use them        
+        if (maintainSession && sessionCookies.size() > 0) {
+            List<String> cookies = null;
+            for (String s : headers.keySet()) {
+                if (HttpHeaderHelper.COOKIE.equalsIgnoreCase(s)) {
+                    cookies = headers.remove(s);
+                    break;
+                }
+            }
+            if (cookies == null) {
+                cookies = new ArrayList<String>();
+            } else {
+                cookies = new ArrayList<String>(cookies);
+            }
+            headers.put(HttpHeaderHelper.COOKIE, cookies);
+            for (Cookie c : sessionCookies.values()) {
+                cookies.add(c.requestCookieHeader());
+            }
+        }
+    }
+
     
     /**
      * Wrapper output stream responsible for flushing headers and handling
@@ -1891,6 +1907,7 @@ public class HTTPConduit 
          */
         protected final boolean chunking;
         
+    
         /**
          * This field contains the output stream with which we cache
          * the request. It maybe null if we are not caching.
@@ -2123,6 +2140,15 @@ public class HTTPConduit 
                 int maxRetransmits = (policy == null)
                                      ? -1
                                      : policy.getMaxRetransmits();
+
+                // evaluate "Set-Cookie" headers before handling retransmits
+                if (maintainSession) {
+                    for (Map.Entry<String, List<String>> h : connection.getHeaderFields().entrySet())
{
+                        if ("Set-Cookie".equalsIgnoreCase(h.getKey())) {
+                            Cookie.handleSetCookie(sessionCookies, h.getValue());
+                        }
+                    }
+                }
                 
                 // MaxRetransmits of zero means zero.
                 if (maxRetransmits == 0) {



Mime
View raw message