Allow to customize the path of a web endpoint
This commit introduces a endpoints.<id>.web.path generic property that allows to customize the path of an endpoint. By default the path is the same as the id of the endpoint. Such customization does not apply for the CloudFoundry specific endpoints. Closes gh-10181pull/10511/merge
parent
622e65a290
commit
56afc25304
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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.autoconfigure.endpoint;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointPathResolver;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* Default {@link EndpointPathResolver} implementation that use the
|
||||
* {@link Environment} to determine if an endpoint has a custom path.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class DefaultEndpointPathResolver implements EndpointPathResolver {
|
||||
|
||||
private final Environment environment;
|
||||
|
||||
DefaultEndpointPathResolver(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolvePath(String endpointId) {
|
||||
String key = String.format("endpoints.%s.web.path", endpointId);
|
||||
return this.environment.getProperty(key, String.class, endpointId);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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.autoconfigure.endpoint;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointPathResolver;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DefaultEndpointPathResolver}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class DefaultEndpointPathResolverTests {
|
||||
|
||||
private final MockEnvironment environment = new MockEnvironment();
|
||||
|
||||
private final EndpointPathResolver resolver = new DefaultEndpointPathResolver(
|
||||
this.environment);
|
||||
|
||||
@Test
|
||||
public void defaultConfiguration() {
|
||||
assertThat(this.resolver.resolvePath("test")).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userConfiguration() {
|
||||
this.environment.setProperty("endpoints.test.web.path", "custom");
|
||||
assertThat(this.resolver.resolvePath("test")).isEqualTo("custom");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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.web;
|
||||
|
||||
/**
|
||||
* Resolve the path of an endpoint.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface EndpointPathResolver {
|
||||
|
||||
/**
|
||||
* Resolve the path for the endpoint with the specified {@code endpointId}.
|
||||
* @param endpointId the id of an endpoint
|
||||
* @return the path of the endpoint
|
||||
*/
|
||||
String resolvePath(String endpointId);
|
||||
|
||||
}
|
Loading…
Reference in New Issue