CPPSERV


Home Projects Jobs Clientele Contact

cppserv


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add new test functionality for sessions servlet, fixed issue



From: Sergey Jukov <sergey@total-knowledge.com>

diff --git a/ChangeLog b/ChangeLog
index cde6de9..31a1c5d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sergey Jukov <sergey@total-knowledge.com>            Tue, 19 Sep 2006 18:40:00 -0800
+- Add testing getId(), getCreationTime(), getLastAccessedTime(),
+  setMaxInactiveInterval(), getMaxInactiveInterval() and isNew()
+  functions for session servlet.
+- Fixed issue with session visits counter.
+
 Sergey Jukov <sergey@total-knowledge.com>            Tue, 19 Sep 2006 15:50:00 -0800
 - Add testing reset() for headers
 
diff --git a/session/session.cpp b/session/session.cpp
index 4e380b6..c285d04 100644
--- a/session/session.cpp
+++ b/session/session.cpp
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2004 by Ilya A. Volynets-Evenbakh                       *
+ *   Copyright (C) 2004-2006 by Ilya A. Volynets-Evenbakh                  *
  *   ilya@total-knowledge.com                                              *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -30,10 +30,31 @@ void SessionServlet::service(servlet::Ht
 		(*counter)++;
 	} else {
 		counter=ctr_t(new int(0));
-		s->setAttribute("count",counter);
+		s->setAttribute("count",*counter);
 	}
 	renderHeader(out);
+	out<<"<PRE>";
+	if(s->isNew()){
+		out<<"New session!\n";
+	} else {
+		out<<"Old session\n";
+	}
 	out<<"You hit this page "<<*counter<<" times during this session";
+	out<<"\n\nSessionID: "<<s->getId();
+	long sCreationTime=s->getCreationTime();
+	struct tm sout;
+	gmtime_r(&sCreationTime, &sout);
+	char str[32];
+	strftime(str, sizeof(str), "%a, %d %b %Y %H:%M:%S GMT", &sout);
+	out<<"\nCreation time: "<<str;
+	long sLastAccessedTime=s->getLastAccessedTime();
+	gmtime_r(&sLastAccessedTime, &sout);
+	strftime(str, sizeof(str), "%a, %d %b %Y %H:%M:%S GMT", &sout);
+	out<<"\nLast Accessed time: "<<str;
+	s->setMaxInactiveInterval(30);
+	int sMaxInactiveInterval=s->getMaxInactiveInterval();
+	out<<"\nMaximum time interval: "<<sMaxInactiveInterval<<" seconds";
+	out<<"<\PRE>";
 	renderFooter(out);
 }
 
diff --git a/session/session.h b/session/session.h
index 0022658..8117cd2 100644
--- a/session/session.h
+++ b/session/session.h
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2004 by Ilya A. Volynets-Evenbakh                       *
+ *   Copyright (C) 2004-2006 by Ilya A. Volynets-Evenbakh                  *
  *   ilya@total-knowledge.com                                              *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -28,7 +28,13 @@ #include <iostream>
 /**
 This servlet demonstrates how to use sessions.
 It displays a page with number of hits within current session.
-This servlet also remonstrates use of CPPServObjectWrapper template.
+This servlet also demonstrates use of CPPServObjectWrapper template.
+It shows session id, session creation time and the last time when
+client sent a request associated with this session.
+It sets time (30 seconds in this example) between client requests
+before the session will be invalidated and returns maximum time
+interval, in seconds, that the servlet container will keep this session
+open between client accesses.
 
 @author Ilya A. Volynets-Evenbakh
 */
-- 
1.4.2


Authoright © Total Knowledge: 2001-2008