• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cookie object return incorrect value

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

>
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Karup Mew
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I have used base64 and its working in other servlet container .Is this servlet container version problem ?
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which servlet container is creating problems??
 
Karup Mew
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both are Tomcat5.5 but the size of servletapi.jar is different
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ...
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's take a step back: why base64?
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am facing the same problem.

Has anyone found a solution to this?
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic