Hello all,
[EMAIL PROTECTED] and I have answered my own question, and I thought I'd 
share what I learned just in case somebody else runs into the same problem:

There is nothing fundamentally different from adding a cookie to the 
response during an action, than adding a cookie to a response during a 
screen. My problem occured due to the path attribute of the cookie.

When a cookie is added to a response, by default, it's path attribute will 
be set to the URL relative to the root directory.

1 (the action) -- For example, if I request 
http://localhost:8080/appname/servlet/appname/template/index.vm/action/LoginUser 
and my response instantiates a new cookie, the Path attribute of that cookie 
will be "/appname/servlet/appname/template/index.vm/action" by default.

2 (the screen) -- On the other hand, when I coded my default template's 
class to add the cookie (from my previous message listed below), the URL I 
requested was http://localhost:8080/appname/servlet/appname/ and the new 
cookie that was sent back had a Path attribute of 
"/appname/servlet/appname/".

This makes a big diference when the browser decides which cookies to send to 
the browser. The browser decides which cookies to return based on the server 
requesting them, and the path that the user requested.

Based on this, you can see why my cookie code that I put into the action did 
not work for me. I suppose it would have worked if 
"/appname/servlet/appname/template/index.vm/action" was a prefix to the URL 
I was requesting, but that would rarely happen.

You can also see why the cookie code I put in my default template's class 
did work. "/appname/servlet/appname/" is a prefix in all requests that I 
make of my Turbine application.

The lesson I learned during this is to set the path on my cookies to 
something that will be a prefix in all my applications request. I'd be happy 
to answer any questions others may have about this phenomenon.

-Kevin

>From: "Kevin Clark" <[EMAIL PROTECTED]>
>Reply-To: "Turbine" <[EMAIL PROTECTED]>

>I've been working on some code to automate login; however, I still haven't
>gotten it to work the way I want. My problem seems to be related to adding 
>a
>persistent cookie (one that will last through multiple sessions) during the
>execution of an action.
>
>I've put the cookie check (check to see if the user has a cookie set for
>auto-login) in SessionValidator. In my case, I modified a copy of
>TemplateSessionValidator that I put in my package classpath. Witin the
>conditional "if (data.getUser == null)" block, I get all the cookies and
>check to see if one of them is an auto-login cookie. If so, put he
>username/password in the RunData's parameter list, and:
>
>ActionLoader.getInstance().exec(data,
>TurbineResources.getString("action.login"));
>
>Then, if the User object within the RunData is not logged in, set the user
>to the anonymous user (this is in case the cookie didn't sucessfully log 
>the
>user in). Also, if no cookies for auto-login where found, again set the
>anonymous user.
>
>Anyway, this seems to work okay. I did some testing by adding a cookie with
>a correct username/password for a value and a MaxAge of (60*60*24*365) in
>the default template, so the cookie would be set immediately upon accessing
>the site. Then I hit the site and closed my browser and hit the site again
>(this time the cookie was set...) and I was already logged in. This all
>seems great so far.
>
>To continue the test, I change the code I used to set the cookie so set the
>MaxAge to (0). Again, I hit the site, and the new cookie was set (which
>basically deleted the previous cookie) and I closed the browser again. Upon
>opening it once more, I was logged out. Again, everything seems great...
>
>My next step was to lose the cookie in the default template, and put the
>code in the LoginUser action where I had planned for it to go. I added a
>"remember me" checkbox to the login form. Then, I literatally cut & pasted
>my cookie code from the default template to the LoginUser action and put it
>within a conditional check to see if the user checked the "remember me"
>checkbox, and set the MaxAge back to (60*60*24*365).
>
>I figured this would be the easy part. The only time a cookie would be set
>is when a user logs in with the "remember me" checkbox checked. I used
>navigator and set it to warn me about cookies, then I hit the site. When I
>hit the site, I saw the session cookie warning first (name=JSESSIONID) and
>let it set the cookie. Then I navigated the site for a bit and tried to
>login. Sure enough, it gave me a warning with the correct name/value/maxage
>and I let it set. Unfortunately, after closing the browser and hitting the
>site again, I wasn't logged in. I put plently of debug code in and realized
>that the server was not seeing a cookie when the browser revisited the 
>site.
>
>I decided to put the cookie code back into default template's class and try
>again, everything worked fine...
>
>So it seems that the only difference between my code working and not 
>working
>is whether the code is executed during an action or a screen. When the
>cookie set code is executed during an action, it only seems to persist 
>until
>the next request, yet when it is executed during a screen, it lasts until
>the MaxAge (like I was hoping...). Can anyone tell me what is going on? or
>how to fix this? I'd be happy to provide any other information necessary...

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to