Commit c4d8fb1c authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '1.4.x' into 1.5.x

parents f6959ccb 88d95260
...@@ -44,6 +44,11 @@ ...@@ -44,6 +44,11 @@
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
...@@ -81,6 +86,12 @@ ...@@ -81,6 +86,12 @@
<dependency> <dependency>
<groupId>org.springframework.hateoas</groupId> <groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId> <artifactId>spring-hateoas</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.restdocs</groupId> <groupId>org.springframework.restdocs</groupId>
......
...@@ -57,13 +57,15 @@ HAL browser is not active). ...@@ -57,13 +57,15 @@ HAL browser is not active).
== Hypermedia Support == Hypermedia Support
If https://projects.spring.io/spring-hateoas[Spring HATEOAS] is enabled (i.e. if it is If `endpoints.hypermedia.enabled` is set to `true` and
on the classpath by default) then the Actuator endpoint responses are enhanced with https://projects.spring.io/spring-hateoas[Spring HATEOAS] is on the classpath (e.g.
hypermedia in the form of "links". The default media type for responses is through the `spring-boot-starter-hateoas` or if you are using
http://stateless.co/hal_specification.html[HAL], resulting in each resource having an http://projects.spring.io/spring-data-rest[Spring Data REST]) then the Actuator endpoint
extra property called "_links". You can change the media type to another one supported by responses are enhanced with hypermedia in the form of "links". The default media type for
Spring HATEOAS by providing your own `@EnableHypermedia` annotation and custom providers responses is http://stateless.co/hal_specification.html[HAL], resulting in each resource
as necessary. having an extra property called "_links". You can change the media type to another one
supported by Spring HATEOAS by providing your own `@EnableHypermedia` annotation and
custom providers as necessary.
Example enhanced "/metrics" endpoint with additional "_links": Example enhanced "/metrics" endpoint with additional "_links":
......
...@@ -33,12 +33,14 @@ import org.springframework.test.web.servlet.MockMvc; ...@@ -33,12 +33,14 @@ import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration(classes = SpringBootHypermediaApplication.class, loader = SpringBootContextLoader.class) @ContextConfiguration(classes = SpringBootHypermediaApplication.class, loader = SpringBootContextLoader.class)
@WebAppConfiguration @WebAppConfiguration
@TestPropertySource(properties = "spring.jackson.serialization.indent_output=true") @TestPropertySource(properties = { "spring.jackson.serialization.indent_output=true",
"endpoints.hypermedia.enabled=true" })
@DirtiesContext @DirtiesContext
@AutoConfigureMockMvc @AutoConfigureMockMvc
@AutoConfigureRestDocs("target/generated-snippets") @AutoConfigureRestDocs("target/generated-snippets")
...@@ -56,7 +58,10 @@ public class HypermediaEndpointDocumentation { ...@@ -56,7 +58,10 @@ public class HypermediaEndpointDocumentation {
@Test @Test
public void metrics() throws Exception { public void metrics() throws Exception {
this.mockMvc.perform(get("/metrics").accept(MediaType.APPLICATION_JSON)) this.mockMvc.perform(get("/metrics").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andDo(document("metrics/hypermedia")); .andExpect(status().isOk())
.andExpect(jsonPath("$._links.self.href")
.value("http://localhost:8080/metrics"))
.andDo(document("metrics/hypermedia"));
} }
@Test @Test
......
...@@ -47,6 +47,12 @@ ...@@ -47,6 +47,12 @@
"vcap_services" "vcap_services"
] ]
}, },
{
"name": "endpoints.hypermedia.enabled",
"type": "java.lang.Boolean",
"description": "Enable hypermedia support for endpoints.",
"defaultValue": false
},
{ {
"name": "endpoints.info.path", "name": "endpoints.info.path",
"type": "java.lang.String", "type": "java.lang.String",
......
...@@ -946,6 +946,7 @@ content into your application; rather pick only the properties that you need. ...@@ -946,6 +946,7 @@ content into your application; rather pick only the properties that you need.
endpoints.heapdump.enabled= # Enable the endpoint. endpoints.heapdump.enabled= # Enable the endpoint.
endpoints.heapdump.path= # Endpoint path. endpoints.heapdump.path= # Endpoint path.
endpoints.heapdump.sensitive= # Mark if the endpoint exposes sensitive information. endpoints.heapdump.sensitive= # Mark if the endpoint exposes sensitive information.
endpoints.hypermedia.enabled=false # Enable hypermedia support for endpoints.
endpoints.info.enabled= # Enable the endpoint. endpoints.info.enabled= # Enable the endpoint.
endpoints.info.id= # Endpoint identifier. endpoints.info.id= # Endpoint identifier.
endpoints.info.path= # Endpoint path. endpoints.info.path= # Endpoint path.
......
...@@ -203,7 +203,8 @@ For example, to mark _all_ endpoints as sensitive except `info`: ...@@ -203,7 +203,8 @@ For example, to mark _all_ endpoints as sensitive except `info`:
[[production-ready-endpoint-hypermedia]] [[production-ready-endpoint-hypermedia]]
=== Hypermedia for actuator MVC endpoints === Hypermedia for actuator MVC endpoints
If http://projects.spring.io/spring-hateoas[Spring HATEOAS] is on the classpath (e.g. If `endpoints.hypermedia.enabled` is set to `true` and
http://projects.spring.io/spring-hateoas[Spring HATEOAS] is on the classpath (e.g.
through the `spring-boot-starter-hateoas` or if you are using through the `spring-boot-starter-hateoas` or if you are using
http://projects.spring.io/spring-data-rest[Spring Data REST]) then the HTTP endpoints http://projects.spring.io/spring-data-rest[Spring Data REST]) then the HTTP endpoints
from the Actuator are enhanced with hypermedia links, and a "`discovery page`" is added from the Actuator are enhanced with hypermedia links, and a "`discovery page`" is added
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment