Author: kishanthan
Date: Mon Sep 30 01:40:10 2013
New Revision: 1527429

URL: http://svn.apache.org/r1527429
Log:
fixing AXIS2-5608 by removing the specific check for JSESSIONID/axis_session 
and adding whatever the value(s) in the Set-Cookie header as session cookie

Modified:
    
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
    
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java

Modified: 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java?rev=1527429&r1=1527428&r2=1527429&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
 Mon Sep 30 01:40:10 2013
@@ -413,19 +413,28 @@ public class HTTPSenderImpl extends HTTP
         // Process old style headers first
         Header[] cookieHeaders = 
method.getResponseHeaders(HTTPConstants.HEADER_SET_COOKIE);
         String customCoookiId = (String) 
msgContext.getProperty(Constants.CUSTOM_COOKIE_ID);
-        for (int i = 0; i < cookieHeaders.length; i++) {
-            HeaderElement[] elements = cookieHeaders[i].getElements();
-            for (int e = 0; e < elements.length; e++) {
-                HeaderElement element = elements[e];
-                if 
(Constants.SESSION_COOKIE.equalsIgnoreCase(element.getName())
-                        || 
Constants.SESSION_COOKIE_JSESSIONID.equalsIgnoreCase(element.getName())) {
-                    sessionCookie = processCookieHeader(element);
-                }
-                if (customCoookiId != null && 
customCoookiId.equalsIgnoreCase(element.getName())) {
-                    sessionCookie = processCookieHeader(element);
-                }
-            }
-        }
+
+        // The following only check for JSESSIONID / axis_session / 
custom-cookie-id from the Set-Cookie header.
+        // But it will ignore if there are other Set-Cookie values, which may 
cause issues at client level,
+        // when invoking via a load-balancer, which expect some specific 
Cookie value.
+        // So the correct fix is to add whatever the value(s) in the 
Set-Cookie header as session cookie.
+
+//        for (int i = 0; i < cookieHeaders.length; i++) {
+//            HeaderElement[] elements = cookieHeaders[i].getElements();
+//            for (int e = 0; e < elements.length; e++) {
+//                HeaderElement element = elements[e];
+//                if 
(Constants.SESSION_COOKIE.equalsIgnoreCase(element.getName())
+//                        || 
Constants.SESSION_COOKIE_JSESSIONID.equalsIgnoreCase(element.getName())) {
+//                    sessionCookie = processCookieHeader(element);
+//                }
+//                if (customCoookiId != null && 
customCoookiId.equalsIgnoreCase(element.getName())) {
+//                    sessionCookie = processCookieHeader(element);
+//                }
+//            }
+//        }
+
+        sessionCookie = processSetCookieHeaders(cookieHeaders);
+
         // Overwrite old style cookies with new style ones if present
         cookieHeaders = 
method.getResponseHeaders(HTTPConstants.HEADER_SET_COOKIE2);
         for (int i = 0; i < cookieHeaders.length; i++) {
@@ -442,7 +451,7 @@ public class HTTPSenderImpl extends HTTP
             }
         }
 
-        if (sessionCookie != null) {
+        if (sessionCookie != null && !sessionCookie.equals("")) {
             
msgContext.getServiceContext().setProperty(HTTPConstants.COOKIE_STRING, 
sessionCookie);
         }
     }
@@ -457,6 +466,25 @@ public class HTTPSenderImpl extends HTTP
         return cookie;
     }
 
