|
16 | 16 | */
|
17 | 17 | package com.ericsson.ei.config;
|
18 | 18 |
|
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.Collection; |
| 21 | +import java.util.List; |
19 | 22 | import java.util.concurrent.Executor;
|
20 | 23 |
|
| 24 | +import org.apache.commons.lang3.StringUtils; |
21 | 25 | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
22 | 26 | import org.springframework.beans.factory.annotation.Value;
|
| 27 | +import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties; |
| 28 | +import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties; |
| 29 | +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType; |
| 30 | +import org.springframework.boot.actuate.endpoint.ExposableEndpoint; |
| 31 | +import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver; |
| 32 | +import org.springframework.boot.actuate.endpoint.web.EndpointMapping; |
| 33 | +import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes; |
| 34 | +import org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint; |
| 35 | +import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier; |
| 36 | +import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier; |
| 37 | +import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier; |
| 38 | +import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping; |
| 39 | +import org.springframework.context.annotation.Bean; |
23 | 40 | import org.springframework.context.annotation.Configuration;
|
| 41 | +import org.springframework.core.env.Environment; |
24 | 42 | import org.springframework.scheduling.annotation.AsyncConfigurer;
|
25 | 43 | import org.springframework.scheduling.annotation.EnableAsync;
|
26 | 44 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
@@ -54,4 +72,22 @@ public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
54 | 72 | // TODO Auto-generated method stub
|
55 | 73 | return null;
|
56 | 74 | }
|
| 75 | + |
| 76 | + @Bean |
| 77 | + public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) { |
| 78 | + List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>(); |
| 79 | + Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints(); |
| 80 | + allEndpoints.addAll(webEndpoints); |
| 81 | + allEndpoints.addAll(servletEndpointsSupplier.getEndpoints()); |
| 82 | + allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints()); |
| 83 | + String basePath = webEndpointProperties.getBasePath(); |
| 84 | + EndpointMapping endpointMapping = new EndpointMapping(basePath); |
| 85 | + boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath); |
| 86 | + return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null); |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | + private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) { |
| 91 | + return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.isNotEmpty(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT)); |
| 92 | + } |
57 | 93 | }
|
0 commit comments