mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-10 11:33:11 +00:00
[DS-1456] Make webapp.s register in a new database table when started, so we can
list them later.
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
package org.dspace.app.util;
|
package org.dspace.app.util;
|
||||||
|
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.dspace.storage.rdbms.DatabaseManager;
|
import org.dspace.storage.rdbms.DatabaseManager;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
@@ -19,26 +20,35 @@ import java.net.URL;
|
|||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.sql.Driver;
|
import java.sql.Driver;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to initialize / cleanup resources used by DSpace when the web application
|
* 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
|
public class DSpaceContextListener implements ServletContextListener
|
||||||
{
|
{
|
||||||
private static Logger log = Logger.getLogger(DSpaceContextListener.class);
|
private static Logger log = Logger.getLogger(DSpaceContextListener.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DSpace config parameter, this is where the path to the DSpace
|
* Name of the context parameter giving the path to the DSpace configuration file.
|
||||||
* configuration file can be obtained
|
|
||||||
*/
|
*/
|
||||||
public static final String DSPACE_CONFIG_PARAMETER = "dspace-config";
|
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
|
* @param event
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent event)
|
public void contextInitialized(ServletContextEvent event)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -114,6 +124,37 @@ public class DSpaceContextListener implements ServletContextListener
|
|||||||
"either the local servlet or global context.\n\n",e);
|
"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
|
* @param event
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent event)
|
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
|
try
|
||||||
{
|
{
|
||||||
// Remove the database pool
|
// Remove the database pool
|
||||||
|
@@ -51,6 +51,11 @@
|
|||||||
<param-value>/WEB-INF/spring/*.xml</param-value>
|
<param-value>/WEB-INF/spring/*.xml</param-value>
|
||||||
</context-param>
|
</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 -->
|
<!-- Filters -->
|
||||||
|
|
||||||
|
@@ -21,6 +21,12 @@
|
|||||||
</description>
|
</description>
|
||||||
</context-param>
|
</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
|
Listener to initialise DSpace configuration and clean up the application
|
||||||
-->
|
-->
|
||||||
|
@@ -30,6 +30,12 @@
|
|||||||
<param-value>${dspace.dir}</param-value>
|
<param-value>${dspace.dir}</param-value>
|
||||||
</context-param>
|
</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>
|
||||||
<listener-class>
|
<listener-class>
|
||||||
org.dspace.app.util.DSpaceContextListener
|
org.dspace.app.util.DSpaceContextListener
|
||||||
|
@@ -49,6 +49,12 @@
|
|||||||
</description>
|
</description>
|
||||||
</context-param>
|
</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
|
Listener to initialise DSpace configuration and clean up the application
|
||||||
-->
|
-->
|
||||||
|
@@ -31,6 +31,12 @@
|
|||||||
<param-value>${dspace.dir}</param-value>
|
<param-value>${dspace.dir}</param-value>
|
||||||
</context-param>
|
</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 -->
|
<!-- Configuration Information -->
|
||||||
|
|
||||||
<context-param>
|
<context-param>
|
||||||
|
@@ -55,6 +55,12 @@
|
|||||||
<param-value>/WEB-INF/spring/*.xml</param-value>
|
<param-value>/WEB-INF/spring/*.xml</param-value>
|
||||||
</context-param>
|
</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
|
- Use the Cocoon debug filter together with the Cocoon demo webapp
|
||||||
<filter-mapping>
|
<filter-mapping>
|
||||||
|
@@ -807,8 +807,9 @@ CREATE TABLE versionitem
|
|||||||
CREATE SEQUENCE versionitem_seq;
|
CREATE SEQUENCE versionitem_seq;
|
||||||
CREATE SEQUENCE versionhistory_seq;
|
CREATE SEQUENCE versionhistory_seq;
|
||||||
|
|
||||||
|
CREATE TABLE Webapp
|
||||||
|
(
|
||||||
|
AppName VARCHAR(32) NOT NULL PRIMARY KEY,
|
||||||
|
URL VARCHAR NOT NULL,
|
||||||
|
Started TIMESTAMP
|
||||||
|
);
|
||||||
|
@@ -751,3 +751,10 @@ CREATE TABLE versionitem
|
|||||||
version_summary VARCHAR2(255),
|
version_summary VARCHAR2(255),
|
||||||
versionhistory_id INTEGER REFERENCES VersionHistory(versionhistory_id)
|
versionhistory_id INTEGER REFERENCES VersionHistory(versionhistory_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Webapp
|
||||||
|
(
|
||||||
|
AppName VARCHAR(32) NOT NULL PRIMARY KEY,
|
||||||
|
URL VARCHAR NOT NULL,
|
||||||
|
Started TIMESTAMP
|
||||||
|
);
|
||||||
|
@@ -798,9 +798,9 @@ CREATE TABLE versionitem
|
|||||||
versionhistory_id INTEGER REFERENCES VersionHistory(versionhistory_id)
|
versionhistory_id INTEGER REFERENCES VersionHistory(versionhistory_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Webapp
|
||||||
|
(
|
||||||
|
AppName VARCHAR(32) NOT NULL PRIMARY KEY,
|
||||||
|
URL VARCHAR NOT NULL,
|
||||||
|
Started TIMESTAMP
|
||||||
|
);
|
||||||
|
2
pom.xml
2
pom.xml
@@ -710,7 +710,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>servlet-api</artifactId>
|
<artifactId>servlet-api</artifactId>
|
||||||
<version>2.4</version>
|
<version>2.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
Reference in New Issue
Block a user