Rename Endpoint path to ID
This commit is contained in:
parent
451acb5679
commit
43b820a7d3
|
|
@ -29,23 +29,32 @@ import javax.validation.constraints.Pattern;
|
|||
public abstract class AbstractEndpoint<T> implements Endpoint<T> {
|
||||
|
||||
@NotNull
|
||||
@Pattern(regexp = "/[^/]*", message = "Path must start with /")
|
||||
private String path;
|
||||
@Pattern(regexp = "\\w+", message = "ID must only contains letters, numbers and '_'")
|
||||
private String id;
|
||||
|
||||
private boolean sensitive;
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
public AbstractEndpoint(String path) {
|
||||
this(path, true, true);
|
||||
public AbstractEndpoint(String id) {
|
||||
this(id, true, true);
|
||||
}
|
||||
|
||||
public AbstractEndpoint(String path, boolean sensitive, boolean enabled) {
|
||||
this.path = path;
|
||||
public AbstractEndpoint(String id, boolean sensitive, boolean enabled) {
|
||||
this.id = id;
|
||||
this.sensitive = sensitive;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
|
@ -54,15 +63,6 @@ public abstract class AbstractEndpoint<T> implements Endpoint<T> {
|
|||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSensitive() {
|
||||
return this.sensitive;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class AutoConfigurationReportEndpoint extends AbstractEndpoint<Report> {
|
|||
private AutoConfigurationReport autoConfigurationReport;
|
||||
|
||||
public AutoConfigurationReportEndpoint() {
|
||||
super("/autoconfig");
|
||||
super("autoconfig");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class BeansEndpoint extends AbstractEndpoint<List<Object>> implements
|
|||
private JsonParser parser = JsonParserFactory.getJsonParser();
|
||||
|
||||
public BeansEndpoint() {
|
||||
super("/beans");
|
||||
super("beans");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class ConfigurationPropertiesReportEndpoint extends
|
|||
private ApplicationContext context;
|
||||
|
||||
public ConfigurationPropertiesReportEndpoint() {
|
||||
super("/configprops");
|
||||
super("configprops");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class DumpEndpoint extends AbstractEndpoint<List<ThreadInfo>> {
|
|||
* Create a new {@link DumpEndpoint} instance.
|
||||
*/
|
||||
public DumpEndpoint() {
|
||||
super("/dump");
|
||||
super("dump");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -27,13 +27,18 @@ package org.springframework.boot.actuate.endpoint;
|
|||
public interface Endpoint<T> {
|
||||
|
||||
/**
|
||||
* Returns the path of the endpoint. Must start with '/' and should not include
|
||||
* wildcards.
|
||||
* The logical ID of the endpoint. Must only contain simple letters, numbers and '_'
|
||||
* characters (ie a {@literal "\w"} regex).
|
||||
*/
|
||||
String getPath();
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Returns if the endpoint is sensitive, i.e. may return data that the average user
|
||||
* Return if the endpoint is enabled.
|
||||
*/
|
||||
boolean isEnabled();
|
||||
|
||||
/**
|
||||
* Return if the endpoint is sensitive, i.e. may return data that the average user
|
||||
* should not see. Mappings can use this as a security hint.
|
||||
*/
|
||||
boolean isSensitive();
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> i
|
|||
* Create a new {@link EnvironmentEndpoint} instance.
|
||||
*/
|
||||
public EnvironmentEndpoint() {
|
||||
super("/env");
|
||||
super("env");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -36,15 +36,11 @@ public class HealthEndpoint<T> extends AbstractEndpoint<T> {
|
|||
* @param indicator the health indicator
|
||||
*/
|
||||
public HealthEndpoint(HealthIndicator<? extends T> indicator) {
|
||||
super("/health", false, true);
|
||||
super("health", false, true);
|
||||
Assert.notNull(indicator, "Indicator must not be null");
|
||||
this.indicator = indicator;
|
||||
}
|
||||
|
||||
HealthEndpoint() {
|
||||
super("/health", false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T invoke() {
|
||||
return this.indicator.health();
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class InfoEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
|||
* @param info the info to expose
|
||||
*/
|
||||
public InfoEndpoint(Map<String, ? extends Object> info) {
|
||||
super("/info", false, true);
|
||||
super("info", false, true);
|
||||
Assert.notNull(info, "Info must not be null");
|
||||
this.info = info;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class MetricsEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
|||
* @param metrics the metrics to expose
|
||||
*/
|
||||
public MetricsEndpoint(PublicMetrics metrics) {
|
||||
super("/metrics");
|
||||
super("metrics");
|
||||
Assert.notNull(metrics, "Metrics must not be null");
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>> impl
|
|||
* Create a new {@link ShutdownEndpoint} instance.
|
||||
*/
|
||||
public ShutdownEndpoint() {
|
||||
super("/shutdown", true, false);
|
||||
super("shutdown", true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class TraceEndpoint extends AbstractEndpoint<List<Trace>> {
|
|||
* @param repository the trace repository
|
||||
*/
|
||||
public TraceEndpoint(TraceRepository repository) {
|
||||
super("/trace");
|
||||
super("trace");
|
||||
Assert.notNull(repository, "Repository must not be null");
|
||||
this.repository = repository;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
|||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
/**
|
||||
* {@link HandlerMapping} to map {@link Endpoint}s to URLs via {@link Endpoint#getPath()}.
|
||||
* {@link HandlerMapping} to map {@link Endpoint}s to URLs via {@link Endpoint#getId()}.
|
||||
* Only endpoints that are annotated as <code>@FrameworkEndpoint</code> will be mapped,
|
||||
* and within that class only those methods with <code>@RequestMapping</code> will be
|
||||
* exposed. The semantics of <code>@RequestMapping</code> should be identical to a normal
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class GenericMvcEndpoint implements MvcEndpoint {
|
|||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return this.delegate.getPath();
|
||||
return "/" + this.delegate.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -42,17 +42,17 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
|
|||
|
||||
private final Class<?> type;
|
||||
|
||||
private final String path;
|
||||
private final String id;
|
||||
|
||||
private final boolean sensitive;
|
||||
|
||||
private final String property;
|
||||
|
||||
public AbstractEndpointTests(Class<?> configClass, Class<?> type, String path,
|
||||
public AbstractEndpointTests(Class<?> configClass, Class<?> type, String id,
|
||||
boolean sensitive, String property) {
|
||||
this.configClass = configClass;
|
||||
this.type = type;
|
||||
this.path = path;
|
||||
this.id = id;
|
||||
this.sensitive = sensitive;
|
||||
this.property = property;
|
||||
}
|
||||
|
|
@ -72,8 +72,8 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getPath() throws Exception {
|
||||
assertThat(getEndpointBean().getPath(), equalTo(this.path));
|
||||
public void getId() throws Exception {
|
||||
assertThat(getEndpointBean().getId(), equalTo(this.id));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -82,12 +82,12 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void pathOverride() throws Exception {
|
||||
public void idOverride() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
TestUtils.addEnviroment(this.context, this.property + ".path:/mypath");
|
||||
TestUtils.addEnviroment(this.context, this.property + ".id:myid");
|
||||
this.context.register(this.configClass);
|
||||
this.context.refresh();
|
||||
assertThat(getEndpointBean().getPath(), equalTo("/mypath"));
|
||||
assertThat(getEndpointBean().getId(), equalTo("myid"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class AutoConfigurationReportEndpointTests extends
|
|||
AbstractEndpointTests<AutoConfigurationReportEndpoint> {
|
||||
|
||||
public AutoConfigurationReportEndpointTests() {
|
||||
super(Config.class, AutoConfigurationReportEndpoint.class, "/autoconfig", true,
|
||||
super(Config.class, AutoConfigurationReportEndpoint.class, "autoconfig", true,
|
||||
"endpoints.autoconfig");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import static org.junit.Assert.assertTrue;
|
|||
public class BeansEndpointTests extends AbstractEndpointTests<BeansEndpoint> {
|
||||
|
||||
public BeansEndpointTests() {
|
||||
super(Config.class, BeansEndpoint.class, "/beans", true, "endpoints.beans");
|
||||
super(Config.class, BeansEndpoint.class, "beans", true, "endpoints.beans");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class ConfigurationPropertiesReportEndpointTests extends
|
|||
AbstractEndpointTests<ConfigurationPropertiesReportEndpoint> {
|
||||
|
||||
public ConfigurationPropertiesReportEndpointTests() {
|
||||
super(Config.class, ConfigurationPropertiesReportEndpoint.class, "/configprops",
|
||||
super(Config.class, ConfigurationPropertiesReportEndpoint.class, "configprops",
|
||||
true, "endpoints.configprops");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import java.lang.management.ThreadInfo;
|
|||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.actuate.endpoint.DumpEndpoint;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
|
@ -36,7 +35,7 @@ import static org.junit.Assert.assertThat;
|
|||
public class DumpEndpointTests extends AbstractEndpointTests<DumpEndpoint> {
|
||||
|
||||
public DumpEndpointTests() {
|
||||
super(Config.class, DumpEndpoint.class, "/dump", true, "endpoints.dump");
|
||||
super(Config.class, DumpEndpoint.class, "dump", true, "endpoints.dump");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import static org.junit.Assert.assertThat;
|
|||
public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentEndpoint> {
|
||||
|
||||
public EnvironmentEndpointTests() {
|
||||
super(Config.class, EnvironmentEndpoint.class, "/env", true, "endpoints.env");
|
||||
super(Config.class, EnvironmentEndpoint.class, "env", true, "endpoints.env");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.boot.actuate.endpoint;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.actuate.endpoint.HealthEndpoint;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
|
@ -34,7 +33,7 @@ import static org.junit.Assert.assertThat;
|
|||
public class HealthEndpointTests extends AbstractEndpointTests<HealthEndpoint<String>> {
|
||||
|
||||
public HealthEndpointTests() {
|
||||
super(Config.class, HealthEndpoint.class, "/health", false, "endpoints.health");
|
||||
super(Config.class, HealthEndpoint.class, "health", false, "endpoints.health");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import static org.junit.Assert.assertThat;
|
|||
public class InfoEndpointTests extends AbstractEndpointTests<InfoEndpoint> {
|
||||
|
||||
public InfoEndpointTests() {
|
||||
super(Config.class, InfoEndpoint.class, "/info", false, "endpoints.info");
|
||||
super(Config.class, InfoEndpoint.class, "info", false, "endpoints.info");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.actuate.endpoint.MetricsEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.PublicMetrics;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
|
@ -38,7 +36,7 @@ import static org.junit.Assert.assertThat;
|
|||
public class MetricsEndpointTests extends AbstractEndpointTests<MetricsEndpoint> {
|
||||
|
||||
public MetricsEndpointTests() {
|
||||
super(Config.class, MetricsEndpoint.class, "/metrics", true, "endpoints.metrics");
|
||||
super(Config.class, MetricsEndpoint.class, "metrics", true, "endpoints.metrics");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import static org.junit.Assert.assertTrue;
|
|||
public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoint> {
|
||||
|
||||
public ShutdownEndpointTests() {
|
||||
super(Config.class, ShutdownEndpoint.class, "/shutdown", true,
|
||||
super(Config.class, ShutdownEndpoint.class, "shutdown", true,
|
||||
"endpoints.shutdown");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package org.springframework.boot.actuate.endpoint;
|
|||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.actuate.endpoint.TraceEndpoint;
|
||||
import org.springframework.boot.actuate.trace.InMemoryTraceRepository;
|
||||
import org.springframework.boot.actuate.trace.Trace;
|
||||
import org.springframework.boot.actuate.trace.TraceRepository;
|
||||
|
|
@ -38,7 +37,7 @@ import static org.junit.Assert.assertThat;
|
|||
public class TraceEndpointTests extends AbstractEndpointTests<TraceEndpoint> {
|
||||
|
||||
public TraceEndpointTests() {
|
||||
super(Config.class, TraceEndpoint.class, "/trace", true, "endpoints.trace");
|
||||
super(Config.class, TraceEndpoint.class, "trace", true, "endpoints.trace");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -167,11 +167,11 @@ public class EndpointMBeanExporterTests {
|
|||
public static class TestEndpoint extends AbstractEndpoint<String> {
|
||||
|
||||
public TestEndpoint() {
|
||||
super("/test");
|
||||
super("test");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInvoke() {
|
||||
public String invoke() {
|
||||
return "hello world";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue