tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ansgar W. Konermann" <konerm...@inf.tu-dresden.de>
Subject GenericServlet.getServletConfig buggy?
Date Fri, 23 Feb 2001 03:00:17 GMT
Hi all,

I (still) have a problem with the context of a servlet.

Within a class derived from HttpServlet (nop.Receiver), this
is my doGet method:

-----
    public void doGet(HttpServletRequest rq, HttpServletResponse rs) 
        throws IOException, ServletException 
    {
        rs.setBufferSize(0);
        rs.setContentType("text/html");
        PrintWriter out = rs.getWriter();
        makeHead(out);
        out.println("<P>Chat Receiver</P>\n");
        rs.flushBuffer();

        ServletConfig myConfig = getServletConfig();
        out.println("myConfig == " + myConfig + "<br>"); // debug output
        theContext = getServletContext();
        out.println("theContext == " + theContext + "<br>"); // debug output

	// ...

-----

It gives me the following output when I call the servlet:

-----

Chat Receiver

myConfig == null

Error: 500

Location: /trial/servlet/Receiver

Internal Servlet Error:

java.lang.NullPointerException
        at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:205)
        at nop.Receiver.doGet(Receiver.java:59)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Handler.java:286)
        at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
        at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
        at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
        at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
        at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
        at java.lang.Thread.run(Thread.java:484)

-----

Please note that myConfig == null and that the following call to 
getServletContext fails with a NullPtrXcpt. From the source code
of GenericServlet I can see that getServletContext is merely
getServletConfig().getServletContext().

According to the Servlet API, Servlet.getServletConfig(),

"Implementations of this interface are responsible for storing
the ServletConfig object so that this method can return it.
The GenericServlet class, which implements this interface,
already does this."

To me, this looks like the implementation I am using is *not*
storing the ServletConfig (which was previously passed to init),
since it returns null. Therefore, GenericServlet.getServletContext
must fail (since it relies on getServletConfig).

Is this a bug or am I just too blind to see my mistake?
Any help would be greatly apreciated.

(Using Tomcat Web Server/3.2.1 (JSP 1.1; Servlet 2.2; Java 1.3.0;
Linux 2.2.16 i386; java.vendor=Sun Microsystems Inc.)

--

Best regards,

Ansgar W. Konermann

Mime
View raw message