From 7a11d0d6051b46fc84aecdde58b2154fcec875c5 Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Fri, 11 Mar 2022 12:16:11 -0600 Subject: [PATCH] Replace Spring Data REST HAL Browser with HAL Browser from WebJars --- dspace-server-webapp/README.md | 5 ++- dspace-server-webapp/pom.xml | 37 +++++-------------- .../java/org/dspace/app/rest/Application.java | 21 ++++++++++- pom.xml | 5 +-- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/dspace-server-webapp/README.md b/dspace-server-webapp/README.md index e71039308a..8d3853e8cc 100644 --- a/dspace-server-webapp/README.md +++ b/dspace-server-webapp/README.md @@ -22,7 +22,10 @@ The only tested way right now is to run this webapp inside your IDE (Eclipse). J > dspace.dir = d:/install/dspace7 ## HAL Browser -The modified version of the HAL Browser from the Spring Data REST project is included, the index.html file is overriden locally to support the /api baseURL (see [DATAREST-971](https://jira.spring.io/browse/DATAREST-971)) + +The modified version of the HAL Browser from https://github.com/mikekelly/hal-browser + +We've updated/customized the HAL Browser to integrate better with our authentication system, provide CSRF support, and use a more recent version of its dependencies. ## Packages and main classes *[org.dspace.app.rest.Application](src/main/java/org/dspace/app/rest/Application.java)* is the spring boot main class it initializes diff --git a/dspace-server-webapp/pom.xml b/dspace-server-webapp/pom.xml index 6c34e11a81..e83e411d39 100644 --- a/dspace-server-webapp/pom.xml +++ b/dspace-server-webapp/pom.xml @@ -238,24 +238,7 @@ - - - - - - + org.springframework.boot spring-boot-starter-web @@ -293,17 +276,15 @@ 0.4.6 - + + + - org.springframework.data - spring-data-rest-hal-browser - ${spring-hal-browser.version} - - - org.springframework.data - spring-data-rest-webmvc - - + org.webjars + hal-browser + ad9b865 diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/Application.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/Application.java index e0ea0cccb0..459cfe0dee 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/Application.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/Application.java @@ -40,6 +40,7 @@ import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** @@ -192,13 +193,31 @@ public class Application extends SpringBootServletInitializer { } } + /** + * Add a ViewController for the root path, to load HAL Browser + * @param registry ViewControllerRegistry + */ + @Override + public void addViewControllers(ViewControllerRegistry registry) { + // Ensure accessing the root path will load the index.html of the HAL Browser + registry.addViewController("/").setViewName("forward:/index.html"); + } + /** * Add a new ResourceHandler to allow us to use WebJars.org to pull in web dependencies - * dynamically for HAL Browser, and access them off the /webjars path. + * dynamically for HAL Browser, etc. * @param registry ResourceHandlerRegistry */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { + // First, "mount" the Hal Browser resources at the /browser path + // NOTE: the hal-browser directory uses the version of the Hal browser, so this needs to be synced + // with the org.webjars.hal-browser version in the POM + registry + .addResourceHandler("/browser/**") + .addResourceLocations("/webjars/hal-browser/ad9b865/"); + + // Make all other Webjars available off the /webjars path registry .addResourceHandler("/webjars/**") .addResourceLocations("/webjars/"); diff --git a/pom.xml b/pom.xml index 7aa5fc9dad..9da639b710 100644 --- a/pom.xml +++ b/pom.xml @@ -46,8 +46,6 @@ 1.70 - - 3.3.9.RELEASE 2.6.0 com.jayway.jsonpath json-path ${json-path.version} - test + com.jayway.jsonpath json-path-assert