Support NamedMvcEndpoints
Introduce a new NamedMvcEndpoint interface which can be used when an MvcEndpoint also has a logical name. Existing MvcEndpoints have been reworked to implement the NamedMvcEndpoint interface. Fixes gh-7156
This commit is contained in:
parent
90722a9bca
commit
7f1ff968a1
|
|
@ -30,7 +30,7 @@ import org.springframework.util.Assert;
|
|||
* @since 1.3.0
|
||||
*/
|
||||
public abstract class AbstractEndpointMvcAdapter<E extends Endpoint<?>>
|
||||
implements MvcEndpoint {
|
||||
implements NamedMvcEndpoint {
|
||||
|
||||
private final E delegate;
|
||||
|
||||
|
|
@ -60,6 +60,11 @@ public abstract class AbstractEndpointMvcAdapter<E extends Endpoint<?>>
|
|||
return this.delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.delegate.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return (this.path != null ? this.path : "/" + this.delegate.getId());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright 2012-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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.mvc;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link NamedMvcEndpoint} implementations without a backing
|
||||
* {@link Endpoint}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class AbstractNamedMvcEndpoint extends AbstractMvcEndpoint
|
||||
implements NamedMvcEndpoint {
|
||||
|
||||
private final String name;
|
||||
|
||||
public AbstractNamedMvcEndpoint(String name, String path, boolean sensitive) {
|
||||
super(path, sensitive);
|
||||
Assert.hasLength(name, "Name must not be empty");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public AbstractNamedMvcEndpoint(String name, String path, boolean sensitive,
|
||||
boolean enabled) {
|
||||
super(path, sensitive, enabled);
|
||||
Assert.hasLength(name, "Name must not be empty");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
|||
* @since 1.3.0
|
||||
*/
|
||||
@ConfigurationProperties("endpoints.docs")
|
||||
public class DocsMvcEndpoint extends AbstractMvcEndpoint {
|
||||
public class DocsMvcEndpoint extends AbstractNamedMvcEndpoint {
|
||||
|
||||
private static final String DOCS_LOCATION = "classpath:/META-INF/resources/spring-boot-actuator/docs/";
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ public class DocsMvcEndpoint extends AbstractMvcEndpoint {
|
|||
}
|
||||
|
||||
public DocsMvcEndpoint(ManagementServletContext managementServletContext) {
|
||||
super("/docs", false);
|
||||
super("docs", "/docs", false);
|
||||
this.managementServletContext = managementServletContext;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||
* @since 1.3.0
|
||||
*/
|
||||
@ConfigurationProperties("endpoints.actuator")
|
||||
public class HalJsonMvcEndpoint extends AbstractMvcEndpoint {
|
||||
public class HalJsonMvcEndpoint extends AbstractNamedMvcEndpoint {
|
||||
|
||||
private final ManagementServletContext managementServletContext;
|
||||
|
||||
public HalJsonMvcEndpoint(ManagementServletContext managementServletContext) {
|
||||
super(getDefaultPath(managementServletContext), false);
|
||||
super("actuator", getDefaultPath(managementServletContext), false);
|
||||
this.managementServletContext = managementServletContext;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
|||
*/
|
||||
@ConfigurationProperties("endpoints.heapdump")
|
||||
@HypermediaDisabled
|
||||
public class HeapdumpMvcEndpoint extends AbstractMvcEndpoint {
|
||||
public class HeapdumpMvcEndpoint extends AbstractNamedMvcEndpoint {
|
||||
|
||||
private final long timeout;
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ public class HeapdumpMvcEndpoint extends AbstractMvcEndpoint {
|
|||
}
|
||||
|
||||
protected HeapdumpMvcEndpoint(long timeout) {
|
||||
super("/heapdump", true);
|
||||
super("heapdump", "/heapdump", true);
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,12 +44,12 @@ import org.springframework.web.util.UrlPathHelper;
|
|||
*/
|
||||
@ConfigurationProperties(prefix = "endpoints.jolokia", ignoreUnknownFields = false)
|
||||
@HypermediaDisabled
|
||||
public class JolokiaMvcEndpoint extends AbstractMvcEndpoint
|
||||
public class JolokiaMvcEndpoint extends AbstractNamedMvcEndpoint
|
||||
implements InitializingBean, ApplicationContextAware, ServletContextAware {
|
||||
private final ServletWrappingController controller = new ServletWrappingController();
|
||||
|
||||
public JolokiaMvcEndpoint() {
|
||||
super("/jolokia", true);
|
||||
super("jolokia", "/jolokia", true);
|
||||
this.controller.setServletClass(AgentServlet.class);
|
||||
this.controller.setServletName("jolokia");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
|
|||
* @since 1.3.0
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "endpoints.logfile")
|
||||
public class LogFileMvcEndpoint extends AbstractMvcEndpoint {
|
||||
public class LogFileMvcEndpoint extends AbstractNamedMvcEndpoint {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(LogFileMvcEndpoint.class);
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ public class LogFileMvcEndpoint extends AbstractMvcEndpoint {
|
|||
private File externalFile;
|
||||
|
||||
public LogFileMvcEndpoint() {
|
||||
super("/logfile", true);
|
||||
super("logfile", "/logfile", true);
|
||||
}
|
||||
|
||||
public File getExternalFile() {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.springframework.http.ResponseEntity;
|
|||
* {@link EndpointHandlerMapping}).
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @see NamedMvcEndpoint
|
||||
*/
|
||||
public interface MvcEndpoint {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright 2012-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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.mvc;
|
||||
|
||||
/**
|
||||
* A {@link MvcEndpoint} that also includes a logical name. Unlike {@link #getPath()
|
||||
* endpoints paths}, it should not be possible for a user to change the endpoint name.
|
||||
* Names provide a consistent way to reference an endpoint, for example they may be used
|
||||
* as the {@literal 'rel'} attribute in a HAL response.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public interface NamedMvcEndpoint extends MvcEndpoint {
|
||||
|
||||
/**
|
||||
* Return the logical name of the endpoint. Names should be non-null, non-empty,
|
||||
* alpha-numeric values.
|
||||
* @return the logical name of the endpoint
|
||||
*/
|
||||
String getName();
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue