diff --git a/spring-data-rest-hal-browser/pom.xml b/spring-data-rest-hal-browser/pom.xml
index b8546a029..ccb2e7de0 100644
--- a/spring-data-rest-hal-browser/pom.xml
+++ b/spring-data-rest-hal-browser/pom.xml
@@ -7,6 +7,7 @@
spring-data-rest-parent
2.4.5.BUILD-SNAPSHOT
+
spring-data-rest-hal-browser
Spring Data REST - HAL Browser
@@ -28,7 +29,7 @@
javax.servlet
javax.servlet-api
3.0.1
- test
+ provided
@@ -54,7 +55,6 @@
org.apache.maven.plugins
maven-dependency-plugin
- 2.10
unpack-hal-browser
@@ -94,7 +94,6 @@
org.apache.maven.plugins
maven-antrun-plugin
- 1.7
process-resources
diff --git a/spring-data-rest-hal-browser/src/main/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowser.java b/spring-data-rest-hal-browser/src/main/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowser.java
index ee43bb862..2037eaa71 100644
--- a/spring-data-rest-hal-browser/src/main/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowser.java
+++ b/spring-data-rest-hal-browser/src/main/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 the original author or authors.
+ * Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
*/
package org.springframework.data.rest.webmvc.halbrowser;
+import javax.servlet.http.HttpServletRequest;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.BasePathAwareController;
@@ -58,8 +60,8 @@ public class HalBrowser {
* @return
*/
@RequestMapping(value = { "/", "" }, method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
- public View index() {
- return browser();
+ public View index(HttpServletRequest request) {
+ return browser(request);
}
/**
@@ -68,9 +70,11 @@ public class HalBrowser {
* @return
*/
@RequestMapping(value = "/browser", method = RequestMethod.GET)
- public View browser() {
+ public View browser(HttpServletRequest request) {
+ String contextPath = request.getContextPath();
String basePath = configuration.getBasePath().toString();
- return new RedirectView(basePath.concat(BROWSER_INDEX).concat("#").concat(basePath), true);
+
+ return new RedirectView(basePath.concat(BROWSER_INDEX).concat("#").concat(contextPath.concat(basePath)), true);
}
}
diff --git a/spring-data-rest-hal-browser/src/test/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowserUnitTests.java b/spring-data-rest-hal-browser/src/test/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowserUnitTests.java
index 33566955c..2b4aa943f 100644
--- a/spring-data-rest-hal-browser/src/test/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowserUnitTests.java
+++ b/spring-data-rest-hal-browser/src/test/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowserUnitTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 the original author or authors.
+ * Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,8 @@ import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.AbstractView;
import org.springframework.web.servlet.view.RedirectView;
+import org.springframework.web.util.UriComponents;
+import org.springframework.web.util.UriComponentsBuilder;
/**
* Unit tests for {@link HalBrowser}.
@@ -44,22 +46,27 @@ public class HalBrowserUnitTests {
/**
* @see DATAREST-565
+ * @see DATAREST-720
*/
@Test
public void createsContextRelativeRedirectForBrowser() throws Exception {
RepositoryRestConfiguration configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
- View view = new HalBrowser(configuration).browser();
-
- assertThat(view, is(instanceOf(RedirectView.class)));
MockHttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("/context");
+ View view = new HalBrowser(configuration).browser(request);
+
+ assertThat(view, is(instanceOf(RedirectView.class)));
+
((AbstractView) view).render(Collections. emptyMap(), request, response);
- assertThat(response.getHeader(HttpHeaders.LOCATION), Matchers.startsWith("/context"));
+ UriComponents components = UriComponentsBuilder.fromUriString(response.getHeader(HttpHeaders.LOCATION)).build();
+
+ assertThat(components.getPath(), Matchers.startsWith("/context"));
+ assertThat(components.getFragment(), is("/context"));
}
}