"Vaishnav, Kunal" wrote:
> 
> Hello All,
>   I have a unique error when I am working with JUnit and Cactus. I am
> testing some of my APIs for login stuff. Now
> to login, I need to pass encrypted cookies. Fine that is ok. What I am
> passing in the cookies is a pipe of the username and password. (eg
> username|password). Cactus seems to
> be converting the "|" to %7C. I wanted to know how I can avoid this.
> If it gets converted to %7C, it gives me a number format excpetion and so
> on...
> Is there any workaround this? Is this a bug in Cactus because of which this
> is happening?.

This does look like a bug.

The HttpClientHelper class appears to URLEncode the cookies like so:
(see private addCookies method, round about line 230).

        while (keys.hasMoreElements()) {
            String key = (String)keys.nextElement();
            String value = (String)theRequest.getCookieValue(key);
            cookieString.append(';');
            cookieString.append(URLEncoder.encode(key));
            cookieString.append('=');
            cookieString.append(URLEncoder.encode(value));
            cookieString.append(value);
        }
before using 
        setRequestProperty("Cookie", cookieString.toString());

if you change to :
        while (keys.hasMoreElements()) {
            String key = (String)keys.nextElement();
            String value = (String)theRequest.getCookieValue(key);
            cookieString.append(';');
            cookieString.append(key);
            cookieString.append('=');
            cookieString.append(value);
        }

then the cookie string isn't URLEncoded then it appears to work ok, and
the Cookie values come through ok on the server.

HttpURLConnection must do the encoding for you, in which case your
cookie is being encoded twice! :)


Anyone care to comment? and if this is a bug then fix in the source? 

Vincent?

Jari


> 
> Thx.
> Kunal.

--
Jari Worsley
Senior Programmer
Hyperlink Interactive Ltd

Reply via email to