+
+    private String processSetCookieHeaders(Header[] headers) {
+        String cookie = "";
+        for (Header header : headers) {
+            if (!cookie.equals("")) {
+                cookie = cookie + ";";
+            }
+            HeaderElement[] elements = header.getElements();
+            for (HeaderElement element : elements) {
+                cookie = cookie + element.getName() + "=" + element.getValue();
+                NameValuePair[] parameters = element.getParameters();
+                for (NameValuePair parameter : parameters) {
+                    cookie = cookie + "; " + parameter.getName() + "=" + 
parameter.getValue();
+                }
+            }
+        }
+        return cookie;
+    }
+
     protected void processResponse(HttpMethodBase httpMethod, MessageContext 
msgContext)
             throws IOException {
         obtainHTTPHeaderInformation(httpMethod, msgContext);

Modified: 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java?rev=1527429&r1=1527428&r2=1527429&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java
 Mon Sep 30 01:40:10 2013
@@ -433,19 +433,28 @@ public class HTTPSenderImpl extends HTTP
         // Process old style headers first
         Header[] cookieHeaders = 
response.getHeaders(HTTPConstants.HEADER_SET_COOKIE);
         String customCoookiId = (String) 
msgContext.getProperty(Constants.CUSTOM_COOKIE_ID);
-        for (int i = 0; i < cookieHeaders.length; i++) {
-            HeaderElement[] elements = cookieHeaders[i].getElements();
-            for (int e = 0; e < elements.length; e++) {
-                HeaderElement element = elements[e];
-                if 
(Constants.SESSION_COOKIE.equalsIgnoreCase(element.getName())
-                    || 
Constants.SESSION_COOKIE_JSESSIONID.equalsIgnoreCase(element.getName())) {
-                    sessionCookie = processCookieHeader(element);
-                }
-                if (customCoookiId != null && 
customCoookiId.equalsIgnoreCase(element.getName())) {
-                    sessionCookie = processCookieHeader(element);
-                }
-            }
-        }
+
+        // The following only check for JSESSIONID / axis_session / 
custom-cookie-id from the Set-Cookie header.
+        // But it will ignore if there are other Set-Cookie values, which may 
cause issues at client level,
+        // when invoking via a load-balancer, which expect some specific 
Cookie value.
+        // So the correct fix is to add whatever the value(s) in the 
Set-Cookie header as session cookie.
+
+//        for (int i = 0; i < cookieHeaders.length; i++) {
+//            HeaderElement[] elements = cookieHeaders[i].getElements();
+//            for (int e = 0; e < elements.length; e++) {
+//                HeaderElement element = elements[e];
+//                if 
(Constants.SESSION_COOKIE.equalsIgnoreCase(element.getName())
+//                    || 
Constants.SESSION_COOKIE_JSESSIONID.equalsIgnoreCase(element.getName())) {
+//                    sessionCookie = processCookieHeader(element);
+//                }
+//                if (customCoookiId != null && 
customCoookiId.equalsIgnoreCase(element.getName())) {
+//                    sessionCookie = processCookieHeader(element);
+//                }
+//            }
+//        }
+
+        sessionCookie = processSetCookieHeaders(cookieHeaders);
+
         // Overwrite old style cookies with new style ones if present
         cookieHeaders = response.getHeaders(HTTPConstants.HEADER_SET_COOKIE2);
         for (int i = 0; i < cookieHeaders.length; i++) {
@@ -462,7 +471,7 @@ public class HTTPSenderImpl extends HTTP
             }
         }
 
-        if (sessionCookie != null) {
+        if (sessionCookie != null  && !sessionCookie.equals("")) {
             
msgContext.getServiceContext().setProperty(HTTPConstants.COOKIE_STRING, 
sessionCookie);
         }
     }
@@ -477,6 +486,24 @@ public class HTTPSenderImpl extends HTTP
         return cookie;
     }
 
+    private String processSetCookieHeaders(Header[] headers) {
+        String cookie = "";
+        for (Header header : headers) {
+            if (!cookie.equals("")) {
+                cookie = cookie + ";";
+            }
+            HeaderElement[] elements = header.getElements();
+            for (HeaderElement element : elements) {
+                cookie = cookie + element.getName() + "=" + element.getValue();
+                NameValuePair[] parameters = element.getParameters();
+                for (NameValuePair parameter : parameters) {
+                    cookie = cookie + "; " + parameter.getName() + "=" + 
parameter.getValue();
+                }
+            }
+        }
+        return cookie;
+    }
+
     protected void processResponse(HttpResponse response, MessageContext 
msgContext)
             throws IOException {
         obtainHTTPHeaderInformation(response, msgContext);


Reply via email to