Search in sources :

Example 16 with ExposableWebEndpoint

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

the class ReactiveCloudFoundryActuatorAutoConfigurationTests method endpointPathCustomizationIsNotApplied.

@Test
void endpointPathCustomizationIsNotApplied() {
    this.contextRunner.withBean(TestEndpoint.class, TestEndpoint::new).withPropertyValues("VCAP_APPLICATION:---", "vcap.application.application_id:my-app-id", "vcap.application.cf_api:https://my-cloud-controller.com").run((context) -> {
        CloudFoundryWebFluxEndpointHandlerMapping handlerMapping = getHandlerMapping(context);
        Collection<ExposableWebEndpoint> endpoints = handlerMapping.getEndpoints();
        ExposableWebEndpoint endpoint = endpoints.stream().filter((candidate) -> EndpointId.of("test").equals(candidate.getEndpointId())).findFirst().get();
        assertThat(endpoint.getOperations()).hasSize(1);
        WebOperation operation = endpoint.getOperations().iterator().next();
        assertThat(operation.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 17 with ExposableWebEndpoint

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

the class CloudFoundryActuatorAutoConfigurationTests method healthEndpointInvokerShouldBeCloudFoundryWebExtension.

@Test
void healthEndpointInvokerShouldBeCloudFoundryWebExtension() {
    this.contextRunner.withPropertyValues("VCAP_APPLICATION:---", "vcap.application.application_id:my-app-id", "vcap.application.cf_api:https://my-cloud-controller.com").withConfiguration(AutoConfigurations.of(HealthContributorAutoConfiguration.class, HealthEndpointAutoConfiguration.class)).run((context) -> {
        Collection<ExposableWebEndpoint> endpoints = context.getBean("cloudFoundryWebEndpointServletHandlerMapping", CloudFoundryWebEndpointServletHandlerMapping.class).getEndpoints();
        ExposableWebEndpoint endpoint = endpoints.iterator().next();
        assertThat(endpoint.getOperations()).hasSize(2);
        WebOperation webOperation = findOperationWithRequestPath(endpoint, "health");
        assertThat(webOperation).extracting("invoker.target").isInstanceOf(CloudFoundryHealthEndpointWebExtension.class);
    });
}
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 18 with ExposableWebEndpoint

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

the class WebMvcEndpointManagementContextConfiguration method webEndpointServletHandlerMapping.

@Bean
@ConditionalOnMissingBean
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
    List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
    Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
    allEndpoints.addAll(webEndpoints);
    allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
    allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
    String basePath = webEndpointProperties.getBasePath();
    EndpointMapping endpointMapping = new EndpointMapping(basePath);
    boolean shouldRegisterLinksMapping = shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
    return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, WebMvcAutoConfiguration.pathPatternParser);
}
Also used : ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) ExposableEndpoint(org.springframework.boot.actuate.endpoint.ExposableEndpoint) WebMvcEndpointHandlerMapping(org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping) ArrayList(java.util.ArrayList) 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 19 with ExposableWebEndpoint

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

the class WebEndpointAutoConfigurationTests method webApplicationSupportCustomPathMatcher.

@Test
void webApplicationSupportCustomPathMatcher() {
    this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=*", "management.endpoints.web.path-mapping.testanotherone=foo").withUserConfiguration(TestPathMatcher.class, TestOneEndpoint.class, TestAnotherOneEndpoint.class, TestTwoEndpoint.class).run((context) -> {
        WebEndpointDiscoverer discoverer = context.getBean(WebEndpointDiscoverer.class);
        Collection<ExposableWebEndpoint> endpoints = discoverer.getEndpoints();
        ExposableWebEndpoint[] webEndpoints = endpoints.toArray(new ExposableWebEndpoint[0]);
        List<String> paths = Arrays.stream(webEndpoints).map(PathMappedEndpoint::getRootPath).collect(Collectors.toList());
        assertThat(paths).containsOnly("1/testone", "foo", "testtwo");
    });
}
Also used : ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) WebEndpointDiscoverer(org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointDiscoverer) Test(org.junit.jupiter.api.Test)

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