org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint Java Examples

The following examples show how to use org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SkipPatternAutoConfiguration.java    From java-spring-web with Apache License 2.0 6 votes vote down vote up
static Optional<Pattern> getEndpointsPatterns(WebEndpointProperties webEndpointProperties,
                                              EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
  Collection<ExposableWebEndpoint> endpoints = endpointsSupplier.getEndpoints();

  if (endpoints.isEmpty()) {
    return Optional.empty();
  }

  String pattern = endpoints.stream().map(PathMappedEndpoint::getRootPath)
      .map(path -> path + "|" + path + "/.*").collect(
          Collectors.joining("|",
              getPathPrefix(webEndpointProperties.getBasePath()) + "/(",
              ")"));
  if (StringUtils.hasText(pattern)) {
    return Optional.of(Pattern.compile(pattern));
  }
  return Optional.empty();
}
 
Example #2
Source File: ArmeriaSpringActuatorAutoConfiguration.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean(WebEndpointsSupplier.class)
WebEndpointDiscoverer webEndpointDiscoverer(
        ApplicationContext applicationContext,
        ParameterValueMapper parameterValueMapper,
        EndpointMediaTypes endpointMediaTypes,
        ObjectProvider<PathMapper> endpointPathMappers,
        ObjectProvider<OperationInvokerAdvisor> invokerAdvisors,
        ObjectProvider<EndpointFilter<ExposableWebEndpoint>> filters) {
    return new WebEndpointDiscoverer(applicationContext,
                                     parameterValueMapper,
                                     endpointMediaTypes,
                                     endpointPathMappers.orderedStream().collect(toImmutableList()),
                                     invokerAdvisors.orderedStream().collect(toImmutableList()),
                                     filters.orderedStream().collect(toImmutableList()));
}
 
Example #3
Source File: SkipPatternConfigTest.java    From java-spring-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testShouldReturnEndpointsWithoutContextPath() {
  WebEndpointProperties webEndpointProperties = new WebEndpointProperties();
  ServerProperties properties = new ServerProperties();
  properties.getServlet().setContextPath("foo");

  EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = () -> {
    ExposableWebEndpoint infoEndpoint = createEndpoint("info");
    ExposableWebEndpoint healthEndpoint = createEndpoint("health");

    return Arrays.asList(infoEndpoint, healthEndpoint);
  };

  Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ActuatorSkipPatternProviderConfig()
      .skipPatternForActuatorEndpointsSamePort(webEndpointProperties, endpointsSupplier)
      .pattern();

  then(pattern).isNotEmpty();
  then(pattern.get().pattern())
      .isEqualTo("/actuator/(info|info/.*|health|health/.*)");
}
 
Example #4
Source File: SkipPatternConfigTest.java    From java-spring-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testShouldReturnEndpointsWithoutContextPathAndBasePathSetToRoot() {
  WebEndpointProperties webEndpointProperties = new WebEndpointProperties();
  webEndpointProperties.setBasePath("/");

  EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = () -> {
    ExposableWebEndpoint infoEndpoint = createEndpoint("info");
    ExposableWebEndpoint healthEndpoint = createEndpoint("health");

    return Arrays.asList(infoEndpoint, healthEndpoint);
  };

  Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ActuatorSkipPatternProviderConfig()
      .skipPatternForActuatorEndpointsSamePort(webEndpointProperties, endpointsSupplier)
      .pattern();

  then(pattern).isNotEmpty();
  then(pattern.get().pattern()).isEqualTo("/(info|info/.*|health|health/.*)");
}
 
Example #5
Source File: SkipPatternConfigTest.java    From java-spring-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testShouldReturnEndpointsWithContextPathAndBasePathSetToRoot() {
  WebEndpointProperties webEndpointProperties = new WebEndpointProperties();
  webEndpointProperties.setBasePath("/");

  EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = () -> {
    ExposableWebEndpoint infoEndpoint = createEndpoint("info");
    ExposableWebEndpoint healthEndpoint = createEndpoint("health");

    return Arrays.asList(infoEndpoint, healthEndpoint);
  };

  Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ActuatorSkipPatternProviderConfig()
      .skipPatternForActuatorEndpointsSamePort(webEndpointProperties, endpointsSupplier)
      .pattern();

  then(pattern).isNotEmpty();
  then(pattern.get().pattern()).isEqualTo("/(info|info/.*|health|health/.*)");
}
 
Example #6
Source File: SkipPatternConfigTest.java    From java-spring-web with Apache License 2.0 6 votes vote down vote up
private ExposableWebEndpoint createEndpoint(final String name) {
  return new ExposableWebEndpoint() {

    @Override
    public String getRootPath() {
      return name;
    }

    @Override
    public EndpointId getEndpointId() {
      return EndpointId.of(name);
    }

    @Override
    public boolean isEnableByDefault() {
      return false;
    }

    @Override
    public Collection<WebOperation> getOperations() {
      return null;
    }
  };
}
 
