From: Fábio Madeira <fmmarquesmadeira@dundee.ac.uk> Date: Fri, 2 Jun 2017 14:16:35 +0000 (+0100) Subject: JWS-121 Added new refresher methods and the respective servlets and mappings entries... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e3be7cadbc2fa3756bd9807ef8db6e4151ebe729;p=jabaws.git 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. --- 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 @@ <servlet-class>compbio.stat.servlet.ServiceStatus</servlet-class> </servlet> + <servlet> + <description>WebServices Status</description> + <servlet-name>ServiceStatusRefresher</servlet-name> + <servlet-class>compbio.stat.servlet.ServiceStatusRefresher</servlet-class> + </servlet> + <!--<servlet>--> <!--<servlet-name>DownloadRedirector</servlet-name>--> <!--<servlet-class>compbio.stat.servlet.DownloadRedirector</servlet-class>--> @@ -91,6 +97,12 @@ </servlet> <servlet> + <description>Display monthly summary statistics with no links to details</description> + <servlet-name>PublicAnnualStatRefresher</servlet-name> + <servlet-class>compbio.stat.servlet.AnnualStatRefresher</servlet-class> + </servlet> + + <servlet> <servlet-name>RegistryWS</servlet-name> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> <load-on-startup>1</load-on-startup> @@ -207,6 +219,11 @@ </servlet-mapping> <servlet-mapping> + <servlet-name>ServiceStatusRefresher</servlet-name> + <url-pattern>/ServiceStatusRefresher</url-pattern> + </servlet-mapping> + + <servlet-mapping> <servlet-name>HttpCodeResponseServiceStatus</servlet-name> <url-pattern>/HttpCodeResponseServiceStatus/*</url-pattern> </servlet-mapping> @@ -222,6 +239,11 @@ </servlet-mapping> <servlet-mapping> + <servlet-name>PublicAnnualStatRefresher</servlet-name> + <url-pattern>/PublicAnnualStatRefresher</url-pattern> + </servlet-mapping> + + <servlet-mapping> <servlet-name>Joblist</servlet-name> <url-pattern>/Joblist</url-pattern> </servlet-mapping> 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<Date, Totals> 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<ServiceTestResult> testResults = new ArrayList<ServiceTestResult>(); + 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"); + + } + +}