On Fri, 5 Jul 2002, A. Alfred Ayache wrote:

> Date: Fri, 05 Jul 2002 17:05:46 -0400
> From: A. Alfred Ayache <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: Tomcat Users List <[EMAIL PROTECTED]>
> Subject: Re: Garbage in Context Attributes
>
> Craig:
>
> You know, I had tried that, and this is the first few lines of the
> exception I got back:
>
> java.lang.ClassCastException: java.lang.String
>       at ServerSnoop.service(ServerSnoop.java:23)
>       at
> org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:450)
>       at
> org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at
> 
>org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
>
> Line 23 of ServerSnoop.java looks like this:
>
>     Enumeration enum = context.getAttributeNames();
>     while (enum.hasMoreElements()) {
>       String name[] = (String[]) enum.nextElement();
>         for (int i=0; i < name.length; ++i) {
>               out.println("  context.getAttribute(\"" + name + "[" + i + "]\"):
> " +
>                      context.getAttribute(name[i]));
>       }
>     }
>
> It's the line with the String[] cast.
>

Your code would only work if *every* servlet context attribute is a string
array, which is not the case.  So you will naturally get a class cast
exception on anything that is not.


> Thanks for your help!
> - Alfred
>

Craig


> "Craig R. McClanahan" wrote:
> >
> > On Thu, 4 Jul 2002, Cor Hofman wrote:
> >
> > > Date: Thu, 4 Jul 2002 08:40:34 +0200
> > > From: Cor Hofman <[EMAIL PROTECTED]>
> > > Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> > > To: Tomcat Users List <[EMAIL PROTECTED]>
> > > Subject: RE: Garbage in Context Attributes
> > >
> > > Alfred,
> > >
> > > I am not familiar with the example you mention, but the contents of your
> > > attributes is not garbage.
> > >
> > > The WELCOME_FILES contains a String array.
> > > The resources contains a class named
> > > org.apache.naming.resource.ProxyDirContext.
> > >
> >
> > As the "org.apache.xxx" prefix implies, these attributes are created by
> > Tomcat for its own purposes.  It's perfectly legal for the container to
> > store its own servlet context attributes.  To avoid name clashes, the same
> > conventions as used for fully qualified classes (reversed domain name) are
> > appropriate here.
> >
> > > Cor.
> > >
> >
> > Craig
> >
> > > -----Original Message-----
> > > From: A. Alfred Ayache [mailto:[EMAIL PROTECTED]]
> > > Sent: Wednesday, July 03, 2002 22:19
> > > To: Tomcat Users List
> > > Subject: Garbage in Context Attributes
> > >
> > >
> > > Just ran ServerSnoop from the Hunter book, and in the
> > > context.getAttributeNames() I get two attributes with partial garbage:
> > >
> > > context.getAttributeNames():
> > >   context.getAttribute("org.apache.catalina.WELCOME_FILES"):
> > > [Ljava.lang.String;@baa466
> > >   context.getAttribute("org.apache.catalina.resources"):
> > > org.apache.naming.resources.ProxyDirContext@7f409c
> > >
> > > Anyone know why this is happening?
> > >
> > > Thanks,
> > > --
> > > A. Alfred Ayache,              | 20 years' experience
> > > President, The Last Byte, Inc. | Testimonials
> > > Custom software par excellence | Links
> > > http://www.lastbyte-inc.com    | Free Software
> > >
> > > --
> > > To unsubscribe, e-mail:
> > > <mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail:
> > > <mailto:[EMAIL PROTECTED]>
> > >
> > >
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> > >
> > >
> >
> > --
> > To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
> --
> A. Alfred Ayache,              | 20 years' experience
> President, The Last Byte, Inc. | Testimonials
> Custom software par excellence | Links
> http://www.lastbyte-inc.com    | Free Software
>
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to