From e3be7cadbc2fa3756bd9807ef8db6e4151ebe729 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fa=CC=81bio=20Madeira?= Date: Fri, 2 Jun 2017 15:16:35 +0100 Subject: [PATCH] JWS-121 Added new refresher methods and the respective servlets and mappings entries in web.xml. These are used to update the ServletContext values as an input from the user (clickable links) that point to the new endpoints. --- WEB-INF/web.xml | 22 +++++++ .../compbio/stat/servlet/AnnualStatRefresher.java | 65 +++++++++++++++++++ .../stat/servlet/ServiceStatusRefresher.java | 68 ++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 webservices/compbio/stat/servlet/AnnualStatRefresher.java create mode 100644 webservices/compbio/stat/servlet/ServiceStatusRefresher.java diff --git a/WEB-INF/web.xml b/WEB-INF/web.xml index f6b6daf..1519d57 100644 --- a/WEB-INF/web.xml +++ b/WEB-INF/web.xml @@ -61,6 +61,12 @@ compbio.stat.servlet.ServiceStatus + + WebServices Status + ServiceStatusRefresher + compbio.stat.servlet.ServiceStatusRefresher + + @@ -91,6 +97,12 @@ + Display monthly summary statistics with no links to details + PublicAnnualStatRefresher + compbio.stat.servlet.AnnualStatRefresher + + + RegistryWS com.sun.xml.ws.transport.http.servlet.WSServlet 1 @@ -207,6 +219,11 @@ + ServiceStatusRefresher + /ServiceStatusRefresher + + + HttpCodeResponseServiceStatus /HttpCodeResponseServiceStatus/* @@ -222,6 +239,11 @@ + PublicAnnualStatRefresher + /PublicAnnualStatRefresher + + + Joblist /Joblist diff --git a/webservices/compbio/stat/servlet/AnnualStatRefresher.java b/webservices/compbio/stat/servlet/AnnualStatRefresher.java new file mode 100644 index 0000000..28a10c0 --- /dev/null +++ b/webservices/compbio/stat/servlet/AnnualStatRefresher.java @@ -0,0 +1,65 @@ +/* Copyright (c) 2017 Fabio Madeira + * + * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 + * + * This library is free software; you can redistribute it and/or modify it under the terms of the + * Apache License version 2 as published by the Apache Software Foundation + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache + * License for more details. + * + * A copy of the license is in apache_license.txt. It is also available here: + * @see: http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Any republication or derived work distributed in source code form + * must include this copyright and license notice. + */ + +package compbio.stat.servlet; + +import compbio.stat.servlet.util.Totals; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Map; + +public class AnnualStatRefresher extends AnnualStat { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + Map monthlyTotals; + String timeStamp = new String(); + long startTime; + long endTime; + + // get stats from db + startTime = System.nanoTime(); + monthlyTotals = checkMonthlyTotals(resp); + endTime = System.nanoTime(); + if (monthlyTotals != null) { + // try clear the previous values if any + clearContextCache(); + // add the current values to the context + this.getServletConfig().getServletContext().setAttribute("usageStatsResults", monthlyTotals); + timeStamp = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format( + Calendar.getInstance().getTime()); + this.getServletConfig().getServletContext().setAttribute("usageStatsTimestamp", timeStamp); + this.getServletConfig().getServletContext().setAttribute("usageStatsStart", startTime); + this.getServletConfig().getServletContext().setAttribute("usageStatsEnd", endTime); + } else { + return; + } + + resp.sendRedirect("PublicAnnualStat"); + + } + +} \ No newline at end of file diff --git a/webservices/compbio/stat/servlet/ServiceStatusRefresher.java b/webservices/compbio/stat/servlet/ServiceStatusRefresher.java new file mode 100644 index 0000000..5240648 --- /dev/null +++ b/webservices/compbio/stat/servlet/ServiceStatusRefresher.java @@ -0,0 +1,68 @@ +/* Copyright (c) 2017 Fabio Madeira + * + * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 + * + * This library is free software; you can redistribute it and/or modify it under the terms of the + * Apache License version 2 as published by the Apache Software Foundation + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache + * License for more details. + * + * A copy of the license is in apache_license.txt. It is also available here: + * @see: http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Any republication or derived work distributed in source code form + * must include this copyright and license notice. + */ + +package compbio.stat.servlet; + +import java.io.IOException; +import java.util.*; +import java.text.SimpleDateFormat; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +public class ServiceStatusRefresher extends ServiceStatus { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + /** + * // PROBLEM: the code tries to test not WS endpoints on an internal + * Tomcat, but on an external // endpoints with wrong info on the + * proxing StringBuffer jabawspath = req.getRequestURL(); jabawspath = + * jabawspath.delete(jabawspath.lastIndexOf("/"), jabawspath.length()); + * String serverPath = jabawspath.toString(); + */ + + ArrayList testResults = new ArrayList(); + String timeStamp = new String(); + long startTime; + long endTime; + String goodStatus; + + // test the services and timeit + startTime = System.nanoTime(); + testResults = testServiceStatus(req); + endTime = System.nanoTime(); + // try clear the previous values if any + clearContextCache(); + // add the current values to the context + this.getServletConfig().getServletContext().setAttribute("serviceStatusResults", testResults); + timeStamp = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format( + Calendar.getInstance().getTime()); + this.getServletConfig().getServletContext().setAttribute("serviceStatusTimestamp", timeStamp); + this.getServletConfig().getServletContext().setAttribute("serviceStatusStart", startTime); + this.getServletConfig().getServletContext().setAttribute("serviceStatusEnd", endTime); + goodStatus = overallStatusGood(testResults); + this.getServletConfig().getServletContext().setAttribute("serviceStatusAllGood", goodStatus); + + resp.sendRedirect("ServiceStatus"); + + } + +} -- 1.7.10.2