You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Felipe Jaekel <fk...@gmail.com> on 2012/10/18 15:34:26 UTC
Get active session list
I need to get the active session list. Searching about I saw a lot of
people with the same question, but no answer.
I don't want to write a list inside a HttpSessionListener and keep the
session list there, because I use session serialization and the list inside
the listener would be destroyed in case the server is restarted.
I'd like know which class does the Manager Application uses to get the
session list, so I can use it in my application too.
Thanks a lot,
Phillip
Re: Get active session list
Posted by Mark Thomas <ma...@apache.org>.
On 18/10/2012 14:34, Felipe Jaekel wrote:
> I need to get the active session list. Searching about I saw a lot of
> people with the same question, but no answer.
>
> I don't want to write a list inside a HttpSessionListener and keep the
> session list there, because I use session serialization and the list inside
> the listener would be destroyed in case the server is restarted.
>
> I'd like know which class does the Manager Application uses to get the
> session list, so I can use it in my application too.
Have you looked at the Tomcat source code?
The short answer is from an implementation of the Manager interface but
that won't really help you as you need to get a reference to the correct
Manager instance. How to do that should be apparent from the
ManagerServlet source code but feel free to ask here if you need some
pointers.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get active session list
Posted by Jose María Zaragoza <de...@gmail.com>.
2012/10/18 Felipe Jaekel <fk...@gmail.com>:
> I need to get the active session list. Searching abou I saw a lot of
> people with the same question, but no answer.
https://code.google.com/p/psi-probe/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get active session list
Posted by Mark Thomas <ma...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 19/10/2012 19:17, Felipe Jaekel wrote:
> Anyone?
Again, look at the source code to see how the Tomcat Manager servlet
does it.
Mark
>
> 2012/10/18 Felipe Jaekel <fk...@gmail.com>
>
>> Found the following:
>>
>> context = (Context) wrapper.getParent();
>>> host = (Host) context.getParent();
>>>
>>
>>
>>> Context ctx = (Context) host.findChild(name); Manager manager =
>>> ctx.getManager(); Session [] sessions =
>>> manager.findSessions();
>>
>>
>> Had the same doubt I had when I looked at the PSI Probe code some
>> days ago: how to handle the wrapper property?
>>
>>
>> As a alternative I tried to implement
>> *HttpSessionActivationListener*, but the methods aren't called
>> when I restart the server.
>>
>> Thanks again for the help, Phillip
>>
>>
>> 2012/10/18 Christopher Schultz <ch...@christopherschultz.net>
>>
> Felipe,
>
> On 10/18/12 9:34 AM, Felipe Jaekel wrote:
>>>>> I need to get the active session list. Searching about I
>>>>> saw a lot of people with the same question, but no answer.
>>>>>
>>>>> I don't want to write a list inside a HttpSessionListener
>>>>> and keep the session list there, because I use session
>>>>> serialization and the list inside the listener would be
>>>>> destroyed in case the server is restarted.
>
> You *can* get notification of sessions being de-serialized from
> the disk to maintain your list. Look at the other session-related
> listeners in the servlet API.
>
> You could also use JMX to get a list of sessions. Use JConsole to
> poke-around in Tomcat's JMX beans and find the one(s) that expose
> sessions. You may have to make your webapp "privileged" in order
> to make JMX calls.
>
> -chris
>>>
>>> ---------------------------------------------------------------------
>>>
>>>
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
iQIcBAEBAgAGBQJQgaamAAoJEBDAHFovYFnnXC8P/2YMIuVEYDOs2xWtzA8brB2X
WAMoqu8eP3qVCxRxmilImnnmCSum7jV0yXEhwDaYfC71hPni7LLDNU69oEnfg19d
gR43m84v1VENIpZimlij6ZPZBpV5P+0VlyVgfoOm5sVppsERXKvn/B1XUCzyD7YR
mAbbrwbRa+c1NiMfFf0XMHrb9+BoYfQ1aUDJ3BaK/vzplCrzBgDSygBYPOozwva+
GlHn76MkAE86ojeYvmJN0yIF9ahuwfNXm/NK5wdOKf78BD23NrRW23j+Y80xz15N
mHI/8F1kX6A8bVdaUeJzEsvpZodKP3AhkqX5bhKh1E4HmKuoYU0s5dqDqTnbyuJA
eN/BFQDBPYK7R4p4VJkADu3yCORRkkpp8l//TwYZO9ylddNZpd7eSDkmX7qlC8DJ
Usa77xCV5g1nZvrAuJYWYtfFWqMtXtTBfQMw809170Ugh821ruPvTi23YFZSYYFL
LkZBBbKkatnjeU/jE7QXmWwQrEop6ZF8rGZjlSMFYAsLRR75+qdf9A5+wl/HKfKh
3eLZT5frkOmqhWrmb35aMA4sxUlJAhc+UhudbHjp3twUX2U1ki59QW/EMOJAtsvr
G3FFY0/Ui1dxmuzeA+tzB1Eiypq6RU+34ZTjZ9XjHqKfV/ydNwczhc3fSYk4l4N7
FH5cLf3tldLqP35Wj7mg
=h6w0
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get active session list
Posted by Felipe Jaekel <fk...@gmail.com>.
Anyone?
2012/10/18 Felipe Jaekel <fk...@gmail.com>
> Found the following:
>
> context = (Context) wrapper.getParent();
>> host = (Host) context.getParent();
>>
>
>
>> Context ctx = (Context) host.findChild(name);
>> Manager manager = ctx.getManager();
>> Session [] sessions = manager.findSessions();
>
>
> Had the same doubt I had when I looked at the PSI Probe code some days
> ago: how to handle the wrapper property?
>
>
> As a alternative I tried to implement *HttpSessionActivationListener*,
> but the methods aren't called when I restart the server.
>
> Thanks again for the help,
> Phillip
>
>
> 2012/10/18 Christopher Schultz <ch...@christopherschultz.net>
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Felipe,
>>
>> On 10/18/12 9:34 AM, Felipe Jaekel wrote:
>> > I need to get the active session list. Searching about I saw a lot
>> > of people with the same question, but no answer.
>> >
>> > I don't want to write a list inside a HttpSessionListener and keep
>> > the session list there, because I use session serialization and the
>> > list inside the listener would be destroyed in case the server is
>> > restarted.
>>
>> You *can* get notification of sessions being de-serialized from the
>> disk to maintain your list. Look at the other session-related
>> listeners in the servlet API.
>>
>> You could also use JMX to get a list of sessions. Use JConsole to
>> poke-around in Tomcat's JMX beans and find the one(s) that expose
>> sessions. You may have to make your webapp "privileged" in order to
>> make JMX calls.
>>
>> - -chris
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
>> Comment: GPGTools - http://gpgtools.org
>> Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
>>
>> iEYEARECAAYFAlCAEgwACgkQ9CaO5/Lv0PARBACfZ+EG7KJWXt+49sbB1kVsLunF
>> A4MAoKv1hM4KBlaAS4a1UaP0ePqfRr3W
>> =n3WU
>> -----END PGP SIGNATURE-----
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
Re: Get active session list
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Raul,
On 11/20/12 11:02 AM, Cosio, Raul wrote:
> As far as I know there is no way to get the list of active
> sessions for security reasons
You can also use JMX to get a list of sessions.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with undefined - http://www.enigmail.net/
iEYEARECAAYFAlCr+9sACgkQ9CaO5/Lv0PCgMgCfdycQlWtur1RBFzXEMiuGxf+H
7DUAnigezADr+Ee5hnxSRTifEjTr+IjS
=CES6
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get active session list
Posted by Jose María Zaragoza <de...@gmail.com>.
Sorry, I'm not following this thread but
Don't you want to use
http://localhost:8080/manager/html/sessions?path=/<contextpath>
?
You only have to parse this plain HTML webpage
I know that it's not very elegant but ....
Regards
2012/11/20 Cosio, Raul <jo...@merck.com>:
> As far as I know there is no way to get the list of active sessions for security reasons, some time ago I wanted to display in my application a list of active sessions, what I did is to implement some listeners, it is tricky but fun once you understand how it works.
>
> The first listener I implemented was an HttpSessionListener (declared in my web.xml file), the listener has a method sessionCreated() and sessionDestroyed() that I used to update my list of active sessions.
>
> The tricky part is when the server is restarted, because tomcat serializes the sessions and after a restart there will be active sessions that are created without a sessionCreated() event (which makes sense because they were not destroyed, just serialized). I handle this situation with a SessionActivationListener interface that has a method sessionDidActivate(), usefult to update my list of active sessions.
>
> The SessionActivationListener is used for any attribute that you add to a session with the setAttribute() method. To make this listener available I just added an object that implements the listener in the HttpSessionListener.sessionCreated() method.
>
> Regards
>
> -----Original Message-----
> From: Felipe Jaekel [mailto:fkjaekel@gmail.com]
> Sent: Thursday, October 18, 2012 3:59 PM
> To: Tomcat Users List
> Subject: Re: Get active session list
>
> Found the following:
>
> context = (Context) wrapper.getParent();
>> host = (Host) context.getParent();
>>
>
>
>> Context ctx = (Context) host.findChild(name);
>> Manager manager = ctx.getManager();
>> Session [] sessions = manager.findSessions();
>
>
> Had the same doubt I had when I looked at the PSI Probe code some days ago:
> how to handle the wrapper property?
>
>
> As a alternative I tried to implement *HttpSessionActivationListener*, but
> the methods aren't called when I restart the server.
>
> Thanks again for the help,
> Phillip
>
>
> 2012/10/18 Christopher Schultz <ch...@christopherschultz.net>
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Felipe,
>>
>> On 10/18/12 9:34 AM, Felipe Jaekel wrote:
>> > I need to get the active session list. Searching about I saw a lot
>> > of people with the same question, but no answer.
>> >
>> > I don't want to write a list inside a HttpSessionListener and keep
>> > the session list there, because I use session serialization and the
>> > list inside the listener would be destroyed in case the server is
>> > restarted.
>>
>> You *can* get notification of sessions being de-serialized from the
>> disk to maintain your list. Look at the other session-related
>> listeners in the servlet API.
>>
>> You could also use JMX to get a list of sessions. Use JConsole to
>> poke-around in Tomcat's JMX beans and find the one(s) that expose
>> sessions. You may have to make your webapp "privileged" in order to
>> make JMX calls.
>>
>> - -chris
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
>> Comment: GPGTools - http://gpgtools.org
>> Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
>>
>> iEYEARECAAYFAlCAEgwACgkQ9CaO5/Lv0PARBACfZ+EG7KJWXt+49sbB1kVsLunF
>> A4MAoKv1hM4KBlaAS4a1UaP0ePqfRr3W
>> =n3WU
>> -----END PGP SIGNATURE-----
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> Notice: This e-mail message, together with any attachments, contains
> information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
> New Jersey, USA 08889), and/or its affiliates Direct contact information
> for affiliates is available at
> http://www.merck.com/contact/contacts.html) that may be confidential,
> proprietary copyrighted and/or legally privileged. It is intended solely
> for the use of the individual or entity named on this message. If you are
> not the intended recipient, and have received this message in error,
> please notify us immediately by reply e-mail and then delete it from
> your system.
>
>
> ---------------------------------------------------------------------
> 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: Get active session list
Posted by "Cosio, Raul" <jo...@merck.com>.
As far as I know there is no way to get the list of active sessions for security reasons, some time ago I wanted to display in my application a list of active sessions, what I did is to implement some listeners, it is tricky but fun once you understand how it works.
The first listener I implemented was an HttpSessionListener (declared in my web.xml file), the listener has a method sessionCreated() and sessionDestroyed() that I used to update my list of active sessions.
The tricky part is when the server is restarted, because tomcat serializes the sessions and after a restart there will be active sessions that are created without a sessionCreated() event (which makes sense because they were not destroyed, just serialized). I handle this situation with a SessionActivationListener interface that has a method sessionDidActivate(), usefult to update my list of active sessions.
The SessionActivationListener is used for any attribute that you add to a session with the setAttribute() method. To make this listener available I just added an object that implements the listener in the HttpSessionListener.sessionCreated() method.
Regards
-----Original Message-----
From: Felipe Jaekel [mailto:fkjaekel@gmail.com]
Sent: Thursday, October 18, 2012 3:59 PM
To: Tomcat Users List
Subject: Re: Get active session list
Found the following:
context = (Context) wrapper.getParent();
> host = (Host) context.getParent();
>
> Context ctx = (Context) host.findChild(name);
> Manager manager = ctx.getManager();
> Session [] sessions = manager.findSessions();
Had the same doubt I had when I looked at the PSI Probe code some days ago:
how to handle the wrapper property?
As a alternative I tried to implement *HttpSessionActivationListener*, but
the methods aren't called when I restart the server.
Thanks again for the help,
Phillip
2012/10/18 Christopher Schultz <ch...@christopherschultz.net>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Felipe,
>
> On 10/18/12 9:34 AM, Felipe Jaekel wrote:
> > I need to get the active session list. Searching about I saw a lot
> > of people with the same question, but no answer.
> >
> > I don't want to write a list inside a HttpSessionListener and keep
> > the session list there, because I use session serialization and the
> > list inside the listener would be destroyed in case the server is
> > restarted.
>
> You *can* get notification of sessions being de-serialized from the
> disk to maintain your list. Look at the other session-related
> listeners in the servlet API.
>
> You could also use JMX to get a list of sessions. Use JConsole to
> poke-around in Tomcat's JMX beans and find the one(s) that expose
> sessions. You may have to make your webapp "privileged" in order to
> make JMX calls.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
>
> iEYEARECAAYFAlCAEgwACgkQ9CaO5/Lv0PARBACfZ+EG7KJWXt+49sbB1kVsLunF
> A4MAoKv1hM4KBlaAS4a1UaP0ePqfRr3W
> =n3WU
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Notice: This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates Direct contact information
for affiliates is available at
http://www.merck.com/contact/contacts.html) that may be confidential,
proprietary copyrighted and/or legally privileged. It is intended solely
for the use of the individual or entity named on this message. If you are
not the intended recipient, and have received this message in error,
please notify us immediately by reply e-mail and then delete it from
your system.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get active session list
Posted by Felipe Jaekel <fk...@gmail.com>.
Found the following:
context = (Context) wrapper.getParent();
> host = (Host) context.getParent();
>
> Context ctx = (Context) host.findChild(name);
> Manager manager = ctx.getManager();
> Session [] sessions = manager.findSessions();
Had the same doubt I had when I looked at the PSI Probe code some days ago:
how to handle the wrapper property?
As a alternative I tried to implement *HttpSessionActivationListener*, but
the methods aren't called when I restart the server.
Thanks again for the help,
Phillip
2012/10/18 Christopher Schultz <ch...@christopherschultz.net>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Felipe,
>
> On 10/18/12 9:34 AM, Felipe Jaekel wrote:
> > I need to get the active session list. Searching about I saw a lot
> > of people with the same question, but no answer.
> >
> > I don't want to write a list inside a HttpSessionListener and keep
> > the session list there, because I use session serialization and the
> > list inside the listener would be destroyed in case the server is
> > restarted.
>
> You *can* get notification of sessions being de-serialized from the
> disk to maintain your list. Look at the other session-related
> listeners in the servlet API.
>
> You could also use JMX to get a list of sessions. Use JConsole to
> poke-around in Tomcat's JMX beans and find the one(s) that expose
> sessions. You may have to make your webapp "privileged" in order to
> make JMX calls.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
>
> iEYEARECAAYFAlCAEgwACgkQ9CaO5/Lv0PARBACfZ+EG7KJWXt+49sbB1kVsLunF
> A4MAoKv1hM4KBlaAS4a1UaP0ePqfRr3W
> =n3WU
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Get active session list
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Felipe,
On 10/18/12 9:34 AM, Felipe Jaekel wrote:
> I need to get the active session list. Searching about I saw a lot
> of people with the same question, but no answer.
>
> I don't want to write a list inside a HttpSessionListener and keep
> the session list there, because I use session serialization and the
> list inside the listener would be destroyed in case the server is
> restarted.
You *can* get notification of sessions being de-serialized from the
disk to maintain your list. Look at the other session-related
listeners in the servlet API.
You could also use JMX to get a list of sessions. Use JConsole to
poke-around in Tomcat's JMX beans and find the one(s) that expose
sessions. You may have to make your webapp "privileged" in order to
make JMX calls.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
iEYEARECAAYFAlCAEgwACgkQ9CaO5/Lv0PARBACfZ+EG7KJWXt+49sbB1kVsLunF
A4MAoKv1hM4KBlaAS4a1UaP0ePqfRr3W
=n3WU
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org