Bug 34164 - context attributes not available when servlet's destroy() is called
Summary: context attributes not available when servlet's destroy() is called
Status: RESOLVED DUPLICATE of bug 33463
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 5.5.7
Hardware: PC Linux
: P2 blocker (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-24 14:37 UTC by Marc Guillemot
Modified: 2005-03-24 05:41 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Guillemot 2005-03-24 14:37:36 UTC
In Tomcat 5.5.7, the context attributes seem to have been removed before the
method destroy() of the loaded servlets is called. This is not the case with
Tomcat 5.0.28 and I guess that it is wrong because Struts for instance relies on
it to destroy its modules (in
org.apache.struts.action.ActionServlet#destroyModules).

In the case of struts, this causes the plugins not to be notified that they are
destroyed what is against their expected behavior.

A simple servlet illustrates the problem:

public class TestServlet extends HttpServlet
{
  public void init() throws ServletException
  {
    log("In init TestServlet");
    getServletContext().setAttribute("test", "test");
    log("Attribute test: " + getServletContext().getAttribute("test"));
  }

  public void destroy()
  {
    log("In destroy TestServlet");
    log("Attribute test: " + getServletContext().getAttribute("test"));
    super.destroy();
  }
}

Configured with:
  <servlet>
    <servlet-name>test</servlet-name>
    <description>Custom test</description>
    <servlet-class>de.internetzky.test.TestServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>
	

  <servlet-mapping>
    <servlet-name>test</servlet-name>
    <url-pattern>/foo/*</url-pattern>
  </servlet-mapping>

Gives following output in Tomcat 5.5.7:

INFO main org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test]
- test: In init TestServlet
 INFO main org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test]
- test: Attribute test: test

INFO http-8080-Processor24
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test] - test: In
destroy TestServlet
 INFO http-8080-Processor24
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test] - test:
Attribute test: null

but in Tomcat 5.0.28:
StandardContext[/test]test: In init TestServlet
StandardContext[/test]test: Attribute test: test

StandardContext[/test]test: In destroy TestServlet
StandardContext[/test]test: Attribute test: test
Comment 1 Remy Maucherat 2005-03-24 14:41:24 UTC

*** This bug has been marked as a duplicate of 33463 ***