You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by jerrySheen <pr...@yahoo.co.in> on 2009/04/13 12:30:59 UTC

retrieve session data stored in db using JDBCStore.

Hi,
I have been successful in saving the sessions to my mysql db, using the
given code in my server configuration file.

<Store className="org.apache.catalina.session.JDBCStore" 
          
connectionURL="jdbc:mysql://XXXXXXXXX/xxxxxx?user=zzzzz&amp;password=zzzzzz"
	   driverName="com.mysql.jdbc.Driver"
	   sessionIdCol="id"
	   sessionValidCol="valid"
	   sessionMaxInactiveCol="maxinactive"
	   sessionLastAccessedCol="lastaccess"
	   sessionTable = "app_sessions"
	   sessionAppCol = "context"
	   sessionDataCol = "data"
	/>
this stores the session data as a blob in the db. So my questions are, 

Can we assign the blob data directly to a new session, so that this new
session assumes the state of the session in the db?
Can we retrieve and edit information from the blob?

if YES, please furnish some sample code or at least direct me towards the
solutions.
if NO, what other ways can we go about, to achieve session persistence(not
just validation as in cookies but a complete session state snapshot).
-- 
View this message in context: http://www.nabble.com/retrieve-session-data-stored-in-db-using-JDBCStore.-tp23020556p23020556.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: retrieve session data stored in db using JDBCStore.

