You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Yves Glodt <yg...@gmail.com> on 2009/07/13 14:28:21 UTC
Manipulate other session
Hello,
is it possible to "open" a different HttpSession than my "own" (if
it's session-id is known), and set an attribute in that session?
Best regards,
Yves
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Manipulate other session
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Yves,
On 7/14/2009 2:33 PM, Yves Glodt wrote:
> The reason I wanted to manipulate one HttpSession from another is
> since in this case, I have an external entity (and thus in another
> HttpSession) making a POST request to my servlet, posting information
> about a transaction made in another user-HttpSession.
>
> Manipulating the user-HttpSession from the external request would
> have been a way to feed the information from the external entity to
> the user-session which is concerned.
>
> Although I cannot consider this behaviour really beautiful, it's
> also not that ugly...
>
> Or do you (now "you" as "one") disagree or know a nicer way? :-)
I'm not sure I really understand what you're doing. You want to accept a
POST request from a separately-authenticated user and then publish some
data directly into the session of another authenticated user?
I'm afraid I can't understand a use case where that makes sense. What if
the target session doesn't exist? Is the POSTed information lost? Why
not put this kind of information in a database where it can be retrieved
by whomever wants it?
Or, better yet, build a small pub/sub infrastructure where users (or
sessions) register themselves as consumers of POST events. When a POST
event arrives, you simply publish it to the group, and those interested
in hearing the message will get it and then do whatever they want (such
as setting an attribute in the session).
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkpc0ioACgkQ9CaO5/Lv0PDa5wCgwrtUmdNxDkpXPiTNjojAVCUZ
wrAAoJiR+7varN8AM5UqnSHPaDvIEdo1
=nvTd
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Manipulate other session
Posted by Yves Glodt <yg...@gmail.com>.
2009/7/13 Christopher Schultz <ch...@christopherschultz.net>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Daniel,
>
> On 7/13/2009 12:16 PM, Daniel Henrique Alves Lima wrote:
>> I don't know if you can/should change other HttpSession directly.
>
> You might be able to on an older servlet container, but this portion of
> the API has been deprecated and will cause modern containers to throw
> exceptions. I'm not sure if a webapp specifies an old version of the
> spec, whether this API will be supported or not (by a new container
> which will enforce this prohibition on newer webapps).
>
>> As
>> Mikolaj Rydzewski said, you could perform a HTTP request using a
>> different JSESSIONID cookie or a ;jsessionid URL rewriting.
>
> This is possible.
>
> It's also possible to use a SessionListener to maintain your own list of
> sessions and then you can do whatever you want.
>
> The real question is why you want to do this in the first place.
After reading the other replies, I take the "you" for me for this reply ;-)
The reason I wanted to manipulate one HttpSession from another is
since in this case, I have
an external entity (and thus in another HttpSession) making a POST
request to my servlet, posting information about
a transaction made in another user-HttpSession.
Manipulating the user-HttpSession from the external request would have
been a way to feed the information
from the external entity to the user-session which is concerned.
Although I cannot consider this behaviour really beautiful, it's also
not that ugly...
Or do you (now "you" as "one") disagree or know a nicer way? :-)
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkpbaBsACgkQ9CaO5/Lv0PC+RgCfUEoAJwWB+/4jgDCzJgK/4eDb
> YhsAnA8DXWpTkOQdg7vMursGAg5dWfPx
> =g3Tk
> -----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Manipulate other session
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Daniel,
On 7/14/2009 12:14 AM, Daniel Henrique Alves Lima wrote:
> On Mon, 2009-07-13 at 13:00 -0400, Christopher Schultz wrote:
>>> As
>>> Mikolaj Rydzewski said, you could perform a HTTP request using a
>>> different JSESSIONID cookie or a ;jsessionid URL rewriting.
>> This is possible.
>>
>> It's also possible to use a SessionListener to maintain your own list of
>> sessions and then you can do whatever you want.
>>
>> The real question is why you want to do this in the first place.
>
> I don't. It is Yves' question.
Sorry if I was unclear. I meant "the royal you" -- that is:
The real question is why /one/ would want to do this in the first place.
(Not you specifically).
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkpcm+4ACgkQ9CaO5/Lv0PA8LACeKOfLEH7qf4gprUuzArLaO3U6
smcAnjplAMWa9S9JQHGKkTVX6heh1Dyj
=lKFm
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Manipulate other session
Posted by Daniel Henrique Alves Lima <em...@yahoo.com.br>.
On Mon, 2009-07-13 at 13:00 -0400, Christopher Schultz wrote:
>
> > As
> > Mikolaj Rydzewski said, you could perform a HTTP request using a
> > different JSESSIONID cookie or a ;jsessionid URL rewriting.
>
> This is possible.
>
> It's also possible to use a SessionListener to maintain your own list of
> sessions and then you can do whatever you want.
>
> The real question is why you want to do this in the first place.
I don't. It is Yves' question.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Manipulate other session
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Daniel,
On 7/13/2009 12:16 PM, Daniel Henrique Alves Lima wrote:
> I don't know if you can/should change other HttpSession directly.
You might be able to on an older servlet container, but this portion of
the API has been deprecated and will cause modern containers to throw
exceptions. I'm not sure if a webapp specifies an old version of the
spec, whether this API will be supported or not (by a new container
which will enforce this prohibition on newer webapps).
> As
> Mikolaj Rydzewski said, you could perform a HTTP request using a
> different JSESSIONID cookie or a ;jsessionid URL rewriting.
This is possible.
It's also possible to use a SessionListener to maintain your own list of
sessions and then you can do whatever you want.
The real question is why you want to do this in the first place.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkpbaBsACgkQ9CaO5/Lv0PC+RgCfUEoAJwWB+/4jgDCzJgK/4eDb
YhsAnA8DXWpTkOQdg7vMursGAg5dWfPx
=g3Tk
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Manipulate other session
Posted by Daniel Henrique Alves Lima <em...@yahoo.com.br>.
I don't know if you can/should change other HttpSession directly. As
Mikolaj Rydzewski said, you could perform a HTTP request using a
different JSESSIONID cookie or a ;jsessionid URL rewriting.
On Mon, 2009-07-13 at 16:33 +0200, Yves Glodt wrote:
> Unfortunately what the blog above describes does not seem to work anymore...:
>
> HttpSessionContext sc = request.getSession().getSessionContext();
> HttpSession userSession = sc.getSession(sessionId);
> userSession.setAttribute("myObject", cr);
>
> It silently fails with an exception at the last line, an exception
> without a message...
>
> 2009/7/13 Yves Glodt <yg...@gmail.com>:
> > Thanks for telling. I found another way (deprecated) in the mean time:
> >
> > http://javasolution.blogspot.com/2007/08/getting-session-object-using-session-id.html
> >
> > 2009/7/13 Mikolaj Rydzewski <mi...@ceti.pl>:
> >> Yves Glodt wrote:
> >>>
> >>> is it possible to "open" a different HttpSession than my "own" (if
> >>> it's session-id is known), and set an attribute in that session?
> >>>
> >>
> >> You can perform HTTP request with session cookie explicity set.
> >>
> >> --
> >> Mikolaj Rydzewski <mi...@ceti.pl>
> >>
> >>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Manipulate other session
Posted by Yves Glodt <yg...@gmail.com>.
Unfortunately what the blog above describes does not seem to work anymore...:
HttpSessionContext sc = request.getSession().getSessionContext();
HttpSession userSession = sc.getSession(sessionId);
userSession.setAttribute("myObject", cr);
It silently fails with an exception at the last line, an exception
without a message...
2009/7/13 Yves Glodt <yg...@gmail.com>:
> Thanks for telling. I found another way (deprecated) in the mean time:
>
> http://javasolution.blogspot.com/2007/08/getting-session-object-using-session-id.html
>
> 2009/7/13 Mikolaj Rydzewski <mi...@ceti.pl>:
>> Yves Glodt wrote:
>>>
>>> is it possible to "open" a different HttpSession than my "own" (if
>>> it's session-id is known), and set an attribute in that session?
>>>
>>
>> You can perform HTTP request with session cookie explicity set.
>>
>> --
>> Mikolaj Rydzewski <mi...@ceti.pl>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Manipulate other session
Posted by Yves Glodt <yg...@gmail.com>.
Thanks for telling. I found another way (deprecated) in the mean time:
http://javasolution.blogspot.com/2007/08/getting-session-object-using-session-id.html
2009/7/13 Mikolaj Rydzewski <mi...@ceti.pl>:
> Yves Glodt wrote:
>>
>> is it possible to "open" a different HttpSession than my "own" (if
>> it's session-id is known), and set an attribute in that session?
>>
>
> You can perform HTTP request with session cookie explicity set.
>
> --
> Mikolaj Rydzewski <mi...@ceti.pl>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Manipulate other session
Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
Yves Glodt wrote:
> is it possible to "open" a different HttpSession than my "own" (if
> it's session-id is known), and set an attribute in that session?
>
You can perform HTTP request with session cookie explicity set.
--
Mikolaj Rydzewski <mi...@ceti.pl>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org