Search in sources :

Example 1 with NamedMvcEndpoint

use of org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint in project spring-boot by spring-projects.

the class CloudFoundryEndpointHandlerMapping method postProcessEndpoints.

@Override
protected void postProcessEndpoints(Set<NamedMvcEndpoint> endpoints) {
    super.postProcessEndpoints(endpoints);
    Iterator<NamedMvcEndpoint> iterator = endpoints.iterator();
    HealthMvcEndpoint healthMvcEndpoint = null;
    while (iterator.hasNext()) {
        NamedMvcEndpoint endpoint = iterator.next();
        if (endpoint instanceof HalJsonMvcEndpoint) {
            iterator.remove();
        } else if (endpoint instanceof HealthMvcEndpoint) {
            iterator.remove();
            healthMvcEndpoint = (HealthMvcEndpoint) endpoint;
        }
    }
    if (healthMvcEndpoint != null) {
        endpoints.add(new CloudFoundryHealthMvcEndpoint(healthMvcEndpoint.getDelegate()));
    }
}
Also used : NamedMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint) HalJsonMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.HalJsonMvcEndpoint) HealthMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint)

Example 2 with NamedMvcEndpoint

use of org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint in project spring-boot by spring-projects.

the class CloudFoundryDiscoveryMvcEndpointTests method setup.

@Before
public void setup() {
    NamedMvcEndpoint endpoint = new TestMvcEndpoint(new TestEndpoint("a"));
    this.endpoints = new LinkedHashSet<>();
    this.endpoints.add(endpoint);
    this.endpoint = new CloudFoundryDiscoveryMvcEndpoint(this.endpoints);
}
Also used : NamedMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint) Before(org.junit.Before)

Example 3 with NamedMvcEndpoint

use of org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint in project spring-boot by spring-projects.

the class CloudFoundryDiscoveryMvcEndpointTests method linksResponseWhenRequestHasAccessLevelRestricted.

@Test
public void linksResponseWhenRequestHasAccessLevelRestricted() throws Exception {
    NamedMvcEndpoint testHealthMvcEndpoint = new TestMvcEndpoint(new TestEndpoint("health"));
    this.endpoints.add(testHealthMvcEndpoint);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/cloudfoundryapplication/");
    AccessLevel.RESTRICTED.put(request);
    Map<String, CloudFoundryDiscoveryMvcEndpoint.Link> links = this.endpoint.links(request).get("_links");
    assertThat(links.get("self").getHref()).isEqualTo("http://localhost/cloudfoundryapplication");
    assertThat(links.get("health").getHref()).isEqualTo("http://localhost/cloudfoundryapplication/health");
    assertThat(links.get("a")).isNull();
}
Also used : NamedMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 4 with NamedMvcEndpoint

use of org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint in project spring-boot by spring-projects.

the class CloudFoundryActuatorAutoConfiguration method cloudFoundryEndpointHandlerMapping.

@Bean
public CloudFoundryEndpointHandlerMapping cloudFoundryEndpointHandlerMapping(MvcEndpoints mvcEndpoints, RestTemplateBuilder restTemplateBuilder, Environment environment) {
    Set<NamedMvcEndpoint> endpoints = new LinkedHashSet<>(mvcEndpoints.getEndpoints(NamedMvcEndpoint.class));
    HandlerInterceptor securityInterceptor = getSecurityInterceptor(restTemplateBuilder, environment);
    CorsConfiguration corsConfiguration = getCorsConfiguration();
    CloudFoundryEndpointHandlerMapping mapping = new CloudFoundryEndpointHandlerMapping(endpoints, corsConfiguration, securityInterceptor);
    mapping.setPrefix("/cloudfoundryapplication");
    return mapping;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NamedMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint) CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerInterceptor(org.springframework.web.servlet.HandlerInterceptor) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with NamedMvcEndpoint

use of org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint in project spring-boot by spring-projects.

the class CloudFoundryDiscoveryMvcEndpoint method links.

@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, Map<String, Link>> links(HttpServletRequest request) {
    Map<String, Link> links = new LinkedHashMap<>();
    String url = request.getRequestURL().toString();
    if (url.endsWith("/")) {
        url = url.substring(0, url.length() - 1);
    }
    links.put("self", Link.withHref(url));
    AccessLevel accessLevel = AccessLevel.get(request);
    for (NamedMvcEndpoint endpoint : this.endpoints) {
        if (accessLevel != null && accessLevel.isAccessAllowed(endpoint.getPath())) {
            links.put(endpoint.getName(), Link.withHref(url + "/" + endpoint.getName()));
        }
    }
    return Collections.singletonMap("_links", links);
}
Also used : NamedMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint) LinkedHashMap(java.util.LinkedHashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

NamedMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint)5 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Before (org.junit.Before)1 Test (org.junit.Test)1 HalJsonMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.HalJsonMvcEndpoint)1 HealthMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 Bean (org.springframework.context.annotation.Bean)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)1 HandlerInterceptor (org.springframework.web.servlet.HandlerInterceptor)1