users@grizzly.java.net

Embedded Grizzly HTTP session problems

From: Richard Zschech <richard_at_zschech.net>
Date: Thu, 28 Jan 2010 13:45:39 +1030

Hi All,

 

I'm trying to embed Grizzly in to my application and am having problems with
its HTTP session management.

 

Firstly session.invalidate() does not seem to work as demonstrated by my
test Servlet below. Reloading the page should cause the response message to
rotate between "Creating Session", "Resuming Session" and "Destroying
Session". It only responds with "Creating Session" initially and never does
after "Destroying Session".

 

Secondly different browsers get allocated the same session id.

 

I'm using Grizzly version 1.9.18-i.

 

Everything works fine when I deploy the war using Glassfish version v3.

 

Does anyone have any ideas what the problem is here?

 

Shall I raise a bug?

 

Looking at com.sun.grizzly.http.servlet.HttpSessionImpl invalidate does not
seem to call setIsValid on the underlying GrizzlySession.

 

Looking at com.sun.grizzly.tcp.http11.GrizzlyRequest where the session
management is being done there is no concurrency control on the "sessions"
map, which might be causing multiple browsers getting the same one.

 

From Richard.

 

 

I'm embedding it as follows:

 

public static void main(String[] args) {

                GrizzlyWebServerDeployer deployer = new
GrizzlyWebServerDeployer();

                deployer.setDeployedApplicationList(new
ArrayList<String>());

                deployer.setLocations("grizzly.war");

                deployer.setCometEnabled(true);

                deployer.setForceWarDeployment(true);

                deployer.launch();

}

 

My test Servlet's doGet method:

 

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

                HttpSession session = req.getSession(false);

                String response;

                if (session == null) {

                                session = req.getSession();

                                response = "Creating Session " +
session.getId();

                }

                else {

                                if (session.getAttribute("x") != null) {

                                                response = "Destroying
Session " + session.getId();

                                                session.invalidate();

                                }

                                else {

                                                response = "Resuming Session
" + session.getId();

                                                session.setAttribute("x",
"x");

                                }

                }

                System.err.println(response);

                resp.getWriter().println(response);

}