aspose file tools*
The moose likes Servlets and the fly likes Cookie object return incorrect value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookie object return incorrect value" Watch "Cookie object return incorrect value" New topic
Author

Cookie object return incorrect value

Karup Mew
Ranch Hand

Joined: Aug 11, 2007
Posts: 40
Hi All,

Sometimes the cookie object returns incorrect value because the cookie contains value like "YWRtaW5pc3RyYXRvcg=="
but the cookie object getValue method returns like this "YWRtaW5pc3RyYXRvcg" without equal sign. Kindly provide solution for this
problem.

>
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

Well I think you are using Base 64 encoding here. I also used it in one of my projects to encode parameters but never used it with cookies. Try your program on a different servlet container. If you still get the same behavior than I think this is the default behavior and you'll have to use some different encoding...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Karup Mew
Ranch Hand

Joined: Aug 11, 2007
Posts: 40
Yes, I have used base64 and its working in other servlet container .Is this servlet container version problem ?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

Which servlet container is creating problems??
Karup Mew
Ranch Hand

Joined: Aug 11, 2007
Posts: 40
Both are Tomcat5.5 but the size of servletapi.jar is different
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

This is strange . I think you should use Tomcat 6 or the Tomcat 5.5 which is working . maybe this is a tomcat bug or something but I have no idea ...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12787
    
    5
I suspect that = equals signs are not supposed to be part of cookie values.

Digging around in various RFCs it looks like equals signs are treated as separators if they are not in a quoted string.

Base64 encoding may use = as a padding character. See this wikipedia artice for more confusion.

Bill
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Let's take a step back: why base64?
Piyush Jain
Ranch Hand

Joined: Apr 25, 2003
Posts: 60
I am facing the same problem.

Has anyone found a solution to this?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12787
    
    5
I suggest you trim any = signs out of the base64 string before setting the cookie.

Since they only exist to pad to a fixed length the absence should not cause a problem. See the wikipedia article i cited before.

Bill
Piyush Jain
Ranch Hand

Joined: Apr 25, 2003
Posts: 60
That will not work in this scenario:

I have a service middleware, which passes this cookie, which is a siteminder authentication cookie, and if it does not contain the trailing "=", the authentication fails.
senthil doraiswamy
Greenhorn

Joined: Feb 14, 2002
Posts: 9
It might be notate the boundary [ CR / LF ] per base64 convention. Take a look at this ---> link and search for two equal sign (=) characters. You can also do some research on base64 boundary characters.

good luck, sen.
Kah Tang
Ranch Hand

Joined: Sep 10, 2007
Posts: 58
We were facing the same problem in our company. What we did to resolve this problem was to use the UrlEncoder to encode the cookie value before setting. This will encode all equals signs. And when retrieving the cookie we use UrlDecoder before using the value.

Both UrlEncoder and UrlDecoder can be found in the java.net package.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookie object return incorrect value