diff --git a/dspace-sword/src/main/java/org/dspace/app/configuration/SWORDWebConfig.java b/dspace-sword/src/main/java/org/dspace/app/configuration/SWORDWebConfig.java index 516cbec125..4d1578385b 100644 --- a/dspace-sword/src/main/java/org/dspace/app/configuration/SWORDWebConfig.java +++ b/dspace-sword/src/main/java/org/dspace/app/configuration/SWORDWebConfig.java @@ -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 + *

+ * This @Configuration class is automatically discovered by Spring via a @ComponentScan. + *

+ * 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". + *

+ * 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; } diff --git a/dspace-sword/src/main/webapp/WEB-INF/web.xml b/dspace-sword/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 14b873ccd9..0000000000 --- a/dspace-sword/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,91 +0,0 @@ - - - - - DSpace SWORD Server - - - - The location of the DSpace home directory - dspace.dir - ${dspace.dir} - - - - The SWORDServer class name - sword-server-class - org.dspace.sword.DSpaceSWORDServer - - - - log4jConfiguration - ${dspace.dir}/config/log4j2.xml - - The location of the Log4J configuration - - - - - The type of authentication used : [Basic|None] - authentication-method - Basic - - - - - - org.dspace.app.util.DSpaceContextListener - - - - - org.dspace.servicemanager.servlet.DSpaceKernelServletContextListener - - - - - - servicedocument - org.purl.sword.server.ServiceDocumentServlet - - - - deposit - org.purl.sword.server.DepositServlet - - - - media-link - org.purl.sword.server.AtomDocumentServlet - - - - - - servicedocument - /servicedocument/* - - - - deposit - /deposit/* - - - - media-link - /media-link/* - - - diff --git a/dspace/config/modules/sword-server.cfg b/dspace/config/modules/sword-server.cfg index 6c6778d9c7..0da35ba881 100644 --- a/dspace/config/modules/sword-server.cfg +++ b/dspace/config/modules/sword-server.cfg @@ -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: