Replace Spring Data REST HAL Browser with HAL Browser from WebJars

This commit is contained in:
Tim Donohue
2022-03-11 12:16:11 -06:00
parent 54f2c5c661
commit 7a11d0d605
4 changed files with 35 additions and 33 deletions

View File

@@ -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

View File

@@ -238,24 +238,7 @@
<dependencies>
<!-- These next two dependencies build a WAR that is BOTH executable
AND deployable into an external container (Tomcat).
See: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#build-tool-plugins-maven-packaging -->
<!-- NOTE: For rapid development (if you don't need Solr or other webapps),
you can temporarily comment these out, and switch <packaging> to "jar".
This lets you develop in a standalone, runnable JAR application. -->
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>-->
<!-- Ensure embedded servlet container doesn't interfere when this
WAR is deployed to an external Tomcat (i.e. provided). -->
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>-->
<!-- Spring Boot dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
@@ -293,17 +276,15 @@
<version>0.4.6</version>
</dependency>
<!-- The HAL Browser -->
<!-- HAL Browser (via WebJars) : https://github.com/mikekelly/hal-browser -->
<!-- This is primarily used to pull in the HAL Browser core Javascript code ('js' folder), as we've overridden
many dependencies below and the HTML pages in src/main/webapp/ -->
<!-- NOTE: Eventually this should be replaced by the HAL Explorer included in Spring Data REST,
see https://github.com/DSpace/DSpace/issues/3017 -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
<version>${spring-hal-browser.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
</exclusion>
</exclusions>
<groupId>org.webjars</groupId>
<artifactId>hal-browser</artifactId>
<version>ad9b865</version>
</dependency>
<!-- WebJars dependencies used to update/enhance the default HAL Browser -->

View File

@@ -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/");

View File

@@ -46,8 +46,6 @@
<bouncycastle.version>1.70</bouncycastle.version>
<!--=== SERVER WEBAPP DEPENDENCIES ===-->
<!-- Spring Data REST HAL Browser (used by Server webapp) -->
<spring-hal-browser.version>3.3.9.RELEASE</spring-hal-browser.version>
<!-- Library for reading JSON documents: https://github.com/json-path/JsonPath (used by Server webapp) -->
<json-path.version>2.6.0</json-path.version>
<!-- Library for managing JSON Web Tokens (JWT): https://bitbucket.org/connect2id/nimbus-jose-jwt/wiki/Home
@@ -1753,12 +1751,13 @@
<version>1.2.5</version>
</dependency>
<!-- json-path is needed by Spring HATEOAS -->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${json-path.version}</version>
<scope>test</scope>
</dependency>
<!-- json-path-assert is just needed by tests -->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>