Search in sources :

Example 1 with ExposableWebEndpoint

use of org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint in project spring-boot by spring-projects.

the class CloudFoundryActuatorAutoConfigurationTests method endpointPathCustomizationIsNotApplied.

@Test
void endpointPathCustomizationIsNotApplied() {
    this.contextRunner.withPropertyValues("VCAP_APPLICATION:---", "vcap.application.application_id:my-app-id", "vcap.application.cf_api:https://my-cloud-controller.com", "management.endpoints.web.path-mapping.test=custom").withBean(TestEndpoint.class, TestEndpoint::new).run((context) -> {
        CloudFoundryWebEndpointServletHandlerMapping handlerMapping = getHandlerMapping(context);
        Collection<ExposableWebEndpoint> endpoints = handlerMapping.getEndpoints();
        ExposableWebEndpoint endpoint = endpoints.stream().filter((candidate) -> EndpointId.of("test").equals(candidate.getEndpointId())).findFirst().get();
        Collection<WebOperation> operations = endpoint.getOperations();
        assertThat(operations).hasSize(1);
        assertThat(operations.iterator().next().getRequestPredicate().getPath()).isEqualTo("test");
    });
}
Also used : WebOperation(org.springframework.boot.actuate.endpoint.web.WebOperation) ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) Test(org.junit.jupiter.api.Test)

Example 2 with ExposableWebEndpoint

use of org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint in project spring-boot by spring-projects.

the class CloudFoundryWebEndpointDiscovererTests method getEndpointsShouldAddCloudFoundryHealthExtension.

@Test
void getEndpointsShouldAddCloudFoundryHealthExtension() {
    load(TestConfiguration.class, (discoverer) -> {
        Collection<ExposableWebEndpoint> endpoints = discoverer.getEndpoints();
        assertThat(endpoints.size()).isEqualTo(2);
        for (ExposableWebEndpoint endpoint : endpoints) {
            if (endpoint.getEndpointId().equals(EndpointId.of("health"))) {
                WebOperation operation = findMainReadOperation(endpoint);
                assertThat(operation.invoke(new InvocationContext(mock(SecurityContext.class), Collections.emptyMap()))).isEqualTo("cf");
            }
        }
    });
}
Also used : WebOperation(org.springframework.boot.actuate.endpoint.web.WebOperation) ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) InvocationContext(org.springframework.boot.actuate.endpoint.InvocationContext) Test(org.junit.jupiter.api.Test)

Example 3 with ExposableWebEndpoint

use of org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint in project spring-boot by spring-projects.

the class ReactiveCloudFoundryActuatorAutoConfigurationTests method healthEndpointInvokerShouldBeCloudFoundryWebExtension.

@Test
void healthEndpointInvokerShouldBeCloudFoundryWebExtension() {
    this.contextRunner.withConfiguration(AutoConfigurations.of(HealthEndpointAutoConfiguration.class)).withPropertyValues("VCAP_APPLICATION:---", "vcap.application.application_id:my-app-id", "vcap.application.cf_api:https://my-cloud-controller.com").run((context) -> {
        Collection<ExposableWebEndpoint> endpoints = getHandlerMapping(context).getEndpoints();
        ExposableWebEndpoint endpoint = endpoints.iterator().next();
        assertThat(endpoint.getOperations()).hasSize(2);
        WebOperation webOperation = findOperationWithRequestPath(endpoint, "health");
        assertThat(webOperation).extracting("invoker").extracting("target").isInstanceOf(CloudFoundryReactiveHealthEndpointWebExtension.class);
    });
}
Also used : WebOperation(org.springframework.boot.actuate.endpoint.web.WebOperation) ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) HealthEndpointAutoConfiguration(org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with ExposableWebEndpoint

use of org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint in project spring-boot by spring-projects.

the class WebFluxEndpointManagementContextConfiguration method webEndpointReactiveHandlerMapping.

@Bean
@ConditionalOnMissingBean
public WebFluxEndpointHandlerMapping webEndpointReactiveHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
    String basePath = webEndpointProperties.getBasePath();
    EndpointMapping endpointMapping = new EndpointMapping(basePath);
    Collection<ExposableWebEndpoint> endpoints = webEndpointsSupplier.getEndpoints();
    List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
    allEndpoints.addAll(endpoints);
    allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
    return new WebFluxEndpointHandlerMapping(endpointMapping, endpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping(webEndpointProperties, environment, basePath));
}
Also used : ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) ExposableEndpoint(org.springframework.boot.actuate.endpoint.ExposableEndpoint) ArrayList(java.util.ArrayList) WebFluxEndpointHandlerMapping(org.springframework.boot.actuate.endpoint.web.reactive.WebFluxEndpointHandlerMapping) EndpointLinksResolver(org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver) EndpointMapping(org.springframework.boot.actuate.endpoint.web.EndpointMapping) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with ExposableWebEndpoint

use of org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint in project spring-boot by spring-projects.

the class WebFluxEndpointManagementContextConfiguration method managementHealthEndpointWebFluxHandlerMapping.

@Bean
@ConditionalOnManagementPort(ManagementPortType.DIFFERENT)
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class, exposure = EndpointExposure.WEB)
@ConditionalOnBean(HealthEndpoint.class)
public AdditionalHealthEndpointPathsWebFluxHandlerMapping managementHealthEndpointWebFluxHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, HealthEndpointGroups groups) {
    Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
    ExposableWebEndpoint health = webEndpoints.stream().filter((endpoint) -> endpoint.getEndpointId().equals(HealthEndpoint.ID)).findFirst().get();
    return new AdditionalHealthEndpointPathsWebFluxHandlerMapping(new EndpointMapping(""), health, groups.getAllWithAdditionalPath(WebServerNamespace.MANAGEMENT));
}
Also used : ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) EndpointMapping(org.springframework.boot.actuate.endpoint.web.EndpointMapping) AdditionalHealthEndpointPathsWebFluxHandlerMapping(org.springframework.boot.actuate.endpoint.web.reactive.AdditionalHealthEndpointPathsWebFluxHandlerMapping) ConditionalOnAvailableEndpoint(org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnManagementPort(org.springframework.boot.actuate.autoconfigure.web.server.ConditionalOnManagementPort) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

ExposableWebEndpoint (org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint)19 Test (org.junit.jupiter.api.Test)13 EndpointId (org.springframework.boot.actuate.endpoint.EndpointId)7 WebOperation (org.springframework.boot.actuate.endpoint.web.WebOperation)6 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)6 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)6 Bean (org.springframework.context.annotation.Bean)6 ArrayList (java.util.ArrayList)5 EndpointMapping (org.springframework.boot.actuate.endpoint.web.EndpointMapping)5 ExposableEndpoint (org.springframework.boot.actuate.endpoint.ExposableEndpoint)4 EndpointLinksResolver (org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver)4 CloudFoundryWebEndpointDiscoverer (org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryWebEndpointDiscoverer)2 ConditionalOnAvailableEndpoint (org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint)2 ConditionalOnManagementPort (org.springframework.boot.actuate.autoconfigure.web.server.ConditionalOnManagementPort)2 List (java.util.List)1 HealthEndpointAutoConfiguration (org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration)1 InvocationContext (org.springframework.boot.actuate.endpoint.InvocationContext)1 CachingOperationInvoker (org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker)1 WebOperationRequestPredicate (org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate)1 WebEndpointDiscoverer (org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointDiscoverer)1