|
13 | 13 | import org.springframework.beans.factory.annotation.Value; |
14 | 14 | import org.springframework.context.annotation.Configuration; |
15 | 15 | import org.springframework.util.PathMatcher; |
| 16 | +import org.springframework.util.StringUtils; |
16 | 17 | import org.springframework.web.servlet.config.annotation.CorsRegistry; |
17 | 18 | import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; |
18 | 19 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; |
@@ -90,6 +91,8 @@ public class WapServerConfig extends WebMvcConfigurationSupport{ |
90 | 91 | private static final String CORS_ALLOWED_ORIGINS_PATH_DEFAULT = "./cors_allowed_origins.conf"; |
91 | 92 | private static final boolean FALLBACK_VALIDATION_DEFAULT = true; |
92 | 93 | private static final String RDF_BACKEND_IMPLEMENTATION_DEFAULT = "jena"; |
| 94 | + private static final String CONTEXT_PATH_DEFAULT = ""; |
| 95 | + private static final String PROXYBASEPATH_DEFAULT = ""; |
93 | 96 |
|
94 | 97 | /** |
95 | 98 | * The single instance of the configuration |
@@ -245,6 +248,12 @@ public class WapServerConfig extends WebMvcConfigurationSupport{ |
245 | 248 | @Value("${RdfBackendImplementation:" + RDF_BACKEND_IMPLEMENTATION_DEFAULT + "}") |
246 | 249 | private String rdfBackendImplementation; |
247 | 250 |
|
| 251 | + @Value("${server.servlet.context-path:" + CONTEXT_PATH_DEFAULT + "}") |
| 252 | + private String contextPath = CONTEXT_PATH_DEFAULT; |
| 253 | + |
| 254 | + @Value("${WapBaseUrl:" + PROXYBASEPATH_DEFAULT + "}") |
| 255 | + private String proxiedBasePath; |
| 256 | + |
248 | 257 | /** |
249 | 258 | * The cors configuration to use |
250 | 259 | */ |
@@ -362,6 +371,8 @@ public static Properties getDefaultProperties(){ |
362 | 371 | props.put(ConfigurationKeys.SimpleFormatters.toString(), SIMPLE_FORMATTERS_DEFAULT); |
363 | 372 | props.put(ConfigurationKeys.CorsAllowedOriginsPath.toString(), CORS_ALLOWED_ORIGINS_PATH_DEFAULT); |
364 | 373 | props.put(ConfigurationKeys.FallbackValidation.toString(), FALLBACK_VALIDATION_DEFAULT + ""); |
| 374 | + props.put(ConfigurationKeys.ContextPath.toString(), CONTEXT_PATH_DEFAULT); |
| 375 | + props.put(ConfigurationKeys.ProxiedBasePath.toString(), PROXYBASEPATH_DEFAULT); |
365 | 376 | if(ConfigurationKeys.values().length != props.size()){ |
366 | 377 | throw new RuntimeException("Default properties and the ConfigurationKeys enum not in sync"); |
367 | 378 | } |
@@ -715,6 +726,8 @@ public void updateConfig(Properties props){ |
715 | 726 | corsAllowedOriginsPath |
716 | 727 | = getProperty(props, ConfigurationKeys.CorsAllowedOriginsPath, CORS_ALLOWED_ORIGINS_PATH_DEFAULT); |
717 | 728 | fallbackValidation = getProperty(props, ConfigurationKeys.FallbackValidation, FALLBACK_VALIDATION_DEFAULT); |
| 729 | + contextPath = getProperty(props, ConfigurationKeys.ContextPath, CONTEXT_PATH_DEFAULT); |
| 730 | + proxiedBasePath = getProperty(props, ConfigurationKeys.ProxiedBasePath, PROXYBASEPATH_DEFAULT); |
718 | 731 | } |
719 | 732 |
|
720 | 733 | private String getProperty(Properties newProps, ConfigurationKeys key, String defaultValue){ |
@@ -813,17 +826,18 @@ public boolean isRootWapUrl(String url){ |
813 | 826 | * @return The base url |
814 | 827 | */ |
815 | 828 | public String getBaseUrl(){ |
| 829 | + if(StringUtils.hasText(proxiedBasePath))return proxiedBasePath; |
816 | 830 | if(enableHttps){ |
817 | 831 | if(wapPort == 443){ |
818 | | - return "https://" + hostname; |
| 832 | + return "https://" + hostname + contextPath; |
819 | 833 | } else{ |
820 | | - return "https://" + hostname + ":" + wapPort; |
| 834 | + return "https://" + hostname + ":" + wapPort + contextPath; |
821 | 835 | } |
822 | 836 | } else{ |
823 | 837 | if(wapPort == 80){ |
824 | | - return "http://" + hostname; |
| 838 | + return "http://" + hostname + contextPath; |
825 | 839 | } else{ |
826 | | - return "http://" + hostname + ":" + wapPort; |
| 840 | + return "http://" + hostname + ":" + wapPort + contextPath; |
827 | 841 | } |
828 | 842 | } |
829 | 843 | } |
|
0 commit comments