From 7114c38b358d27e6c390a689a50c7f9d2d2a048c Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Mon, 12 Oct 2009 23:18:03 +0200 Subject: [PATCH] Added a way to get the time of start of the server context. --- src/dolda/jsvc/ServerContext.java | 1 + src/dolda/jsvc/j2ee/J2eeContext.java | 4 ++++ src/dolda/jsvc/j2ee/Servlet.java | 2 ++ src/dolda/jsvc/test/TestResponder.java | 1 + 4 files changed, 8 insertions(+) diff --git a/src/dolda/jsvc/ServerContext.java b/src/dolda/jsvc/ServerContext.java index b9809f9..c2d539b 100644 --- a/src/dolda/jsvc/ServerContext.java +++ b/src/dolda/jsvc/ServerContext.java @@ -2,4 +2,5 @@ package dolda.jsvc; public interface ServerContext { public String rootpath(); + public long starttime(); } diff --git a/src/dolda/jsvc/j2ee/J2eeContext.java b/src/dolda/jsvc/j2ee/J2eeContext.java index f253128..e8f65a6 100644 --- a/src/dolda/jsvc/j2ee/J2eeContext.java +++ b/src/dolda/jsvc/j2ee/J2eeContext.java @@ -18,4 +18,8 @@ public class J2eeContext implements ServerContext { public String rootpath() { return(req.getContextPath()); } + + public long starttime() { + return((Long)cfg.getServletContext().getAttribute("jsvc.starttime")); + } } diff --git a/src/dolda/jsvc/j2ee/Servlet.java b/src/dolda/jsvc/j2ee/Servlet.java index 4d0d3bd..165b0f2 100644 --- a/src/dolda/jsvc/j2ee/Servlet.java +++ b/src/dolda/jsvc/j2ee/Servlet.java @@ -48,6 +48,8 @@ public class Servlet extends HttpServlet { } catch(InvocationTargetException e) { throw(new ServletException("JSvc bootstrapper failed", e)); } + ServletContext ctx = getServletContext(); + ctx.setAttribute("jsvc.starttime", System.currentTimeMillis()); } public void destroy() { diff --git a/src/dolda/jsvc/test/TestResponder.java b/src/dolda/jsvc/test/TestResponder.java index fbe2204..d466156 100644 --- a/src/dolda/jsvc/test/TestResponder.java +++ b/src/dolda/jsvc/test/TestResponder.java @@ -19,6 +19,7 @@ public class TestResponder implements Responder { out.println("

Barda

"); out.println("Bardslen."); out.println(req.inheaders()); + out.println(req.ctx().starttime()); out.println(""); out.println(""); out.flush(); -- 2.11.0