You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by th...@polaris.co.in on 2003/07/22 14:42:58 UTC

Craig/Ted .. Need help classLoader.getResourceAsStream(name) doesn't not work in iPlanet

Hi Craig/Ted,

     I am not getting enough attention to this thread. I am trying to give
different subjects, but no reply. Could you please reply.

      When I was debugging the code and verifying the log. I found the code
snippet mentioned below is behaving erratically in iPlanet/Sun ONE Web
Server. I  have no idea what is the purpose of the following code and why
it should behave differently in two different web servers.

PropertyMessageResources.java

        ClassLoader classLoader = Thread.currentThread
().getContextClassLoader();
        if (classLoader == null) {
            classLoader = this.getClass().getClassLoader();
        }

        is = classLoader.getResourceAsStream(name);

    is always returns NULL in iPlanet/Sun ONE Platform

   If I change the code as mentioned below, it works. This is the code
which was there in struts 1.0.2.

       ClassLoader classLoader = this.getClass().getClassLoader();

   And wherever this code block is used there also it throws exceptions.

   The same code is used in the following sources also.

ActionServlet.java(437)
FormBeanConfig.java(315)
FormPropertyConfig.java(257)
RequestUtils.java(201)

   Could somebody explain the purpose of this code and why was it changed
in 1.1?

   If I change the code to 1.0.2 style will it have any impact on the
struts functionality.

Best Regards,
Thiru


Re: Craig/Ted .. Need help classLoader.getResourceAsStream(name) doesn't not work in iPlanet

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 22 Jul 2003 thirumalai.veeraswamy@polaris.co.in wrote:

> Date: Tue, 22 Jul 2003 18:12:58 +0530
> From: thirumalai.veeraswamy@polaris.co.in
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: struts-user@jakarta.apache.org
> Cc: thirumalai.veeraswamy@polaris.co.in
> Subject: Craig/Ted .. Need help classLoader.getResourceAsStream(name)
>     doesn't not work in iPlanet
>
> Hi Craig/Ted,
>
>      I am not getting enough attention to this thread. I am trying to give
> different subjects, but no reply. Could you please reply.
>

I suspect it's a bug in the webserver, perhaps not setting the thread
context class loader reliably.

>       When I was debugging the code and verifying the log. I found the code
> snippet mentioned below is behaving erratically in iPlanet/Sun ONE Web
> Server. I  have no idea what is the purpose of the following code and why
> it should behave differently in two different web servers.
>
> PropertyMessageResources.java
>
>         ClassLoader classLoader = Thread.currentThread
> ().getContextClassLoader();
>         if (classLoader == null) {
>             classLoader = this.getClass().getClassLoader();
>         }
>
>         is = classLoader.getResourceAsStream(name);
>
>     is always returns NULL in iPlanet/Sun ONE Platform
>
>    If I change the code as mentioned below, it works. This is the code
> which was there in struts 1.0.2.
>
>        ClassLoader classLoader = this.getClass().getClassLoader();
>

This will not work when we ultimately support putting struts.jar into a
shared parent class loader (in Tomcat, that would mean being able to put
it into $CATALINA_HOME/common/lib).  The problem is that code in the
parent class loader can't see classes in the webapp class loader, so you
would get "class not found" on all your actions, form beans, and so on.

I'd file a bug against S1WS on this issue.

>    And wherever this code block is used there also it throws exceptions.
>
>    The same code is used in the following sources also.
>
> ActionServlet.java(437)
> FormBeanConfig.java(315)
> FormPropertyConfig.java(257)
> RequestUtils.java(201)
>

The key issue is that when a class tries to load another class (via the
"new" operator or this.getClass.getClassLoader()), it can only look *up*
the class loader hierarchy, but not *down*.  For detailed information on
how servlet containers are typically organized (the exact info is specific
to Tomcat, but most of them do something similar), see:

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-howto.html

>    Could somebody explain the purpose of this code and why was it changed
> in 1.1?
>

In order to move towards being able to put struts.jar and the commons
libraries in a shared repository.

>    If I change the code to 1.0.2 style will it have any impact on the
> struts functionality.
>

Not for you, but it would for others, so we can't go back.

> Best Regards,
> Thiru
>
>

Craig


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