tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roytman, Alex" <roytm...@peacetech.com>
Subject Thread.currentThread().getContextClassLoader() in Tomcat 3.2
Date Tue, 21 Nov 2000 15:59:50 GMT
I would like to use Thread.currentThread().getContextClassLoader() with
Tomcat 3.2 to resolve one common problem when class from system classpath
needs to call something loaded by tomcat context's loader. As far as I
understand Tomcat 3.2 suppose to run under jdk1.1 so it does not do
Thread.currentThread().setContextClassLoader() before it hands control to a
Servlet.

Below are my interceptors I use for
Thread.currentThread().setContextClassLoader() and setting scope of jndi to
make it tomcat context specific.

I wonder if someone with more knowledge on tomcat internal could possibly
comment on this approach. Is it right approach? is it safe? What if someone
in another interceptor will do something else to
Thread.currentThread().contextClassLoader?    

Your feedback is greatly appreciated

Alex



Request Interceptor:

  public int preService(Request request, Response response) {
 
Thread.currentThread().setContextClassLoader(request.getContext().getServlet
Loader().getClassLoader());
    HierInitCtxFactory.selectScope(request.getContext().getPath());
    return 0;
  }

  public int postService(Request request, Response response) {
    HierInitCtxFactory.selectScope(null);
 
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    return 0;
  }


ContextInterceptor:

  public void preServletInit(Context ctx, ServletWrapper sw) throws
TomcatException {
 
Thread.currentThread().setContextClassLoader(ctx.getServletLoader().getClass
Loader());
    HierInitCtxFactory.selectScope(ctx.getPath());
  }

  public void postServletInit(Context ctx, ServletWrapper sw) throws
TomcatException {
    HierInitCtxFactory.selectScope(null);
 
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  }

Mime
View raw message