Make SWORD module configurable via sword-server.cfg. Remove obsolete web.xml

This commit is contained in:
Tim Donohue
2018-11-28 18:19:15 +00:00
parent fa61b737db
commit adf68447e1
3 changed files with 56 additions and 96 deletions

View File

@@ -7,42 +7,71 @@
*/
package org.dspace.app.configuration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* SWORD webapp configuration. Replaces the old web.xml
* <p>
* This @Configuration class is automatically discovered by Spring via a @ComponentScan.
* <p>
* All SWORD web configurations (beans) can be enabled or disabled by setting "sword-server.enabled"
* to true or false, respectively (in your DSpace configuration). Default is "false".
* <p>
* All @Value annotated configurations below can also be overridden in your DSpace configuration.
*
* @author Tim Donohue
*/
@Configuration
public class SWORDWebConfig {
// Path where SWORD should be deployed (when enabled). Defaults to "sword"
@Value("${sword-server.path:sword}")
private String swordPath;
// SWORD Server class. Defaults to "org.dspace.sword.DSpaceSWORDServer"
@Value("${sword-server.class:org.dspace.sword.DSpaceSWORDServer}")
private String serverClass;
// SWORD Authentication Method. Defaults to "Basic"
@Value("${sword-server.authentication-method:Basic}")
private String authenticationMethod;
@Bean
@ConditionalOnProperty("sword-server.enabled")
public ServletContextInitializer swordv1ContextInitializer() {
return servletContext -> {
servletContext.setInitParameter("sword-server-class", "org.dspace.sword.DSpaceSWORDServer");
servletContext.setInitParameter("authentication-method", "Basic");
servletContext.setInitParameter("sword-server-class", serverClass);
servletContext.setInitParameter("authentication-method", authenticationMethod);
};
}
@Bean
@ConditionalOnProperty("sword-server.enabled")
public ServletRegistrationBean swordv1ServiceDocumentBean() {
ServletRegistrationBean bean = new ServletRegistrationBean( new org.purl.sword.server.ServiceDocumentServlet(),
"/sword/servicedocument/*");
"/" + swordPath + "/servicedocument/*");
bean.setLoadOnStartup(1);
return bean;
}
@Bean
@ConditionalOnProperty("sword-server.enabled")
public ServletRegistrationBean swordv1DepositBean() {
ServletRegistrationBean bean = new ServletRegistrationBean( new org.purl.sword.server.DepositServlet(),
"/sword/deposit/*");
"/" + swordPath + "/deposit/*");
bean.setLoadOnStartup(1);
return bean;
}
@Bean
@ConditionalOnProperty("sword-server.enabled")
public ServletRegistrationBean swordv1MediaLinkBean() {
ServletRegistrationBean bean = new ServletRegistrationBean( new org.purl.sword.server.AtomDocumentServlet(),
"/sword/media-link/*");
"/" + swordPath + "/media-link/*");
bean.setLoadOnStartup(1);
return bean;
}

View File

@@ -1,91 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
The contents of this file are subject to the license and copyright
detailed in the LICENSE and NOTICE files at the root of the source
tree and available online at
http://www.dspace.org/license/
-->
<web-app id="DSpace-SWORDv1" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>DSpace SWORD Server</display-name>
<!-- ConfigurationService initialization for dspace.dir -->
<context-param>
<description>The location of the DSpace home directory</description>
<param-name>dspace.dir</param-name>
<param-value>${dspace.dir}</param-value>
</context-param>
<context-param>
<description>The SWORDServer class name</description>
<param-name>sword-server-class</param-name>
<param-value>org.dspace.sword.DSpaceSWORDServer</param-value>
</context-param>
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>${dspace.dir}/config/log4j2.xml</param-value>
<description>
The location of the Log4J configuration
</description>
</context-param>
<context-param>
<description>The type of authentication used : [Basic|None]</description>
<param-name>authentication-method</param-name>
<param-value>Basic</param-value>
</context-param>
<!--
Listener to initialise DSpace configuration and clean up the application
-->
<listener>
<listener-class>
org.dspace.app.util.DSpaceContextListener
</listener-class>
</listener>
<listener>
<listener-class>
org.dspace.servicemanager.servlet.DSpaceKernelServletContextListener
</listener-class>
</listener>
<!-- Servlets -->
<servlet>
<servlet-name>servicedocument</servlet-name>
<servlet-class>org.purl.sword.server.ServiceDocumentServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>deposit</servlet-name>
<servlet-class>org.purl.sword.server.DepositServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>media-link</servlet-name>
<servlet-class>org.purl.sword.server.AtomDocumentServlet</servlet-class>
</servlet>
<!-- Servlet Mappings -->
<servlet-mapping>
<servlet-name>servicedocument</servlet-name>
<url-pattern>/servicedocument/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>deposit</servlet-name>
<url-pattern>/deposit/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>media-link</servlet-name>
<url-pattern>/media-link/*</url-pattern>
</servlet-mapping>
</web-app>

View File

@@ -6,6 +6,28 @@
# SWORD protocol) #
#---------------------------------------------------------------#
# Whether or not to enable the SWORD v1 module
# When "true", the SWORD module is accessible on ${sword-server.path}
# When "false" or commented out, SWORD is disabled/inaccessible.
# (Requires reboot of servlet container, e.g. Tomcat, to reload)
#sword-server.enabled = true
# Path where SWORD v1 module is available (in the Spring REST webapp)
# Defaults to "sword", which means the SWORD mould would be available
# at ${dspace.restURL}/sword/
# (Requires reboot of servlet container, e.g. Tomcat, to reload)
#sword-server.path = sword
# The SWORDServer class name (in charge of all SWORD activities)
# This Java class must implement 'org.purl.sword.server.SWORDServer'
# (Requires reboot of servlet container, e.g. Tomcat, to reload)
#sword-server.class = org.dspace.sword.DSpaceSWORDServer
# The Authentication Method SWORD should use.
# Valid values are "Basic" or "None". Default is "Basic"
# (Requires reboot of servlet container, e.g. Tomcat, to reload)
#sword-server.authentication-method = Basic
# tell the SWORD METS implementation which package ingester to use
# to install deposited content. This should refer to one of the
# classes configured for: