Bug 16474 - Unable to obtain correct data for version, path, or domain information from Cookie
Summary: Unable to obtain correct data for version, path, or domain information from C...
Status: RESOLVED WORKSFORME
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Connector:Coyote (show other bugs)
Version: Nightly Build
Hardware: All All
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-01-27 21:04 UTC by Ryan Lubke
Modified: 2006-11-16 18:49 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Lubke 2003-01-27 21:04:44 UTC
Using a simple client that sends a cookie per RFC 2109:

Cookie: $Version=1; CookieName=CookieValue; $Path=/; $Domain=.test.com

On the server side, HttpServletRequest.getCookies() returns an array of Cookies
with 1 element.  Cookie.getName() and Cookie.getValue() both return the expected
values, bug Cookie.getVersion() returns 0, and Cookie.getDomain() and
Cookie.getPath() returns null.
Comment 1 Jean-Francois Arcand 2003-02-26 19:37:14 UTC
Fixed.

Thanks,

-- Jeanfrancois
Comment 2 Steffen Spahr 2006-11-15 05:19:26 UTC
Hi,

I am using Apache Tomcat/5.5.17.

With this version I got the same result as described in the bug-report.

Is it realy fixed?

The Cookie.getPath() and Cookie.getDomain() returns always 'null'.


My example program:

package test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CookieAnzeige extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// Returns a writer to write to the browser
		PrintWriter out = response.getWriter();

		// Writes the string to the browser.
		out.println("Anzeige und Setzen von Cookies:");

		Cookie[] cookies = request.getCookies();
		if (cookies == null)
			out.println("Kein Cookie gesetzt!");
		else {
			for (int i = 0; i < cookies.length; i++) {
				String cookieName = cookies[i].getName();
				out.println("Cookie " + cookieName + " hat den Wert "
						+ cookies[i].getValue() + " Pfad: "
						+ cookies[i].getPath() + " Domain: "
						+ cookies[i].getDomain());
			}
		}

		Cookie Versicherungsnehmer = new Cookie("Versicherungsnehmer", "123456");
		Versicherungsnehmer.setPath("/");
		response.addCookie(Versicherungsnehmer);

		out.close();
	}
}


The result:

Anzeige und Setzen von Cookies:

Cookie JSESSIONID hat den Wert A08AE263E7D9854C649BEA65CDE5056A Pfad: null
Domain: null

Cookie Versicherungsnehmer hat den Wert 123456 Pfad: null Domain: null 
Comment 3 Mark Thomas 2006-11-16 18:49:04 UTC
I have repeated the test described by the OP using telnet and the cookie is
correctly parsed. I suspect your client is not sending what you think it is. The
Tomcat users list is the right place to get help with this.