Here's my patch. Attached is a diff for SOAPHTTPConnection and a new file for org.apache.soap.transport.http.Cookie.
I have tested this locally with samples.addressbook2.Main to confirm that it does not break the existing functionality. I have also tested the new Cookie class with a test harness to verify many of its behaviors vis-a-vis the cookie RFCs. However, I will leave it up to Swami and the community to actually break it ;). Scott Nichol ----- Original Message ----- From: "Scott Nichol" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, June 06, 2002 2:45 PM Subject: Re: Session Scope and Cookies > I'll give this a try. > > Scott Nichol > ----- Original Message ----- > From: "K. Swaminathan" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Thursday, June 06, 2002 2:11 PM > Subject: RE: Session Scope and Cookies > > > > ->If its an issue with SOAP 2.2 its not solved with 2.3. I wrote the > > ->cookie stuff with the expectation that there would be only one (I > > ->don't recall my mental state then but probably it was a combination > > ->of lack of understanding and laziness ;-)). > > > > ->Can you submit a patch to fix it? > > The cleaner fix to this requires some dissection on, HttpUtils, > > TransportMessage, and SOAPHttpConnection, to make sure that > > the hashtable that contains the header values, stores all the > > Set-Cookie/Set-Cookie2 values, (perhaps in a String[] instead > > of a String). > > The Http-Spec seems to expects you to 'comma separate' these > > multiple values and set them as a single(!!!) header in the request. > > > > > > Can someone who is more familiar with the code/specs, volunteer. > > > > thanks > > Swami K. > > > > -> > > ->Bye, > > -> > > ->Sanjiva. > > -> > > ->----- Original Message ----- > > ->From: "K. Swaminathan" <[EMAIL PROTECTED]> > > ->To: <[EMAIL PROTECTED]> > > ->Sent: Wednesday, June 05, 2002 5:44 AM > > ->Subject: Session Scope and Cookies > > -> > > -> > > ->> > > ->> The SOAPHttpConnection.java, seems to remember and restore > > ->only a single > > ->> entry > > ->> for the Set-Cookie and Set-Cookie2 header fields, whereas the > > ->spec allows > > ->> for > > ->> more than one to be present. > > ->> > > ->> Is this a solved issue in SOAP 2.3?? > > ->> > > ->> thanks > > ->> Swami K. > > ->> > > ->> > > ->> >One thing to point out, this is a CLIENT side issue not a server side > > ->> issue. > > ->> > > > ->> >It does appear to be correct that multiple entries can be sent in the > > ->same > > ->> >"Cookie:" value, but in terms of storing an manipulating them > > ->this has to > > ->> be > > ->> >done outside of the XML-SOAP code. (Thanks for that one Scott). > > ->> > > > ->> >On the non-passing of the transport headers, this is still there in the > > ->> >current nightly build. This does appear to be a minor > > ->bug-ette. Is the > > ->> fix > > ->> >that sends the headers from the transport acceptable ? > > ->> > > > ->> >Steve > > ->> > > > ->> > -----Original Message----- > > ->> > From: Steve Jones [SMTP:[EMAIL PROTECTED]] > > ->> > Sent: 04 April 2001 16:45 > > ->> > To: Soap-Dev (E-mail) > > ->> > Subject: Session scope and cookies... > > ->> > > > ->> >... > > ->> > The problem is that because the headers is a hashtable indexed by the > > ->key > > ->> > then only one cookie can be sent. This is fine for my example as the > > ->only > > ->> > cookie is the JSESSIONID, if however another cookie was sent > > ->it would be > > ->> > up > > ->> > for grabs which one is sent back. > > ->> > > > ->> > What should I really have done ? > > ->> > > > ->> > Steve > > -> > > -> > > > > > >
Cookie.java
Description: Binary data
--- SOAPHTTPConnection.java.orig Fri Jun 07 01:51:58 2002
+++ SOAPHTTPConnection.java Fri Jun 07 02:06:15 2002
@@ -95,8 +95,8 @@
private String proxyUserName;
private String proxyPassword;
private boolean maintainSession = true;
- private String cookieHeader;
- private String cookieHeader2;
+ private Cookie[] cookies;
+ private Cookie[] cookies2;
private int outputBufferSize = HTTPUtils.DEFAULT_OUTPUT_BUFFER_SIZE;
private Boolean tcpNoDelay = null;
@@ -183,8 +183,8 @@
public void setMaintainSession (boolean maintainSession) {
this.maintainSession = maintainSession;
if (maintainSession == false) {
- cookieHeader = null;
- cookieHeader2 = null;
+ cookies = null;
+ cookies2 = null;
}
}
@@ -279,11 +279,11 @@
}
if (maintainSession) {
// if there is saved cookie headers, put them in to the request
- if (cookieHeader2 != null) { // RFC 2965 header
- headers.put ("Cookie2", cookieHeader2);
+ if (cookies2 != null) { // RFC 2965 header
+ headers.put ("Cookie2", Cookie.buildCookieValue(sendTo, cookies2));
}
- if (cookieHeader != null) { // RFC 2109 header
- headers.put ("Cookie", cookieHeader);
+ if (cookies != null) { // RFC 2109 header
+ headers.put ("Cookie", Cookie.buildCookieValue(sendTo, cookies));
}
}
@@ -323,8 +323,7 @@
responseSOAPContext = response.getSOAPContext();
responseHeaders = response.getHeaders();
if (maintainSession) {
- // look for Set-Cookie2 and Set-Cookie headers and save them after
- // stripping everything after the ';' (i.e., ignore all cookie attrs).
+ // look for Set-Cookie2 and Set-Cookie headers and save them.
// Only update my state iff the header is there .. otherwise
// leave the current
// Note: Header is case-insensitive
@@ -333,21 +332,21 @@
hdr = getHeaderValue (responseHeaders, "Set-Cookie2");
if (hdr != null) {
- cookieHeader2 = hdr;
- int index = cookieHeader2.indexOf (';');
- if (index != -1) {
- cookieHeader2 = cookieHeader2.substring (0, index);
- }
+ Cookie[] hdrCookies = Cookie.parseCookies(sendTo, hdr);
+ if (cookies2 != null)
+ cookies2 = Cookie.updateCookies(cookies2, hdrCookies);
+ else
+ cookies2 = hdrCookies;
}
hdr = getHeaderValue (responseHeaders, "Set-Cookie");
if (hdr != null) {
- cookieHeader = hdr;
- int index = cookieHeader.indexOf (';');
- if (index != -1) {
- cookieHeader = cookieHeader.substring (0, index);
- }
+ Cookie[] hdrCookies = Cookie.parseCookies(sendTo, hdr);
+ if (cookies != null)
+ cookies = Cookie.updateCookies(cookies, hdrCookies);
+ else
+ cookies = hdrCookies;
}
}
} catch (IllegalArgumentException e) {
