DATAREST-720 - HAL Browser fragment now considers the context path if set.

Removed some obsolete Maven dependency versions along the way.
This commit is contained in:
Oliver Gierke
2016-04-01 12:59:37 +02:00
parent 877070a56f
commit 29783fe23e
3 changed files with 23 additions and 13 deletions

View File

@@ -7,6 +7,7 @@
<artifactId>spring-data-rest-parent</artifactId>
<version>2.4.5.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-data-rest-hal-browser</artifactId>
<name>Spring Data REST - HAL Browser</name>
@@ -28,7 +29,7 @@
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
@@ -54,7 +55,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack-hal-browser</id>
@@ -94,7 +94,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>process-resources</phase>

View File

@@ -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);
}
}

View File

@@ -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.<String, Object> 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"));
}
}