Skip to content

Commit

Permalink
Replace Spring Data REST HAL Browser with HAL Browser from WebJars
Browse files Browse the repository at this point in the history
  • Loading branch information
tdonohue committed Mar 11, 2022
1 parent 2581a3f commit dd77619
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
5 changes: 4 additions & 1 deletion dspace-server-webapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 9 additions & 28 deletions dspace-server-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -286,17 +269,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 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
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;

/**
Expand Down Expand Up @@ -192,13 +193,31 @@ public void addCorsMappings(@NonNull CorsRegistry registry) {
}
}

/**
* 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/");
Expand Down
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
<slf4j.version>1.7.25</slf4j.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
Expand Down Expand Up @@ -1761,12 +1759,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>
Expand Down

0 comments on commit dd77619

Please sign in to comment.