Consider custom server.context-path when configuring dev tools endpoints

Previously, the auto-configuration of DevTools’ debug, restart, and
health handlers assumed that the server was running on its default
context path and, if server.context-path was set to a non-default value,
the handlers would not work as expected.

This commit updates the auto-configuration of the three handlers to 
consider the server’s context path when configuring their URIs. Now,
when a custom server context path is used, no further configuration is
required other than the inclusion of that context path when providing
the remote URL as an argument to RemoteSpringApplication.

Closes gh-4301
This commit is contained in:
Andy Wilkinson
2015-10-28 17:22:39 +00:00
parent b5246af148
commit 0adf037410
2 changed files with 53 additions and 4 deletions

View File

@@ -137,6 +137,17 @@ public class RemoteDevToolsAutoConfigurationTests {
assertRestartInvoked(true);
}
@Test
public void invokeRestartWithCustomServerContextPath() throws Exception {
loadContext("spring.devtools.remote.secret:supersecret",
"server.context-path:/test");
DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
this.request.setRequestURI("/test" + DEFAULT_CONTEXT_PATH + "/restart");
this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret");
filter.doFilter(this.request, this.response, this.chain);
assertRestartInvoked(true);
}
@Test
public void disableRestart() throws Exception {
loadContext("spring.devtools.remote.secret:supersecret",
@@ -155,6 +166,17 @@ public class RemoteDevToolsAutoConfigurationTests {
assertTunnelInvoked(true);
}
@Test
public void invokeTunnelWithCustomServerContextPath() throws Exception {
loadContext("spring.devtools.remote.secret:supersecret",
"server.context-path:/test");
DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
this.request.setRequestURI("/test" + DEFAULT_CONTEXT_PATH + "/debug");
this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret");
filter.doFilter(this.request, this.response, this.chain);
assertTunnelInvoked(true);
}
@Test
public void invokeTunnelWithCustomHeaderName() throws Exception {
loadContext("spring.devtools.remote.secret:supersecret",
@@ -185,6 +207,18 @@ public class RemoteDevToolsAutoConfigurationTests {
assertThat(this.response.getStatus(), equalTo(200));
}
@Test
public void devToolsHealthWithCustomServerContextPathReturns200() throws Exception {
loadContext("spring.devtools.remote.secret:supersecret",
"server.context-path:/test");
DispatcherFilter filter = this.context.getBean(DispatcherFilter.class);
this.request.setRequestURI("/test" + DEFAULT_CONTEXT_PATH);
this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret");
this.response.setStatus(500);
filter.doFilter(this.request, this.response, this.chain);
assertThat(this.response.getStatus(), equalTo(200));
}
private void assertTunnelInvoked(boolean value) {
assertThat(this.context.getBean(MockHttpTunnelServer.class).invoked,
equalTo(value));