Example #7
Source File: AbstractEndpointTests.java    From quickfixj-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
void assertReadProperties(Class<?> testConfigClass) {
	load(testConfigClass, (discoverer) -> {
		Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
		assertThat(endpoints).containsKey(endpointId);

		ExposableWebEndpoint endpoint = endpoints.get(endpointId);
		assertThat(endpoint.getOperations()).hasSize(1);

		WebOperation operation = endpoint.getOperations().iterator().next();
		Object invoker = ReflectionTestUtils.getField(operation, "invoker");
		assertThat(invoker).isInstanceOf(ReflectiveOperationInvoker.class);

		Map<String, Properties> properties = (Map<String, Properties>) ((ReflectiveOperationInvoker) invoker).invoke(
				new InvocationContext(mock(SecurityContext.class), Collections.emptyMap()));
		assertThat(properties).hasSize(1);
	});
}
 
Example #8
Source File: SkipPatternAutoConfiguration.java    From java-spring-web with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnManagementPort(ManagementPortType.SAME)
public SkipPattern skipPatternForActuatorEndpointsSamePort(
    final WebEndpointProperties webEndpointProperties,
    final EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
  return () -> getEndpointsPatterns(webEndpointProperties, endpointsSupplier);
}
 
Example #9
Source File: SkipPatternProviderConfigTest.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_empty_when_no_endpoints() {
	EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = Collections::emptyList;
	Optional<Pattern> pattern = new SkipPatternConfiguration.ActuatorSkipPatternProviderConfig()
			.skipPatternForActuatorEndpointsSamePort(new ServerProperties(),
					new WebEndpointProperties(), endpointsSupplier)
			.skipPattern();

	then(pattern).isEmpty();
}
 
Example #10
Source File: SkipPatternConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnManagementPort(ManagementPortType.DIFFERENT)
@ConditionalOnProperty(name = "management.server.servlet.context-path",
		havingValue = "/", matchIfMissing = true)
public SingleSkipPattern skipPatternForActuatorEndpointsDifferentPort(
		final ServerProperties serverProperties,
		final WebEndpointProperties webEndpointProperties,
		final EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
	return () -> getEndpointsPatterns(null, webEndpointProperties,
			endpointsSupplier);
}
 
Example #11
Source File: SkipPatternConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnManagementPort(ManagementPortType.SAME)
public SingleSkipPattern skipPatternForActuatorEndpointsSamePort(
		final ServerProperties serverProperties,
		final WebEndpointProperties webEndpointProperties,
		final EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
	return () -> getEndpointsPatterns(
			serverProperties.getServlet().getContextPath(), webEndpointProperties,
			endpointsSupplier);
}
 
Example #12
Source File: SkipPatternConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
private static String patternFromEndpoints(String contextPath,
		Collection<ExposableWebEndpoint> endpoints, String basePath) {
	StringJoiner joiner = new StringJoiner("|",
			getPathPrefix(contextPath, basePath),
			getPathSuffix(contextPath, basePath));
	for (ExposableWebEndpoint endpoint : endpoints) {
		String path = endpoint.getRootPath();
		String paths = path + "|" + path + "/.*";
		joiner.add(paths);
	}
	return joiner.toString();
}
 
Example #13
Source File: SkipPatternConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
static Optional<Pattern> getEndpointsPatterns(String contextPath,
		WebEndpointProperties webEndpointProperties,
		EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
	Collection<ExposableWebEndpoint> endpoints = endpointsSupplier.getEndpoints();
	if (endpoints.isEmpty()) {
		return Optional.empty();
	}
	String basePath = webEndpointProperties.getBasePath();
	String pattern = patternFromEndpoints(contextPath, endpoints, basePath);
	if (StringUtils.hasText(pattern)) {
		return Optional.of(Pattern.compile(pattern));
	}
	return Optional.empty();
}
 
Example #14
Source File: SkipPatternConfigTest.java    From java-spring-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldReturnEmptyWhenNoEndpoints() {
  EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = Collections::emptyList;
  Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ActuatorSkipPatternProviderConfig()
      .skipPatternForActuatorEndpointsSamePort(new WebEndpointProperties(), endpointsSupplier)
      .pattern();

  then(pattern).isEmpty();
}
 
Example #15
Source File: SkipPatternAutoConfiguration.java    From java-spring-web with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnManagementPort(ManagementPortType.DIFFERENT)
@ConditionalOnProperty(name = "management.server.servlet.context-path", havingValue = "/", matchIfMissing = true)
public SkipPattern skipPatternForActuatorEndpointsDifferentPort(
    final WebEndpointProperties webEndpointProperties,
    final EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier) {
  return () -> getEndpointsPatterns(webEndpointProperties, endpointsSupplier);
}
 
Example #16
Source File: AbstractEndpointTests.java    From quickfixj-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
private Map<EndpointId, ExposableWebEndpoint> mapEndpoints(Collection<ExposableWebEndpoint> endpoints) {
	Map<EndpointId, ExposableWebEndpoint> endpointById = new HashMap<>();
	endpoints.forEach((endpoint) -> endpointById.put(endpoint.getEndpointId(), endpoint));
	return endpointById;
}
 
Example #17
Source File: AbstractEndpointTests.java    From quickfixj-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
void assertActuatorEndpointNotLoaded(Class<?> testConfigClass) {
	load(testConfigClass, (discoverer) -> {
		Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
		assertThat(endpoints).doesNotContainKey(endpointId);
	});
}
 
Example #18
Source File: AbstractEndpointTests.java    From quickfixj-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
void assertActuatorEndpointLoaded(Class<?> testConfigClass) {
	load(testConfigClass, (discoverer) -> {
		Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
		assertThat(endpoints).containsOnlyKeys(endpointId);
	});
}