You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@jakarta.apache.org by Alex Yiu <ay...@us.oracle.com> on 2000/03/08 04:45:38 UTC

problem/bug in tomcat: restarting a session

Hi,

I found out that there is a bug / an extra restriction about restarting
a session in Tomcat implementation (3.1M1). This "behavior" does not
exist in previous Javasoft's servlet reference implementation. And,
IMHO, I don't think the restriction is unreasonble. Actually, I think
it's a bug.

What I want to do in restarting a session:
(1) invalidate the session
(2) recreate a new session within the same request
(3) then use the session (set/get attrs)

When I tried to do these, I got a java.lang.IllegalStateException,
saying, Session already invalidated (see below). After invalidation,
req.getSession(true) still returns the same session handle to me. I
think it should return a new session object to me. So, the
IllegalStateException won't occur.


Here is a piece of sample code: SessTest.java:
======================================================
import javax.servlet.http.*;
import java.io.*;

public class SessTest extends HttpServlet
{
  public void service(HttpServletRequest req, HttpServletResponse rep)
  {
    try {
      PrintWriter out=rep.getWriter();
      out.println("<pre>SessTest");
      HttpSession session=req.getSession(true);
      out.println(session.getAttribute("abc"));
      out.println(session);
      session.setAttribute("abc","def");
      session.invalidate();
      session=req.getSession(true);
      out.println("SessTest-002");
      out.println(session);
      session.setAttribute("abc","def");
      out.println("SessTestEnd</pre>");
    } catch (IOException ioe)
    {
    }
  }
}
======================================================

Here is the output:
======================================================
SessTest
null
org.apache.tomcat.session.StandardSession@1dc63906
SessTest-002
org.apache.tomcat.session.StandardSession@1dc63906
Error: 500

Internal Servlet Error:

java.lang.IllegalStateException: setAttribute: Session already
invalidated
        at
org.apache.tomcat.session.StandardSession.setAttribute(StandardSession.java:709)
        at SessTest.service(SessTest.java:20)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
        at
org.apache.tomcat.core.ServletWrapper.handleInvocation(ServletWrapper.java:403)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:224)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:347)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:144)
        at
org.apache.tomcat.service.TcpConnectionThread.run(TcpEndpoint.java:305)
        at java.lang.Thread.run(Thread.java)
======================================================