I'm trying to build a servlet that I can get the DocBase with, so I'm trying to locate org.apache.catalina.Context from the servlet.
Tomcat Version: 5.0.28 Java Version: 1.4.2_05
What I'm doing:
I am implementing ContainerServlet and this works great when I run the servlet through a web application defined in $catalina.home/servers/webapps/<my_webapp>. Pretty much in the same place as the manager servlet. However when I run it as an installed WAR file I am getting a nasty null pointer exception (running from $catalina.home/webapps/<my_webapp>).
The issue:
setWrapper() is never getting called when I have this inside the $catalina.home/webapps/ directory tree... only when I have it in $catalina.home/server/ directory tree. Any thoughts on this? When this webapp goes live it will be installed as a WAR file and I won't be able to control what directory it is in. Any thoughts?
Here is my servlet, pretty basic, just trying to find the Context and DocBase:
//-- SERVLET START --
import org.apache.catalina.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.*;
import java.io.*;
public class Ctx extends HttpServlet implements ContainerServlet {
Context context;
Deployer deployer;
Wrapper wrapper;
public Ctx() {
context = null;
deployer = null;
wrapper = null;
}
public Wrapper getWrapper() {
return wrapper;
}
public void setWrapper(Wrapper wrapper) {
this.wrapper = wrapper;
try {
context = (Context)wrapper.getParent();
deployer = (Deployer)context.getParent();
} catch (NullPointerException e) {
context = null;
deployer = null;
}
}
public void destroy() {
// do nothing }
public void init() {
// do nothing
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
doGet(request, response); }
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
out.println("My Context Object: " + context);
out.println("Doc Base: " + context.getDocBase());
out.flush();
out.close();
}
}
//-- SERVLET END --
-- /** * Robin Curts * [EMAIL PROTECTED] * http://www.robincurts.com * (813) 786-8634 */
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]