summaryrefslogtreecommitdiffhomepage
path: root/test/java/session
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/java/session/app.java30
-rw-r--r--test/java/session_inactive/app.java27
-rw-r--r--test/java/session_invalidate/app.java23
-rw-r--r--test/java/session_listeners/app.java80
-rw-r--r--test/java/session_listeners/web.xml14
5 files changed, 174 insertions, 0 deletions
diff --git a/test/java/session/app.java b/test/java/session/app.java
new file mode 100644
index 00000000..84d3fa55
--- /dev/null
+++ b/test/java/session/app.java
@@ -0,0 +1,30 @@
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+@WebServlet(urlPatterns = "/")
+public class app extends HttpServlet
+{
+ @Override
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ HttpSession s = request.getSession();
+ String old_var1 = (String) s.getAttribute("var1");
+ s.setAttribute("var1", request.getParameter("var1"));
+
+ if (old_var1 == null) {
+ response.addHeader("X-Var-1", "null");
+ } else {
+ response.addHeader("X-Var-1", old_var1);
+ }
+
+ response.addHeader("X-Session-Id", s.getId());
+ response.addHeader("X-Session-New", "" + s.isNew());
+ }
+}
diff --git a/test/java/session_inactive/app.java b/test/java/session_inactive/app.java
new file mode 100644
index 00000000..f338fc89
--- /dev/null
+++ b/test/java/session_inactive/app.java
@@ -0,0 +1,27 @@
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+@WebServlet(urlPatterns = "/")
+public class app extends HttpServlet
+{
+ @Override
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ HttpSession s = request.getSession();
+
+ if (s.isNew()) {
+ s.setMaxInactiveInterval(2);
+ }
+
+ response.addHeader("X-Session-Id", s.getId());
+ response.addDateHeader("X-Session-Last-Access-Time", s.getLastAccessedTime());
+ response.addIntHeader("X-Session-Interval", s.getMaxInactiveInterval());
+ }
+}
diff --git a/test/java/session_invalidate/app.java b/test/java/session_invalidate/app.java
new file mode 100644
index 00000000..3f66290f
--- /dev/null
+++ b/test/java/session_invalidate/app.java
@@ -0,0 +1,23 @@
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+@WebServlet(urlPatterns = "/")
+public class app extends HttpServlet
+{
+ @Override
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ HttpSession s = request.getSession();
+
+ s.invalidate();
+
+ response.addHeader("X-Session-Id", s.getId());
+ }
+}
diff --git a/test/java/session_listeners/app.java b/test/java/session_listeners/app.java
new file mode 100644
index 00000000..603cc932
--- /dev/null
+++ b/test/java/session_listeners/app.java
@@ -0,0 +1,80 @@
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionIdListener;
+import javax.servlet.http.HttpSessionListener;
+
+@WebServlet(urlPatterns = "/")
+public class app extends HttpServlet implements
+ HttpSessionListener,
+ HttpSessionIdListener,
+ HttpSessionAttributeListener
+{
+ private static String session_created = "";
+ private static String session_destroyed = "";
+ private static String session_id_changed = "";
+ private static String attribute_added = "";
+ private static String attribute_removed = "";
+ private static String attribute_replaced = "";
+
+ @Override
+ public void sessionCreated(HttpSessionEvent se)
+ {
+ session_created += se.getSession().getId();
+ }
+
+ @Override
+ public void sessionDestroyed(HttpSessionEvent se)
+ {
+ session_destroyed += se.getSession().getId();
+ }
+
+ @Override
+ public void sessionIdChanged(HttpSessionEvent event, String oldId)
+ {
+ session_id_changed += " " + oldId + "->" + event.getSession().getId();
+ }
+
+ @Override
+ public void attributeAdded(HttpSessionBindingEvent event)
+ {
+ attribute_added += event.getName() + "=" + event.getValue();
+ }
+
+ @Override
+ public void attributeRemoved(HttpSessionBindingEvent event)
+ {
+ attribute_removed += event.getName() + "=" + event.getValue();
+ }
+
+ @Override
+ public void attributeReplaced(HttpSessionBindingEvent event)
+ {
+ attribute_replaced += event.getName() + "=" + event.getValue();
+ }
+
+ @Override
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ HttpSession s = request.getSession();
+ s.setAttribute("var1", request.getParameter("var1"));
+
+ response.addHeader("X-Session-Id", s.getId());
+ response.addHeader("X-Session-Created", session_created);
+ response.addHeader("X-Session-Destroyed", session_destroyed);
+ response.addHeader("X-Attr-Added", attribute_added);
+ response.addHeader("X-Attr-Removed", attribute_removed);
+ response.addHeader("X-Attr-Replaced", attribute_replaced);
+ }
+}
diff --git a/test/java/session_listeners/web.xml b/test/java/session_listeners/web.xml
new file mode 100644
index 00000000..aedfe175
--- /dev/null
+++ b/test/java/session_listeners/web.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="3.0">
+ <listener>
+ <listener-class>app</listener-class>
+ </listener>
+ <listener>
+ <listener-class>app</listener-class>
+ </listener>
+</web-app>
+