|
14 | 14 | */
|
15 | 15 | package com.ericsson.eiffel.remrem.publish.config;
|
16 | 16 |
|
17 |
| -import io.swagger.annotations.Api; |
| 17 | +import java.util.ArrayList; |
| 18 | +import java.util.Collection; |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties; |
| 22 | +import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties; |
| 23 | +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType; |
| 24 | +import org.springframework.boot.actuate.endpoint.ExposableEndpoint; |
| 25 | +import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver; |
| 26 | +import org.springframework.boot.actuate.endpoint.web.EndpointMapping; |
| 27 | +import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes; |
| 28 | +import org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint; |
| 29 | +import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier; |
| 30 | +import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier; |
| 31 | +import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier; |
| 32 | +import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping; |
18 | 33 | import org.springframework.context.annotation.Bean;
|
19 | 34 | import org.springframework.context.annotation.Configuration;
|
| 35 | +import org.springframework.core.env.Environment; |
| 36 | +import org.springframework.util.StringUtils; |
| 37 | + |
| 38 | +import io.swagger.annotations.Api; |
20 | 39 | import springfox.documentation.builders.ApiInfoBuilder;
|
21 | 40 | import springfox.documentation.builders.PathSelectors;
|
22 | 41 | import springfox.documentation.builders.RequestHandlerSelectors;
|
@@ -48,6 +67,31 @@ public UiConfiguration uiConfig() {
|
48 | 67 | null);
|
49 | 68 | }
|
50 | 69 |
|
| 70 | + @Bean |
| 71 | + public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, |
| 72 | + ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, |
| 73 | + EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, |
| 74 | + WebEndpointProperties webEndpointProperties, Environment environment) { |
| 75 | + List<ExposableEndpoint<?>> allEndpoints = new ArrayList(); |
| 76 | + Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints(); |
| 77 | + allEndpoints.addAll(webEndpoints); |
| 78 | + allEndpoints.addAll(servletEndpointsSupplier.getEndpoints()); |
| 79 | + allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints()); |
| 80 | + String basePath = webEndpointProperties.getBasePath(); |
| 81 | + EndpointMapping endpointMapping = new EndpointMapping(basePath); |
| 82 | + boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, |
| 83 | + basePath); |
| 84 | + return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, |
| 85 | + corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), |
| 86 | + shouldRegisterLinksMapping, null); |
| 87 | + } |
| 88 | + |
| 89 | + private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, |
| 90 | + String basePath) { |
| 91 | + return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) |
| 92 | + || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT)); |
| 93 | + } |
| 94 | + |
51 | 95 | private ApiInfo metaData() {
|
52 | 96 | final StringBuilder remremDescription = new StringBuilder();
|
53 | 97 | remremDescription.append("REMReM (REST Mailbox for Registered Messages) Publish "
|
|
0 commit comments