Posted by jerrySheen <pr...@yahoo.co.in>.
can someone please reply to the above post.:-((

-- 
View this message in context: http://www.nabble.com/retrieve-session-data-stored-in-db-using-JDBCStore.-tp23020556p23052044.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: retrieve session data stored in db using JDBCStore.

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jerry,

On 4/15/2009 11:58 PM, jerrySheen wrote:
> So u mean to say, that if I were to prolong the JSESSIONID cookie's expiry
> time, the server would take care of repopulating the session state(stored in
> the db) even after a browser restart?
> 
> Well, this seems like a much simpler solution,ill give it a try, hope it
> works.

You have to modify the cookie that Tomcat creates. By default, the
cookie has a max age of -1, which means "forget me when the browser
closes". Note that this is different than the "maxInactiveInterval" for
the session itself, which is the expiration date for the /session/ (no
the cookie).

You'll have to write a filter or something like that to modify the
cookie sent to the browser. You want to grab the appropriate cookie and
change the max age to something else. You probably want to make it
something like "tomorrow" (relative to today, of course) so that the
cookie is persisted across browser restarts. Note that an expired
session on the server side is non-recoverable.

Good luck. Post back if you develop a decent solution.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAknooOEACgkQ9CaO5/Lv0PDVIQCeL/EVSixGDiz02Orzk4LuxLKa
K08AoKqmrENfD1zsh17+3eWgLkClQhhT
=RG+p
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: retrieve session data stored in db using JDBCStore.

Posted by jerrySheen <pr...@yahoo.co.in>.
So u mean to say, that if I were to prolong the JSESSIONID cookie's expiry
time, the server would take care of repopulating the session state(stored in
the db) even after a browser restart?

Well, this seems like a much simpler solution,ill give it a try, hope it
works.

Thanks,
JS

-- 
View this message in context: http://www.nabble.com/retrieve-session-data-stored-in-db-using-JDBCStore.-tp23020556p23071047.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: retrieve session data stored in db using JDBCStore.

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jerry,

On 4/13/2009 11:15 PM, jerrySheen wrote:
> As we are dealing with sessions that are no [longer accessible], this action
> would have no effect on any live sessions thus no inconsistencies.
> 
>> if YES, please furnish some sample code or at least direct me towards the
>> solutions.

You could certainly look at the code for the
org.apache.catalina.session.JDBCStore class.

>> Isn't [something already] happening now?
>
> Yes but only at server restarts.

Server restarts or browser restarts?

> what i am trying to implement here is session persistence across browser
> restarts. ie. I would like to maintain the session state even if the browser
> is closed and restarted at which point a new session is started. 

I think you want to change the cookie behavior, not go mucking-around
with the session itself. All you really need is the browser to remember
the JSESSIONID cookie across a browser restart.

> now i would like to persist the old session by maintaining the session id
> inside a cookie, and compare this id against the session id stored in
> 'sessionIdCol="id" ', then copy the session data stored as blob in
> '''sessionDataCol = "data" ' and assign this data to the new session.

This seems like more work than necessary. Why not "fix" the JSESSIONID
cookie?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAknmkxUACgkQ9CaO5/Lv0PCu/ACffl4CPLTEISX8Ri4IAMmVOt61
DlIAn2zwanuZYdBxJjQ85nCeum5f555K
=l8Ey
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: retrieve session data stored in db using JDBCStore.

Posted by jerrySheen <pr...@yahoo.co.in>.
Why?
The risk is that you will introduce inconsistencies into live sessions.
Surely modifying the session using the API provided by the Servlet spec
is a) safer and b) easier.
As we are dealing with sessions that are no more accessable, this action
would have no effect on any live sessions thus no inconsistencies.

> if YES, please furnish some sample code or at least direct me towards the
> solutions.
> if NO, what other ways can we go about, to achieve session persistence(not
> just validation as in cookies but a complete session state snapshot).
Isn't that happening now?
Yes but only at server restarts.

> Can we assign the blob data directly to a new session, so that this new
> session assumes the state of the session in the db?
Why?
The session manager should be doing this for you.
Again this happens only at server restarts.

tomcat version = 5.5.20, 
jvm version = 1.6.0, 
os version = windows xp sp2.

Ok.
what i am trying to implement here is session persistence across browser
restarts. ie. I would like to maintain the session state even if the browser
is closed and restarted at which point a new session is started. 
we know that the session exists in the db for the time that is specified in
'sessionMaxInactiveCol="maxinactive" ' so, even if the browser is closed and
the session is destroyed at browser level it still exists in the db. (we can
prolong session expiry using: session.setMaxInactiveInterval(2 weeks);) 
now i would like to persist the old session by maintaining the session id
inside a cookie, and compare this id against the session id stored in
'sessionIdCol="id" ', then copy the session data stored as blob in
'''sessionDataCol = "data" ' and assign this data to the new session. 
thus i would be able to regain the last session state in which the browser
was closed. once the transaction is complete i would remove the old session
from the db.

Is this possible, if yes how?
-- 
View this message in context: http://www.nabble.com/retrieve-session-data-stored-in-db-using-JDBCStore.-tp23020556p23032552.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: retrieve session data stored in db using JDBCStore.

Posted by Pid <p...@pidster.com>.
jerrySheen wrote:
> Hi,
> I have been successful in saving the sessions to my mysql db, using the
> given code in my server configuration file.
> 
> <Store className="org.apache.catalina.session.JDBCStore" 
>           
> connectionURL="jdbc:mysql://XXXXXXXXX/xxxxxx?user=zzzzz&amp;password=zzzzzz"
> 	   driverName="com.mysql.jdbc.Driver"
> 	   sessionIdCol="id"
> 	   sessionValidCol="valid"
> 	   sessionMaxInactiveCol="maxinactive"
> 	   sessionLastAccessedCol="lastaccess"
> 	   sessionTable = "app_sessions"
> 	   sessionAppCol = "context"
> 	   sessionDataCol = "data"
> 	/>
> this stores the session data as a blob in the db. So my questions are, 
> 
> Can we assign the blob data directly to a new session, so that this new
> session assumes the state of the session in the db?

Why?
The session manager should be doing this for you.

> Can we retrieve and edit information from the blob?

Why?
The risk is that you will introduce inconsistencies into live sessions.
Surely modifying the session using the API provided by the Servlet spec
is a) safer and b) easier.

> if YES, please furnish some sample code or at least direct me towards the
> solutions.
> if NO, what other ways can we go about, to achieve session persistence(not
> just validation as in cookies but a complete session state snapshot).

Isn't that happening now?

p



p.s. tomcat version, jvm version, os version?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org