mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 03:13:21 +08:00
Add redirection to actuator endpoint
If a request to the actuator endpoint ends with a slash with Spring HATEOAS on the classpath, an empty array of links is returned whereas a request without the slash returns a response with all the expected links to the actuator's other endpoints. This commit adds an automatic redirection so that both URIs return the expected result. Closes gh-4575
This commit is contained in:
parent
5beeaf1760
commit
7d6f63ae34
@ -87,6 +87,11 @@ public class HalJsonMvcEndpoint extends WebMvcConfigurerAdapter
|
||||
return new ResourceSupport();
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public String forward() {
|
||||
return "redirect:" + this.managementServletContext.getContextPath() + this.path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@ -75,6 +76,13 @@ public class HalBrowserMvcEndpointManagementContextPathIntegrationTests {
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$._links").exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redirectJson() throws Exception {
|
||||
this.mockMvc.perform(get("/admin/").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isFound())
|
||||
.andExpect(header().string("location", "/admin"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void actuatorHomeHtml() throws Exception {
|
||||
this.mockMvc.perform(get("/admin/").accept(MediaType.TEXT_HTML))
|
||||
|
@ -124,7 +124,7 @@ public class MvcEndpointIntegrationTests {
|
||||
"management.context-path:/management");
|
||||
MockMvc mockMvc = createSecureMockMvc();
|
||||
mockMvc.perform(get("/management/info")).andExpect(status().isOk());
|
||||
mockMvc.perform(get("/management/")).andExpect(status().isOk());
|
||||
mockMvc.perform(get("/management")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user