[DS-1456] Make webapp.s register in a new database table when started, so we can

list them later.
This commit is contained in:
Mark H. Wood
2013-06-07 15:28:27 -04:00
parent 21bab5a336
commit da4dfb1314
11 changed files with 122 additions and 27 deletions

View File

@@ -8,6 +8,7 @@
package org.dspace.app.util;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context;
import org.dspace.storage.rdbms.DatabaseManager;
import org.apache.log4j.Logger;
@@ -19,26 +20,35 @@ import java.net.URL;
import java.net.URLConnection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Enumeration;
/**
* Class to initialize / cleanup resources used by DSpace when the web application
* is started or stopped
* is started or stopped.
*/
public class DSpaceContextListener implements ServletContextListener
{
private static Logger log = Logger.getLogger(DSpaceContextListener.class);
/**
* The DSpace config parameter, this is where the path to the DSpace
* configuration file can be obtained
* Name of the context parameter giving the path to the DSpace configuration file.
*/
public static final String DSPACE_CONFIG_PARAMETER = "dspace-config";
/** Name of context parameter giving this application's name. */
public static final String DSPACE_APP_NAME_PARAMETER = "dspace.app.name";
/** This application's name */
private static String appName;
/**
* Initialize any resources required by the application
* Initialize any resources required by the application.
* @param event
*/
@Override
public void contextInitialized(ServletContextEvent event)
{
@@ -114,6 +124,37 @@ public class DSpaceContextListener implements ServletContextListener
"either the local servlet or global context.\n\n",e);
}
/*
* Stage 3
*
* Record that a DSpace web app. is running.
*/
try {
appName = event.getServletContext().getInitParameter(DSPACE_APP_NAME_PARAMETER);
if (null == appName)
{
log.warn(DSPACE_APP_NAME_PARAMETER + " not defined -- using 'DSpace'");
appName = "DSpace";
}
String baseUrl = ConfigurationManager.getProperty("dspace.baseUrl");
if (null == baseUrl)
{
throw new IllegalStateException("dspace.baseUrl is undefined");
}
String url = baseUrl + '/' + event.getServletContext().getContextPath();
Timestamp now = new Timestamp(new Date().getTime());
Context context = new Context();
DatabaseManager.updateQuery(context,
"DELETE FROM Webapp WHERE AppName = ?", appName);
DatabaseManager.updateQuery(context,
"INSERT INTO Webapp (AppName, URL, Started) VALUES(?, ?, ?);",
appName, url, now);
context.complete();
} catch (SQLException e) {
log.error("Failed to record startup in Webapp table.", e);
}
}
/**
@@ -121,8 +162,19 @@ public class DSpaceContextListener implements ServletContextListener
*
* @param event
*/
@Override
public void contextDestroyed(ServletContextEvent event)
{
// Deregister this application
try {
Context context = new Context();
DatabaseManager.updateQuery(context,
"DELETE FROM Webapp WHERE AppName = ?", appName);
context.complete();
} catch (SQLException e) {
log.error("Failed to record shutdown in Webapp table.", e);
}
try
{
// Remove the database pool

View File

@@ -51,6 +51,11 @@
<param-value>/WEB-INF/spring/*.xml</param-value>
</context-param>
<context-param>
<description>Name of the application</description>
<param-name>dspace.app.name</param-name>
<param-value>JSPUI</param-value>
</context-param>
<!-- Filters -->

View File

@@ -21,6 +21,12 @@
</description>
</context-param>
<context-param>
<description>Name of the application</description>
<param-name>dspace.app.name</param-name>
<param-value>LNI</param-value>
</context-param>
<!--
Listener to initialise DSpace configuration and clean up the application
-->

View File

@@ -30,6 +30,12 @@
<param-value>${dspace.dir}</param-value>
</context-param>
<context-param>
<description>Name of the application</description>
<param-name>dspace.app.name</param-name>
<param-value>OAI</param-value>
</context-param>
<listener>
<listener-class>
org.dspace.app.util.DSpaceContextListener

View File

@@ -49,6 +49,12 @@
</description>
</context-param>
<context-param>
<description>Name of the application</description>
<param-name>dspace.app.name</param-name>
<param-value>SWORD</param-value>
</context-param>
<!--
Listener to initialise DSpace configuration and clean up the application
-->

View File

@@ -31,6 +31,12 @@
<param-value>${dspace.dir}</param-value>
</context-param>
<context-param>
<description>Name of the application</description>
<param-name>dspace.app.name</param-name>
<param-value>SWORDv2</param-value>
</context-param>
<!-- Configuration Information -->
<context-param>

View File

@@ -55,6 +55,12 @@
<param-value>/WEB-INF/spring/*.xml</param-value>
</context-param>
<context-param>
<description>Name of the application</description>
<param-name>dspace.app.name</param-name>
<param-value>XMLUI</param-value>
</context-param>
<!--
- Use the Cocoon debug filter together with the Cocoon demo webapp
<filter-mapping>

View File

@@ -807,8 +807,9 @@ CREATE TABLE versionitem
CREATE SEQUENCE versionitem_seq;
CREATE SEQUENCE versionhistory_seq;
CREATE TABLE Webapp
(
AppName VARCHAR(32) NOT NULL PRIMARY KEY,
URL VARCHAR NOT NULL,
Started TIMESTAMP
);

View File

@@ -751,3 +751,10 @@ CREATE TABLE versionitem
version_summary VARCHAR2(255),
versionhistory_id INTEGER REFERENCES VersionHistory(versionhistory_id)
);
CREATE TABLE Webapp
(
AppName VARCHAR(32) NOT NULL PRIMARY KEY,
URL VARCHAR NOT NULL,
Started TIMESTAMP
);

View File

@@ -798,9 +798,9 @@ CREATE TABLE versionitem
versionhistory_id INTEGER REFERENCES VersionHistory(versionhistory_id)
);
CREATE TABLE Webapp
(
AppName VARCHAR(32) NOT NULL PRIMARY KEY,
URL VARCHAR NOT NULL,
Started TIMESTAMP
);

View File

@@ -710,7 +710,7 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<version>2.5</version>
</dependency>
<dependency>