Commit 78b4cd51 authored by I Patini's avatar I Patini
Browse files

EMS: Control Service: Added 'static.resource.redirects' property for...

EMS: Control Service: Added 'static.resource.redirects' property for configuring redirections. The old 'static.resource.redirect' remains for backward compatibility
parent 879fd905
Pipeline #18373 failed with stages
in 7 minutes and 33 seconds
...@@ -114,7 +114,8 @@ static.favicon.path=file:${PUBLIC_DIR}/favicon.ico ...@@ -114,7 +114,8 @@ static.favicon.path=file:${PUBLIC_DIR}/favicon.ico
#static.resource.redirect=/resources/index.html #static.resource.redirect=/resources/index.html
static.resource.path=file:${PUBLIC_DIR}/ static.resource.path=file:${PUBLIC_DIR}/
static.resource.context=/** static.resource.context=/**
static.resource.redirect=/admin/index.html #static.resource.redirect=/admin/index.html
static.resource.redirects={ '/': '/admin/index.html', '/admin': '/admin/index.html', '/admin/': '/admin/index.html' }
static.logs.path=file:${LOGS_DIR}/ static.logs.path=file:${LOGS_DIR}/
static.logs.context=/logs/** static.logs.context=/logs/**
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
package eu.melodic.event.control.webconf; package eu.melodic.event.control.webconf;
import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -20,6 +21,8 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry ...@@ -20,6 +21,8 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.Map;
@Slf4j @Slf4j
@Configuration @Configuration
public class StaticResourceConfiguration implements WebMvcConfigurer { public class StaticResourceConfiguration implements WebMvcConfigurer {
...@@ -32,8 +35,11 @@ public class StaticResourceConfiguration implements WebMvcConfigurer { ...@@ -32,8 +35,11 @@ public class StaticResourceConfiguration implements WebMvcConfigurer {
private String staticResourceContext; private String staticResourceContext;
@Value("${static.resource.path:#{null}}") @Value("${static.resource.path:#{null}}")
private String[] staticResourcePath; private String[] staticResourcePath;
@Value("${static.resource.redirect:#{null}}") @Value("${static.resource.redirect:#{null}}")
private String staticResourceRedirect; private String staticResourceRedirect;
@Value("#{${static.resource.redirects:{}}}")
private Map<String,String> staticResourceRedirects;
@Value("${static.logs.context:/logs/**}") @Value("${static.logs.context:/logs/**}")
private String staticLogsContext; private String staticLogsContext;
...@@ -82,6 +88,7 @@ public class StaticResourceConfiguration implements WebMvcConfigurer { ...@@ -82,6 +88,7 @@ public class StaticResourceConfiguration implements WebMvcConfigurer {
@Override @Override
public void addViewControllers(ViewControllerRegistry registry) { public void addViewControllers(ViewControllerRegistry registry) {
// Remains for backward compatibility (of properties file)
if (StringUtils.isNotBlank(staticResourceRedirect)) { if (StringUtils.isNotBlank(staticResourceRedirect)) {
log.info("Redirecting / to: {}", staticResourceRedirect); log.info("Redirecting / to: {}", staticResourceRedirect);
registry registry
...@@ -89,6 +96,20 @@ public class StaticResourceConfiguration implements WebMvcConfigurer { ...@@ -89,6 +96,20 @@ public class StaticResourceConfiguration implements WebMvcConfigurer {
.setViewName("redirect:" + staticResourceRedirect); .setViewName("redirect:" + staticResourceRedirect);
} }
log.debug("Configured resource redirects: {}", staticResourceRedirects);
if (staticResourceRedirects!=null) {
staticResourceRedirects.forEach((context, redirect) -> {
if (StringUtils.isNotBlank(context) && StringUtils.isNotBlank(redirect)) {
context = context.trim();
redirect = redirect.trim();
log.info("Redirecting {} to: {}", context, redirect);
registry
.addViewController(context)
.setViewName("redirect:" + redirect);
}
});
}
WebMvcConfigurer.super.addViewControllers(registry); WebMvcConfigurer.super.addViewControllers(registry);
} }
...@@ -109,4 +130,10 @@ public class StaticResourceConfiguration implements WebMvcConfigurer { ...@@ -109,4 +130,10 @@ public class StaticResourceConfiguration implements WebMvcConfigurer {
filter.setAfterMessageSuffix("<< REQUEST DATA AFTER"); filter.setAfterMessageSuffix("<< REQUEST DATA AFTER");
return filter; return filter;
} }
@Data
public static class ResourceRedirect {
private String context;
private String redirect;
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment