You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Francisco J. Bido" <bi...@mac.com> on 2003/04/21 18:41:13 UTC

Inspecting HttpSession (circular trap)

I'm creating a session inspector utility but I've come across a bump on 
the road.  The HttpSession API does not provide a method that
allows me to get the class name for an object contained in the session. 
  I can certainly retrieve the instance names (which are of type String)
but that doesn't help much.  What would help, is the name of the class 
that created the instance.  Any ideas?

On a typical application, this is not an issue since one knows the 
types of all objects in the session (and that's why we know how to 
cast).   But the utility that I'm working is supposed to inspect the 
session and discover the types.   Do you just loose all class info 
(metadata) once objects are inserted into the HttpSession?    From what 
I've seen the reflection API requires you to know the class name in 
order to get metadata.  This sends me back to step one (circular trap) 
since it's the class name that I need.   Any ideas on how to do this, 
where to look etc.?

Thanks!


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


Re: Inspecting HttpSession (circular trap)

Posted by "Francisco J. Bido" <bi...@mac.com>.
Thanks!  Now it's all good.

-FB

On Monday, April 21, 2003, at 11:45  AM, Tim Funk wrote:

> You'll need to iterate throught the session objects. (by name)
> Then via reflection you can determine the class name of each session 
> object.
>
> You can determine className via:
>
> String myClassName = myObject.getClass().getName()
>
> if ("java.lang.String".equals(myClassName)) {
>  ...
> } else if (...) {
>  ...
> }
>
> -Tim
>
>
> Francisco J. Bido wrote:
>> I'm creating a session inspector utility but I've come across a bump 
>> on the road.  The HttpSession API does not provide a method that
>> allows me to get the class name for an object contained in the 
>> session.  I can certainly retrieve the instance names (which are of 
>> type String)
>> but that doesn't help much.  What would help, is the name of the 
>> class that created the instance.  Any ideas?
>> On a typical application, this is not an issue since one knows the 
>> types of all objects in the session (and that's why we know how to 
>> cast).   But the utility that I'm working is supposed to inspect the 
>> session and discover the types.   Do you just loose all class info 
>> (metadata) once objects are inserted into the HttpSession?    From 
>> what I've seen the reflection API requires you to know the class name 
>> in order to get metadata.  This sends me back to step one (circular 
>> trap) since it's the class name that I need.   Any ideas on how to do 
>> this, where to look etc.?
>> Thanks!
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


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


Re: Inspecting HttpSession (circular trap)

Posted by Tim Funk <fu...@joedog.org>.
You'll need to iterate throught the session objects. (by name)
Then via reflection you can determine the class name of each session object.

You can determine className via:

String myClassName = myObject.getClass().getName()

if ("java.lang.String".equals(myClassName)) {
  ...
} else if (...) {
  ...
}

-Tim


Francisco J. Bido wrote:
> I'm creating a session inspector utility but I've come across a bump on 
> the road.  The HttpSession API does not provide a method that
> allows me to get the class name for an object contained in the session. 
>  I can certainly retrieve the instance names (which are of type String)
> but that doesn't help much.  What would help, is the name of the class 
> that created the instance.  Any ideas?
> 
> On a typical application, this is not an issue since one knows the types 
> of all objects in the session (and that's why we know how to cast).   
> But the utility that I'm working is supposed to inspect the session and 
> discover the types.   Do you just loose all class info (metadata) once 
> objects are inserted into the HttpSession?    From what I've seen the 
> reflection API requires you to know the class name in order to get 
> metadata.  This sends me back to step one (circular trap) since it's the 
> class name that I need.   Any ideas on how to do this, where to look etc.?
> 
> Thanks!
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 


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


Re: Inspecting HttpSession (circular trap)

Posted by "Francisco J. Bido" <bi...@mac.com>.
Thanks Filip.  This was the missing piece.

On Monday, April 21, 2003, at 11:48  AM, Filip Hanik wrote:

> retrieve the actual object, and do like this:
>
> String classname = session.getAttribute("myattr").getClass().getName();
>
> check for nulls of course
> Filip
>
> -----Original Message-----
> From: Francisco J. Bido [mailto:bido@mac.com]
> Sent: Monday, April 21, 2003 9:41 AM
> To: Tomcat Users List
> Subject: Inspecting HttpSession (circular trap)
>
>
> I'm creating a session inspector utility but I've come across a bump on
> the road.  The HttpSession API does not provide a method that
> allows me to get the class name for an object contained in the session.
>   I can certainly retrieve the instance names (which are of type 
> String)
> but that doesn't help much.  What would help, is the name of the class
> that created the instance.  Any ideas?
>
> On a typical application, this is not an issue since one knows the
> types of all objects in the session (and that's why we know how to
> cast).   But the utility that I'm working is supposed to inspect the
> session and discover the types.   Do you just loose all class info
> (metadata) once objects are inserted into the HttpSession?    From what
> I've seen the reflection API requires you to know the class name in
> order to get metadata.  This sends me back to step one (circular trap)
> since it's the class name that I need.   Any ideas on how to do this,
> where to look etc.?
>
> Thanks!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


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


RE: Inspecting HttpSession (circular trap)

Posted by Filip Hanik <ma...@filip.net>.
retrieve the actual object, and do like this:

String classname = session.getAttribute("myattr").getClass().getName();

check for nulls of course
Filip

-----Original Message-----
From: Francisco J. Bido [mailto:bido@mac.com]
Sent: Monday, April 21, 2003 9:41 AM
To: Tomcat Users List
Subject: Inspecting HttpSession (circular trap)


I'm creating a session inspector utility but I've come across a bump on 
the road.  The HttpSession API does not provide a method that
allows me to get the class name for an object contained in the session. 
  I can certainly retrieve the instance names (which are of type String)
but that doesn't help much.  What would help, is the name of the class 
that created the instance.  Any ideas?

On a typical application, this is not an issue since one knows the 
types of all objects in the session (and that's why we know how to 
cast).   But the utility that I'm working is supposed to inspect the 
session and discover the types.   Do you just loose all class info 
(metadata) once objects are inserted into the HttpSession?    From what 
I've seen the reflection API requires you to know the class name in 
order to get metadata.  This sends me back to step one (circular trap) 
since it's the class name that I need.   Any ideas on how to do this, 
where to look etc.?

Thanks!


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



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