Author: dkulp Date: Tue Nov 30 16:59:12 2010 New Revision: 1040643 URL: http://svn.apache.org/viewvc?rev=1040643&view=rev Log: Merged revisions 1040640 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.3.x-fixes
................ r1040640 | dkulp | 2010-11-30 11:49:16 -0500 (Tue, 30 Nov 2010) | 9 lines 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.2.x-fixes/ (props changed) cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Propchange: cxf/branches/2.2.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=1040643&r1=1040642&r2=1040643&view=diff ============================================================================== --- cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original) +++ cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Tue Nov 30 16:59:12 2010 @@ -646,24 +646,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. @@ -693,6 +676,7 @@ public class HTTPConduit } public void close(Message msg) throws IOException { + InputStream in = msg.getContent(InputStream.class); try { if (in != null) { @@ -805,6 +789,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); @@ -1736,7 +1721,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() @@ -1769,6 +1753,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); } @@ -1952,6 +1940,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 @@ -1974,6 +1990,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. @@ -2205,6 +2222,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) {
