I'm having a heck of a time trying to set a cookie. This is the code I have so
far:
In the first part attempts to read any cookies that I put there before, this
always comes up blank.
The second part tries to add a new cookie to the response. Theres a few places
that I could have gone wrong:
1) I didn't know how to instantiate a new Series<CookieSetting>, so I grabbed
the existing one and modified it by by calling 'this.getCookieSettings()'.
2) I added the cookie by calling 'this.setCookieSettings()'
3) I'm doing this through 'POST'
When I check the response headers 'Set-Cookie' doesn't appear to be there at
all.
public class TestCookieResource extends ServerResource {
@Post
public Representation post(Representation representation){
// READ COOKIES FROM CLIENT
Series<Cookie> cookies = this.getRequest().getCookies();
int cookieNum = cookies.size();
String values = "";
for( Cookie cookie : cookies){
values += cookie.getValue() + "\n";
}
// SET NEW COOKIE
CookieSetting cS = new CookieSetting(0, "cookieName",
"cookieValue");
Series<CookieSetting> cookieSettings = this.getCookieSettings();
cookieSettings.clear();
cookieSettings.add(cS);
this.setCookieSettings(cookieSettings);
// SEND RESPONSE
this.setStatus(Status.SUCCESS_OK);
StringRepresentation sR = new StringRepresentation("test
response");
return sR;
}
}
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2673142